Skip to content

Instantly share code, notes, and snippets.

@bright23
Last active September 30, 2020 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bright23/66d1bb3f3ee447876d5b5f64c1e13d74 to your computer and use it in GitHub Desktop.
Save bright23/66d1bb3f3ee447876d5b5f64c1e13d74 to your computer and use it in GitHub Desktop.
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