Class: Fastlane::Helper::VersionIconHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::VersionIconHelper
- Defined in:
- lib/fastlane/plugin/icon_versioning/helper/version_icon_helper.rb
Constant Summary collapse
- CACHE_FILE_NAME =
'cache.yml'.freeze
- CONTENTS_JSON_FILE_NAME =
'Contents.json'.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ VersionIconHelper
constructor
A new instance of VersionIconHelper.
- #run ⇒ Object
Constructor Details
#initialize(params) ⇒ VersionIconHelper
Returns a new instance of VersionIconHelper.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fastlane/plugin/icon_versioning/helper/version_icon_helper.rb', line 16 def initialize(params) @appiconset_path = File.(params[:appiconset_path]) @text = params[:text] @text_color = params[:text_color] text_margins_percentages = params[:text_margins_percentages] text_margins_percentages *= 4 if text_margins_percentages.length == 1 text_margins_percentages *= 2 if text_margins_percentages.length == 2 @text_top_margin_percentage = text_margins_percentages[0] @text_right_margin_percentage = text_margins_percentages[1] @text_bottom_margin_percentage = text_margins_percentages[2] @text_left_margin_percentage = text_margins_percentages[3] @band_height_percentage = params[:band_height_percentage] @band_blur_radius_percentage = params[:band_blur_radius_percentage] @band_blur_sigma_percentage = params[:band_blur_sigma_percentage] @ignored_icons_regex = params[:ignored_icons_regex] end |
Class Method Details
.get_versioned_path(path) ⇒ Object
84 85 86 |
# File 'lib/fastlane/plugin/icon_versioning/helper/version_icon_helper.rb', line 84 def self.get_versioned_path(path) return path.gsub(/([^.]+)(\.appiconset)/, '\1-Versioned\2') end |
Instance Method Details
#run ⇒ Object
38 39 40 41 42 43 44 45 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 79 80 81 82 |
# File 'lib/fastlane/plugin/icon_versioning/helper/version_icon_helper.rb', line 38 def run() versioned_appiconset_path = self.class.get_versioned_path(@appiconset_path) Dir.mkdir(versioned_appiconset_path) unless Dir.exist?(versioned_appiconset_path) cache_file_path = File.join(versioned_appiconset_path, CACHE_FILE_NAME) if File.exist?(cache_file_path) cache = YAML.load_file(cache_file_path) else cache = {} end FileUtils.copy("#{@appiconset_path}/#{CONTENTS_JSON_FILE_NAME}", "#{versioned_appiconset_path}/#{CONTENTS_JSON_FILE_NAME}") Dir.glob("#{@appiconset_path}/*.png").each do |original_icon_path| versioned_icon_path = self.class.get_versioned_path(original_icon_path) text_sha = Digest::SHA2.hexdigest(@text) unless cache[original_icon_path].nil? if File.exist?(versioned_icon_path) versioned_icon_sha = Digest::SHA2.file(versioned_icon_path).hexdigest cached_text_sha = cache[original_icon_path][:text] cached_icon_sha = cache[original_icon_path][:icon] next if text_sha == cached_text_sha && versioned_icon_sha == cached_icon_sha end end if @ignored_icons_regex && !(original_icon_path =~ @ignored_icons_regex).nil? FileUtils.copy(original_icon_path, versioned_icon_path) else version_icon(original_icon_path, versioned_icon_path) end cache[original_icon_path] = {} cache[original_icon_path][:text] = text_sha cache[original_icon_path][:icon] = Digest::SHA2.file(versioned_icon_path).hexdigest end File.open(cache_file_path, 'w') { |file| file.write(cache.to_yaml) } end |