Class: Pindo::XcodeResHelper
- Inherits:
-
Object
- Object
- Pindo::XcodeResHelper
- Defined in:
- lib/pindo/module/xcode/xcode_res_helper.rb
Class Method Summary collapse
- .create_icon(icon_name: nil, new_icon_dir: nil, xcode_icon_json: nil) ⇒ Object
- .create_icons(icon_name: nil, new_icon_dir: nil) ⇒ Object
- .create_imessage_icon(icon_name: nil, image_icon_name: nil, new_icon_dir: nil, xcode_icon_json: nil) ⇒ Object
- .install_icon(proj_dir: nil, new_icon_dir: nil) ⇒ Object
- .install_launchimg(proj_dir: nil, launchimg_pub_path: nil) ⇒ Object
Class Method Details
.create_icon(icon_name: nil, new_icon_dir: nil, xcode_icon_json: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pindo/module/xcode/xcode_res_helper.rb', line 12 def create_icon(icon_name:nil, new_icon_dir:nil, xcode_icon_json:nil) if !File.exist?(icon_name) raise Informative, "文件不存在:#{icon_name}" end xcode_icon_json["images"].each do |image_data| width,height = image_data["size"].split("x") image_name = image_data["filename"] iNum = image_name.split("@").last.chomp(".png").chomp("x").to_f width = width.to_f * iNum height = height.to_f * iNum width = width.to_i height = height.to_i command = [ 'sips', '--matchTo', '/System/Library/ColorSync/Profiles/sRGB Profile.icc', '-z', width.to_s, height.to_s, icon_name, '--out', File.join(new_icon_dir, image_name) ] Executable.capture_command('sips', command, capture: :out) # if !File.exist?(File.join(new_icon_dir, image_name)) # raise Informative, "生成icon失败!" # end # system("sips --matchTo '/System/Library/ColorSync/Profiles/sRGB Profile.icc' -z #{width} #{height} #{icon_name} --out #{new_icon_dir}/#{image_name}") end File.open(File.join(new_icon_dir, "Contents.json"), "w") do |f| f.write(JSON.pretty_generate(xcode_icon_json)) end end |
.create_icons(icon_name: nil, new_icon_dir: nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pindo/module/xcode/xcode_res_helper.rb', line 80 def create_icons(icon_name:nil, new_icon_dir:nil) begin FileUtils.mkdir_p(new_icon_dir) rescue => e puts e end create_icon(icon_name: icon_name, new_icon_dir: new_icon_dir, xcode_icon_json: XcodoeResConst.xcode_ios_icon_json) icon_dir = File.dirname(icon_name) = File.join(icon_dir, "icon1024_768.png") = File.join(new_icon_dir, "imessage") if File.exist?() begin FileUtils.mkdir_p() rescue => e puts e end (icon_name: icon_name, image_icon_name:, new_icon_dir: , xcode_icon_json: XcodoeResConst.) end end |
.create_imessage_icon(icon_name: nil, image_icon_name: nil, new_icon_dir: nil, xcode_icon_json: nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pindo/module/xcode/xcode_res_helper.rb', line 46 def (icon_name:nil, image_icon_name:nil, new_icon_dir:nil, xcode_icon_json:nil) if !File.exist?(icon_name) || !File.exist?(image_icon_name) raise Informative, "文件不存在:#{image_icon_name} or #{icon_name}" end xcode_icon_json["images"].each do |image_data| height, width = image_data["size"].split("x") image_name = image_data["filename"] iNum = image_name.split("@").last.chomp(".png").chomp("x").to_f width = width.to_f * iNum height = height.to_f * iNum width = width.to_i height = height.to_i icon_ori_name = image_icon_name if width.to_s.eql?(height.to_s) icon_ori_name = icon_name end command = [ 'sips', '--matchTo', '/System/Library/ColorSync/Profiles/sRGB Profile.icc', '-z', width.to_s, height.to_s, icon_ori_name, '--out', File.join(new_icon_dir, image_name) ] Executable.capture_command('sips', command, capture: :out) end File.open(File.join(new_icon_dir, "Contents.json"), "w") do |f| f.write(JSON.pretty_generate(xcode_icon_json)) end end |
.install_icon(proj_dir: nil, new_icon_dir: nil) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/pindo/module/xcode/xcode_res_helper.rb', line 101 def install_icon(proj_dir:nil, new_icon_dir:nil) xcodeproj_file_name = Dir.glob(File.join(proj_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)} xcodereshandler = XcodeResHandler.new(proj_fullname: xcodeproj_file_name) xcodereshandler.install_icon_res(new_icon_dir: new_icon_dir) xcodereshandler.validate_icon_res = File.join(new_icon_dir, "imessage") if File.exist?() xcodereshandler.(new_icon_dir: ) xcodereshandler. end end |
.install_launchimg(proj_dir: nil, launchimg_pub_path: nil) ⇒ Object
114 115 116 117 118 |
# File 'lib/pindo/module/xcode/xcode_res_helper.rb', line 114 def install_launchimg(proj_dir:nil, launchimg_pub_path:nil) xcodeproj_file_name = Dir.glob(File.join(proj_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)} xcodereshandler = XcodeResHandler.new(proj_fullname: xcodeproj_file_name) xcodereshandler.install_launchimg(launchimg_pub_path:launchimg_pub_path) end |