Last active
September 30, 2020 02:39
-
-
Save bright23/66d1bb3f3ee447876d5b5f64c1e13d74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
# PDFディレクトリ内に入ってる.pdfを | |
# Icons.xcassetsに入れる | |
# 素材ファイルはuniversalでvector画像に設定 | |
# $ProjectDir/Project/Assets/Icons.xcassets | |
Dir.glob('PDF/*.pdf') do | f | | |
# f = PDF/*.pdfになるので | |
file=f.split("/") | |
file_name=file[1] | |
puts file_name | |
icon_name=file_name.split(".")[0] | |
new_dir="$ProjectName/Assets/Icons.xcassets/#{icon_name}.imageset/" | |
FileUtils.mkdir_p new_dir unless File.exists?(new_dir) | |
FileUtils.mv("PDF/#{file_name}", new_dir) | |
contents_file=new_dir+'/Contents.json' | |
contents = <<-EOS | |
{ | |
\"images\" : [ | |
{ | |
\"idiom\" : \"universal\", | |
\"filename\" : \"#{file_name}\" | |
} | |
], | |
\"info\" : { | |
\"version\" : 1, | |
\"author\" : \"xcode\" | |
}, | |
\"properties\" : { | |
\"preserves-vector-representation\" : true | |
} | |
} | |
EOS | |
File.open(contents_file,"w") do |file| | |
file.puts contents | |
end | |
end | |
FileUtils.rm_rf('PDF') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment