acbaker 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bddef30773a817c4152b9e56e8a4fa9224ec08cd
4
- data.tar.gz: eac32823d311bee666ab2fc9cc0afe7c4afc7d23
3
+ metadata.gz: 97a5d5b5fbe81e5ef885249ef880f328cba55338
4
+ data.tar.gz: 816f604d4a787d92a70590417e514ff98e3042b3
5
5
  SHA512:
6
- metadata.gz: 146f709b5a052cd4dc838ed82028fba16de5c302f02ee66d089777ca86ea3fe6b89d33adc76ecaaf7c0e189d529405b44e4858ec4fd391d865e8be802e7b9738
7
- data.tar.gz: deb5a784b9d70ba7e54be635cab97296f8f0fe042ecd424891c25babd241302b466a0307619d15aec5a37651354e291627c465168fce4dc38f3a5aefd9636351
6
+ metadata.gz: 10009156cb23b208ab566b1bcb55d685e98565c924c3ac97c95ae04670a08b9e607b663c54e1d3870122241c69abff60def0526cac4ef9dc731719a816cf4940
7
+ data.tar.gz: 37a99fe9623f576e947eeb3167970a3d8ece3be150da2a5de0a67d7385f747e892fbb14752bcd69208a3255f195da5e11d0b1cd1ba416843e425ccd94e0a10bc
@@ -0,0 +1,192 @@
1
+ Style/SymbolArray:
2
+ Enabled: true
3
+ EnforcedStyle: brackets
4
+
5
+ # kind_of? is a good way to check a type
6
+ Style/ClassCheck:
7
+ EnforcedStyle: kind_of?
8
+
9
+ # It's better to be more explicit about the type
10
+ Style/BracesAroundHashParameters:
11
+ Enabled: false
12
+
13
+ Style/TernaryParentheses:
14
+ Enabled: true
15
+ EnforcedStyle: require_parentheses_when_complex
16
+
17
+ # specs sometimes have useless assignments, which is fine
18
+ Lint/UselessAssignment:
19
+ Exclude:
20
+ - '**/spec/**/*'
21
+
22
+ # We could potentially enable the 2 below:
23
+ Layout/IndentFirstHashElement:
24
+ Enabled: false
25
+
26
+ Layout/AlignHash:
27
+ Enabled: false
28
+
29
+ # HoundCI doesn't like this rule
30
+ Layout/DotPosition:
31
+ Enabled: false
32
+
33
+ # We allow !! as it's an easy way to convert ot boolean
34
+ Style/DoubleNegation:
35
+ Enabled: false
36
+
37
+ Style/NumericPredicate:
38
+ Enabled: false
39
+
40
+ # Sometimes we allow a rescue block that doesn't contain code
41
+ Lint/HandleExceptions:
42
+ Enabled: false
43
+
44
+ Style/RescueStandardError:
45
+ Enabled: false
46
+
47
+ # Cop supports --auto-correct.
48
+ Lint/UnusedBlockArgument:
49
+ Enabled: false
50
+
51
+ # Needed for $verbose
52
+ Style/GlobalVars:
53
+ Enabled: false
54
+
55
+ # We want to allow class Fastlane::Class
56
+ Style/ClassAndModuleChildren:
57
+ Enabled: false
58
+
59
+ # $? Exit
60
+ Style/SpecialGlobalVars:
61
+ Enabled: false
62
+
63
+ Metrics/AbcSize:
64
+ Enabled: false
65
+
66
+ Metrics/MethodLength:
67
+ Enabled: false
68
+
69
+ Metrics/ModuleLength:
70
+ Enabled: true
71
+ Max: 110
72
+
73
+ Metrics/CyclomaticComplexity:
74
+ Enabled: false
75
+
76
+ Metrics/BlockNesting:
77
+ Max: 5
78
+
79
+ Metrics/BlockLength:
80
+ Enabled: false
81
+
82
+ # The %w might be confusing for new users
83
+ Style/WordArray:
84
+ MinSize: 19
85
+
86
+ # raise and fail are both okay
87
+ Style/SignalException:
88
+ Enabled: false
89
+
90
+ # Better too much 'return' than one missing
91
+ Style/RedundantReturn:
92
+ Enabled: false
93
+
94
+ # Having if in the same line might not always be good
95
+ Style/IfUnlessModifier:
96
+ Enabled: false
97
+
98
+ # and and or is okay
99
+ Style/AndOr:
100
+ Enabled: false
101
+
102
+ # Configuration parameters: CountComments.
103
+ Metrics/ClassLength:
104
+ Max: 400
105
+
106
+ # Configuration parameters: AllowURI, URISchemes.
107
+ Metrics/LineLength:
108
+ Enabled: false
109
+ Max: 370
110
+
111
+ # Configuration parameters: CountKeywordArgs.
112
+ Metrics/ParameterLists:
113
+ Max: 17
114
+
115
+ Metrics/PerceivedComplexity:
116
+ Max: 25
117
+
118
+ # Sometimes it's easier to read without guards
119
+ Style/GuardClause:
120
+ Enabled: false
121
+
122
+ # We allow both " and '
123
+ Style/StringLiterals:
124
+ Enabled: false
125
+
126
+ # something = if something_else
127
+ # that's confusing
128
+ Style/ConditionalAssignment:
129
+ Enabled: false
130
+
131
+ # Better to have too much self than missing a self
132
+ Style/RedundantSelf:
133
+ Enabled: false
134
+
135
+ # e.g.
136
+ # def self.is_supported?(platform)
137
+ # we may never use `platform`
138
+ Lint/UnusedMethodArgument:
139
+ Enabled: false
140
+
141
+ # the let(:key) { ... }
142
+ Lint/ParenthesesAsGroupedExpression:
143
+ Exclude:
144
+ - '**/spec/**/*'
145
+
146
+ # This would reject is_ in front of methods
147
+ # We use `is_supported?` everywhere already
148
+ Naming/PredicateName:
149
+ Enabled: false
150
+
151
+ # We allow the $
152
+ Style/PerlBackrefs:
153
+ Enabled: false
154
+
155
+ # Disable '+ should be surrounded with a single space' for xcodebuild_spec.rb
156
+ Layout/SpaceAroundOperators:
157
+ Exclude:
158
+ - '**/spec/actions_specs/xcodebuild_spec.rb'
159
+
160
+ # We're not there yet
161
+ Style/Documentation:
162
+ Enabled: false
163
+
164
+ # Added after upgrade to 0.38.0
165
+ Style/MutableConstant:
166
+ Enabled: false
167
+
168
+ # length > 0 is good
169
+ Style/ZeroLengthPredicate:
170
+ Enabled: false
171
+
172
+ # Adds complexity
173
+ Style/IfInsideElse:
174
+ Enabled: false
175
+
176
+ Style/RescueModifier:
177
+ Enabled: false
178
+
179
+ Naming/VariableNumber:
180
+ Enabled: false
181
+
182
+ Style/ClassVars:
183
+ Enabled: false
184
+
185
+ Style/FrozenStringLiteralComment:
186
+ Enabled: false
187
+
188
+ AllCops:
189
+ TargetRubyVersion: "2.3.3"
190
+ Exclude:
191
+ - './tmp/**/*'
192
+ - './Gemfile'
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acbaker (1.0.0)
5
+ commander (~> 4.4)
6
+ json (~> 2.2)
7
+ rmagick (~> 3.1, >= 3.1.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ ast (2.4.0)
13
+ coderay (1.1.2)
14
+ commander (4.4.7)
15
+ highline (~> 2.0.0)
16
+ diff-lcs (1.3)
17
+ highline (2.0.2)
18
+ jaro_winkler (1.5.2)
19
+ json (2.2.0)
20
+ method_source (0.9.2)
21
+ minitest (5.11.3)
22
+ parallel (1.17.0)
23
+ parser (2.6.3.0)
24
+ ast (~> 2.4.0)
25
+ pry (0.12.2)
26
+ coderay (~> 1.1.0)
27
+ method_source (~> 0.9.0)
28
+ rainbow (3.0.0)
29
+ rake (12.3.2)
30
+ rmagick (3.1.0)
31
+ rspec (3.8.0)
32
+ rspec-core (~> 3.8.0)
33
+ rspec-expectations (~> 3.8.0)
34
+ rspec-mocks (~> 3.8.0)
35
+ rspec-core (3.8.0)
36
+ rspec-support (~> 3.8.0)
37
+ rspec-expectations (3.8.3)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.8.0)
40
+ rspec-mocks (3.8.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-support (3.8.0)
44
+ rubocop (0.69.0)
45
+ jaro_winkler (~> 1.5.1)
46
+ parallel (~> 1.10)
47
+ parser (>= 2.6)
48
+ rainbow (>= 2.2.2, < 4.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 1.4.0, < 1.7)
51
+ ruby-progressbar (1.10.0)
52
+ unicode-display_width (1.6.0)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ acbaker!
59
+ minitest (~> 5.11)
60
+ pry (~> 0.12)
61
+ rake (~> 12.0)
62
+ rspec (~> 3.8)
63
+ rubocop (~> 0.69)
64
+
65
+ BUNDLED WITH
66
+ 1.16.3
data/Rakefile CHANGED
@@ -6,4 +6,4 @@ Rake::TestTask.new do |t|
6
6
  t.libs << 'test'
7
7
  end
8
8
 
9
- task default: %w[test]
9
+ task default: %w[test]
@@ -1,7 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'acbaker/version'
3
+ require "acbaker/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = "acbaker"
@@ -13,12 +12,16 @@ Gem::Specification.new do |s|
13
12
  s.homepage = "http://www.magloft.com"
14
13
  s.summary = "Convert any source images into xcode asset catalogs."
15
14
  s.description = "This gem allows easy conversion and management of xcode asset catalogs."
16
- s.required_rubygems_version = '>= 1.3.6'
17
- s.add_dependency "commander", '~> 4.1'
18
- s.add_dependency 'json', '~> 1.8'
19
- s.add_dependency 'rmagick', '~> 2.13', '>= 2.13.4'
20
- s.add_development_dependency "rake", '~> 10.0'
15
+ s.required_rubygems_version = "~> 2.4"
16
+ s.add_dependency "commander", "~> 4.4"
17
+ s.add_dependency "json", "~> 2.2"
18
+ s.add_dependency "rmagick", "~> 3.1", ">= 3.1.0"
19
+ s.add_development_dependency "minitest", "~> 5.11"
20
+ s.add_development_dependency "pry", "~> 0.12"
21
+ s.add_development_dependency "rake", "~> 12.0"
22
+ s.add_development_dependency "rspec", "~> 3.8"
23
+ s.add_development_dependency "rubocop", "~> 0.69"
21
24
  s.files = `git ls-files`.split("\n")
22
25
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
23
- s.require_path = 'lib'
26
+ s.require_path = "lib"
24
27
  end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'commander/import'
3
- $:.push File.expand_path("../../lib", __FILE__)
3
+ $:.push File.expand_path('../lib', __dir__)
4
4
  require 'acbaker'
5
5
 
6
6
  program :version, Acbaker::VERSION
@@ -3,5 +3,4 @@ require 'acbaker/asset_pack'
3
3
  require 'acbaker/processors'
4
4
 
5
5
  module Acbaker
6
-
7
- end
6
+ end
@@ -4,44 +4,42 @@ require 'rmagick'
4
4
  module Acbaker
5
5
  class AssetPack
6
6
  attr_reader :type, :images, :processors
7
-
8
- def initialize(type, options={})
7
+
8
+ def initialize(type, options = {})
9
9
  @type = type
10
10
  @processors = []
11
11
  if options[:json]
12
12
  @json_data = options[:json]
13
13
  else
14
- @json_file = File.join(File.dirname(File.expand_path(__FILE__)), "config", "#{type.to_s}.json")
14
+ @json_file = File.join(File.dirname(File.expand_path(__FILE__)), "config", "#{type}.json")
15
15
  @json_data = JSON.parse(File.open(@json_file).read)
16
16
  end
17
17
  @images = @json_data['images']
18
- @options = self.defaults().merge(options)
18
+ @options = self.defaults.merge(options)
19
19
  end
20
-
20
+
21
21
  def defaults
22
- {json: false, gravity: 'Center', strategy: 'Cover'}
22
+ { json: false, gravity: 'Center', strategy: 'Cover' }
23
23
  end
24
-
24
+
25
25
  def process(source_image_file, target_directory, &block)
26
-
27
26
  # Define variables
28
27
  json_output_file = File.join(target_directory, "Contents.json")
29
-
28
+
30
29
  # Get processors
31
- if @json_data['processors'] and @json_data['processors'].length
30
+ if @json_data['processors']&.length
32
31
  @json_data['processors'].each do |processor_spec|
33
32
  @processors.push(Object.const_get(processor_spec['type']).new(self, processor_spec['config']))
34
33
  end
35
34
  else
36
35
  @processors = [Object.const_get("Acbaker::Processors::#{@options[:strategy]}").new(self)]
37
36
  end
38
-
37
+
39
38
  # Loop through images
40
39
  @json_data['images'].each_with_index.map do |image_spec, index|
41
-
42
40
  image_size_present = image_spec['size']
43
41
  image = Magick::ImageList.new(source_image_file)
44
- image_spec['size'] = "#{image.columns.to_s}x#{image.rows.to_s}" unless image_size_present
42
+ image_spec['size'] = "#{image.columns}x#{image.rows}" unless image_size_present
45
43
 
46
44
  # Get size
47
45
  scale = image_spec['scale'].gsub('x', '').to_i
@@ -53,9 +51,6 @@ module Acbaker
53
51
  width = image.columns
54
52
  height = image.rows
55
53
  end
56
- size_max = [width, height].max
57
- base_width = width / scale
58
- base_height = height / scale
59
54
 
60
55
  # Get version
61
56
  if image_spec['minimum-system-version'].nil?
@@ -67,12 +62,12 @@ module Acbaker
67
62
  else
68
63
  version = 'ios56'
69
64
  end
70
-
65
+
71
66
  # process image
72
67
  @processors.each do |processor|
73
68
  image = processor.run(image, image_spec, width, height)
74
69
  end
75
-
70
+
76
71
  # Generate filename
77
72
  if image_spec["filename"]
78
73
  filename = image_spec["filename"]
@@ -82,7 +77,7 @@ module Acbaker
82
77
  filename_array.push(image_spec['idiom']) if image_spec['idiom']
83
78
  filename_array.push(image_spec['orientation']) if image_spec['orientation']
84
79
  filename_array.push(version)
85
-
80
+
86
81
  # Add subtype
87
82
  if image_spec['subtype']
88
83
  if image_spec['subtype'] == '736h'
@@ -93,13 +88,13 @@ module Acbaker
93
88
  filename_array.push(image_spec['subtype'])
94
89
  end
95
90
  end
96
-
91
+
97
92
  # Add extent
98
93
  filename_array.push(image_spec['extent']) if image_spec['extent']
99
-
94
+
100
95
  # Add size
101
96
  filename_array.push(image_spec['size'])
102
-
97
+
103
98
  if scale > 1
104
99
  filename = "#{filename_array.join('-')}@#{scale}x.png"
105
100
  else
@@ -109,22 +104,21 @@ module Acbaker
109
104
 
110
105
  # save image
111
106
  image.write("#{target_directory}/#{filename}")
112
-
107
+
113
108
  # Trigger Callback proc
114
- block.call("#{target_directory}/#{filename}", index+1) if not block.nil?
115
-
109
+ block&.call("#{target_directory}/#{filename}", index + 1)
110
+
116
111
  # Update json data
117
112
  image_spec['filename'] = filename
118
113
  end
119
114
 
120
115
  # Save Contents.json
121
116
  @json_data.delete('processors')
122
- File.open(json_output_file,"w") do |f|
117
+ File.open(json_output_file, "w") do |f|
123
118
  f.write(JSON.pretty_generate(@json_data))
124
119
  end
125
-
120
+
126
121
  true
127
122
  end
128
-
129
123
  end
130
124
  end
@@ -1,2 +1,2 @@
1
- $:.push File.expand_path('../', __FILE__)
2
- require 'commands/pack'
1
+ $:.push File.expand_path(__dir__)
2
+ require 'commands/pack'
@@ -1,4 +1,4 @@
1
- command :'pack' do |c|
1
+ command :pack do |c|
2
2
  c.syntax = "acbaker pack [image] [output directory]"
3
3
  c.summary = "Convert an image into a xcode asset catalogs"
4
4
  c.description = "The type will be autodetected by filename, and can be overwritten using the --type option"
@@ -10,7 +10,6 @@ command :'pack' do |c|
10
10
  global_option '--force'
11
11
 
12
12
  c.action do |args, options|
13
-
14
13
  # Prepare arguments
15
14
  @image = args[0]
16
15
  @output_directory = args[1]
@@ -19,7 +18,7 @@ command :'pack' do |c|
19
18
  @gravity = options.gravity
20
19
  @strategy = options.strategy
21
20
  @force = options.force
22
-
21
+
23
22
  # Validate
24
23
  validate_image_magick!
25
24
  validate_image!
@@ -27,7 +26,7 @@ command :'pack' do |c|
27
26
  validate_type!
28
27
  validate_gravity!
29
28
  validate_strategy!
30
-
29
+
31
30
  validate_output_directory!
32
31
 
33
32
  # Initialize packer
@@ -36,8 +35,8 @@ command :'pack' do |c|
36
35
  gravity: @gravity,
37
36
  strategy: @strategy
38
37
  })
39
-
40
- # Pack assets
38
+
39
+ # Pack assets
41
40
  bar = ProgressBar.new(asset_pack.images.size)
42
41
  bar.show
43
42
  asset_pack.process(@image, @output_directory) do |path, progress|
@@ -45,7 +44,6 @@ command :'pack' do |c|
45
44
  end
46
45
 
47
46
  say_ok 'Your assets were successfully packed!'
48
-
49
47
  end
50
48
 
51
49
  private
@@ -55,17 +53,15 @@ command :'pack' do |c|
55
53
  end
56
54
 
57
55
  def validate_image!
58
-
59
56
  # validate image is set
60
57
  abort("Error: no image specified.") if @image.nil?
61
-
58
+
62
59
  # validate image exists
63
- abort("Error: can't find the image you specified. #{@image}") unless File.exist?(@image) and File.file?(@image)
64
-
60
+ abort("Error: can't find the image you specified. #{@image}") unless File.exist?(@image) and File.file?(@image)
65
61
  end
66
-
62
+
67
63
  def validate_type!
68
- if not @type
64
+ unless @type
69
65
  # Detect from image
70
66
  token = @image.split('/')[-1].split('.')[0].downcase.to_sym
71
67
  @type = {
@@ -75,8 +71,8 @@ command :'pack' do |c|
75
71
  launch: :LaunchImage
76
72
  }[token]
77
73
  end
78
-
79
- if not @type and @output_directory
74
+
75
+ if !@type and @output_directory
80
76
  # Detect from directory
81
77
  token = @output_directory.gsub('.', '').downcase.to_sym
82
78
  @type = {
@@ -86,71 +82,63 @@ command :'pack' do |c|
86
82
  launchimage: :LaunchImage
87
83
  }[token]
88
84
  end
89
-
85
+
90
86
  # Fill json
91
- if @type and not @json
87
+ if @type and !@json
92
88
  if File.file?("lib/acbaker/config/#{@type}.json")
93
89
  @json = "lib/acbaker/config/#{@type}.json"
94
90
  end
95
91
  end
96
-
97
- abort "error: no JSON configuration found" if not @json
98
- abort("error: Could not detect asset type.") if not @type
92
+
93
+ abort "error: no JSON configuration found" unless @json
94
+ abort("error: Could not detect asset type.") unless @type
99
95
  end
100
-
96
+
101
97
  def validate_gravity!
102
- if not @gravity
103
- @gravity = "Center"
104
- end
105
- abort("error: Invalid gravity specified.") if not ["NorthWest", "North", "NorthEast", "West", "Center", "East", "SouthWest", "South", "SouthEast"].include?(@gravity)
98
+ @gravity ||= "Center"
99
+ abort("error: Invalid gravity specified.") unless ["NorthWest", "North", "NorthEast", "West", "Center", "East", "SouthWest", "South", "SouthEast"].include?(@gravity)
106
100
  end
107
101
 
108
102
  def validate_strategy!
109
- if not @strategy
110
- @strategy = "Cover"
111
- end
112
-
103
+ @strategy ||= "Cover"
104
+
113
105
  # try to instantiate strategy class
114
106
  begin
115
107
  Object.const_get("Acbaker::Processors::#{@strategy}")
116
- rescue Exception => e
108
+ rescue StandardError
117
109
  abort("error: Invalid strategy specified.")
118
110
  end
119
111
  end
120
112
 
121
-
122
113
  def validate_json!
123
114
  if @json
124
- abort("error: JSON file not found.") if not File.exist?(@json) or not File.file?(@json)
115
+ abort("error: JSON file not found.") if !File.exist?(@json) or !File.file?(@json)
125
116
  begin
126
117
  JSON.parse(File.open(@json).read)
127
- rescue Exception => e
118
+ rescue StandardError
128
119
  abort("error: invalid JSON file: #{@json}")
129
120
  end
130
- @type = :Custom if not @type
121
+ @type ||= :Custom
131
122
  end
132
123
  end
133
124
 
134
125
  def validate_output_directory!
135
- if not @output_directory
136
- @output_directory = {
126
+ @output_directory ||= {
137
127
  AppIcon: "AppIcon.appiconset",
138
128
  LaunchImage: "LaunchImage.launchimage"
139
129
  }[@type]
140
- end
141
130
 
142
131
  # Create custom output directory if type is set
143
- @output_directory = "#{@type}.imageset" if not @output_directory and @type
144
-
132
+ @output_directory = "#{@type}.imageset" if !@output_directory and @type
133
+
145
134
  abort("Error: No output directory specified or detected.") if @output_directory.nil?
146
- parent_directory = File.expand_path(@output_directory).split("/")[0..-2].join("/")
147
- abort("Error: Parent directory '#{parent_directory}' does not exist.") unless File.exist?(parent_directory) and File.directory?(parent_directory)
148
-
135
+ parent_directory = File.expand_path(@output_directory).split("/")[0..-2].join("/")
136
+ abort("Error: Parent directory '#{parent_directory}' does not exist.") unless File.exist?(parent_directory) and File.directory?(parent_directory)
137
+
149
138
  # Prepare output directory
150
139
  if @force
151
140
  FileUtils.rm_rf(@output_directory) if File.directory?(@output_directory)
152
141
  end
153
- FileUtils.mkdir(@output_directory) if not File.directory?(@output_directory)
142
+ FileUtils.mkdir(@output_directory) unless File.directory?(@output_directory)
154
143
  end
155
-
156
- end
144
+ end
@@ -1,4 +1,4 @@
1
- $:.push File.expand_path('../', __FILE__)
1
+ $:.push File.expand_path(__dir__)
2
2
  require 'processors/base'
3
3
  require 'processors/center'
4
4
  require 'processors/cover'
@@ -2,20 +2,19 @@ module Acbaker
2
2
  module Processors
3
3
  class Base
4
4
  attr_accessor :asset_pack, :options
5
-
5
+
6
6
  def defaults
7
7
  {}
8
8
  end
9
-
10
- def initialize(asset_pack, options={})
9
+
10
+ def initialize(asset_pack, options = {})
11
11
  @asset_pack = asset_pack
12
12
  @options = options ? defaults.merge(options) : defaults
13
13
  end
14
-
15
- def run(image, image_spec, width=nil, height=nil)
14
+
15
+ def run(image, image_spec, width = nil, height = nil)
16
16
  throw "Acbaker::Processors::Base should be extended"
17
17
  end
18
-
19
18
  end
20
19
  end
21
20
  end
@@ -3,31 +3,29 @@ require 'pry'
3
3
  module Acbaker
4
4
  module Processors
5
5
  class Center < Base
6
-
7
6
  def defaults
8
- {"max-width" => "50%", "background-color" => "#FFFFFF", "gravity" => "Center"}
7
+ { "max-width" => "50%", "background-color" => "#FFFFFF", "gravity" => "Center" }
9
8
  end
10
-
11
- def run(image, image_spec, width=nil, height=nil)
9
+
10
+ def run(image, image_spec, width = nil, height = nil)
12
11
  transform_width = width.to_f
13
12
  transform_height = height.to_f
14
- target_ratio = transform_width / transform_height
15
13
  image_ratio = image.rows.to_f / image.columns.to_f
16
-
14
+
17
15
  # calculate dimensions
18
16
  if @options['max-width']
19
17
  if @options['max-width'][-1] == "%"
20
18
  rel_width = (@options['max-width'][0..-2].to_f / 100)
21
- transform_width = transform_width * rel_width
19
+ transform_width *= rel_width
22
20
  else
23
21
  transform_width = @options['max-width'].to_f
24
22
  end
25
23
  transform_height = transform_width * image_ratio
26
24
  end
27
-
25
+
28
26
  # resize image
29
27
  image.resize!(transform_width.to_i, transform_height.to_i)
30
-
28
+
31
29
  # create canvas
32
30
  canvas = Magick::Image.new(width, height)
33
31
  if @options['background-color'] == :transparent
@@ -35,13 +33,12 @@ module Acbaker
35
33
  else
36
34
  canvas = canvas.color_floodfill(1, 1, Magick::Pixel.from_color(@options['background-color']))
37
35
  end
38
-
36
+
39
37
  # place image
40
38
  image = canvas.composite(image, Magick::CenterGravity, Magick::OverCompositeOp)
41
-
39
+
42
40
  image
43
41
  end
44
-
45
42
  end
46
43
  end
47
44
  end
@@ -1,17 +1,15 @@
1
1
  module Acbaker
2
2
  module Processors
3
3
  class Constraint < Base
4
-
5
- def run(image, image_spec, width=nil, height=nil)
4
+ def run(image, image_spec, width = nil, height = nil)
6
5
  # resize image
7
6
  image.change_geometry("#{width}x#{height}") do |px, py, i|
8
7
  image.resize!(px, py)
9
8
  image_spec['size'] = "#{px}x#{py}"
10
9
  end
11
-
10
+
12
11
  image
13
12
  end
14
-
15
13
  end
16
14
  end
17
15
  end
@@ -1,17 +1,16 @@
1
1
  module Acbaker
2
2
  module Processors
3
3
  class Contain < Base
4
-
5
4
  def defaults
6
- {"background-color" => "#FFFFFF", "gravity" => "Center"}
5
+ { "background-color" => "#FFFFFF", "gravity" => "Center" }
7
6
  end
8
-
9
- def run(image, image_spec, width=nil, height=nil)
7
+
8
+ def run(image, image_spec, width = nil, height = nil)
10
9
  # resize image
11
10
  image.change_geometry("#{width}x#{height}") do |px, py, i|
12
11
  image.resize!(px, py)
13
12
  end
14
-
13
+
15
14
  # crop image
16
15
  canvas = Magick::Image.new(width, height)
17
16
  if @options['background-color'] == :transparent
@@ -19,15 +18,14 @@ module Acbaker
19
18
  else
20
19
  canvas = canvas.color_floodfill(1, 1, Magick::Pixel.from_color(@options['background-color']))
21
20
  end
22
-
21
+
23
22
  # place image
24
23
  gravity_string = "Magick::#{@options['gravity']}Gravity"
25
24
  gravity = Object.const_get(gravity_string)
26
25
  image = canvas.composite(image, gravity, Magick::OverCompositeOp)
27
-
26
+
28
27
  image
29
28
  end
30
-
31
29
  end
32
30
  end
33
31
  end
@@ -1,17 +1,16 @@
1
1
  module Acbaker
2
2
  module Processors
3
3
  class Cover < Base
4
-
5
4
  def defaults
6
- {"background-color" => "#FFFFFF", "gravity" => "Center"}
5
+ { "background-color" => "#FFFFFF", "gravity" => "Center" }
7
6
  end
8
-
9
- def run(image, image_spec, width=nil, height=nil)
7
+
8
+ def run(image, image_spec, width = nil, height = nil)
10
9
  # resize image
11
10
  image.change_geometry("#{width}x#{height}^") do |px, py, i|
12
11
  image.resize!(px, py)
13
12
  end
14
-
13
+
15
14
  # crop image
16
15
  canvas = Magick::Image.new(width, height)
17
16
  if @options['background-color'] == :transparent
@@ -19,15 +18,14 @@ module Acbaker
19
18
  else
20
19
  canvas = canvas.color_floodfill(1, 1, Magick::Pixel.from_color(@options['background-color']))
21
20
  end
22
-
21
+
23
22
  # place image
24
23
  gravity_string = "Magick::#{@options['gravity']}Gravity"
25
24
  gravity = Object.const_get(gravity_string)
26
25
  image = canvas.composite(image, gravity, Magick::OverCompositeOp)
27
-
26
+
28
27
  image
29
28
  end
30
-
31
29
  end
32
30
  end
33
31
  end
@@ -1,3 +1,3 @@
1
1
  module Acbaker
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -2,23 +2,21 @@ require 'minitest/autorun'
2
2
  require 'acbaker'
3
3
 
4
4
  class AcbakerTest < Minitest::Test
5
-
6
5
  def test_initialize
7
- FileUtils.mkdir("tmp") if not File.directory?("tmp")
6
+ FileUtils.mkdir("tmp") unless File.directory?("tmp")
8
7
  asset_pack = Acbaker::AssetPack.new(:AppIcon)
9
8
  assert_equal :AppIcon, asset_pack.type
10
9
  end
11
-
10
+
12
11
  def test_appicon
13
- FileUtils.mkdir_p("tmp/AppIcon.appiconset") if not File.directory?("tmp/AppIcon.appiconset")
12
+ FileUtils.mkdir_p("tmp/AppIcon.appiconset") unless File.directory?("tmp/AppIcon.appiconset")
14
13
  asset_pack = Acbaker::AssetPack.new(:AppIcon)
15
14
  asset_pack.process("test/assets/AppIcon.png", "tmp/AppIcon.appiconset")
16
15
  end
17
16
 
18
17
  def test_launchimage
19
- FileUtils.mkdir_p("tmp/LaunchImage.launchimage") if not File.directory?("tmp/LaunchImage.launchimage")
18
+ FileUtils.mkdir_p("tmp/LaunchImage.launchimage") unless File.directory?("tmp/LaunchImage.launchimage")
20
19
  asset_pack = Acbaker::AssetPack.new(:LaunchImage)
21
20
  asset_pack.process("test/assets/LaunchImage.png", "tmp/LaunchImage.launchimage")
22
21
  end
23
-
24
- end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acbaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Strebitzer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-24 00:00:00.000000000 Z
11
+ date: 2019-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -16,62 +16,118 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '4.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.1'
26
+ version: '4.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.8'
33
+ version: '2.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.8'
40
+ version: '2.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rmagick
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.13'
47
+ version: '3.1'
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 2.13.4
50
+ version: 3.1.0
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: '2.13'
57
+ version: '3.1'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 2.13.4
60
+ version: 3.1.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.11'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.11'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.12'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.12'
61
89
  - !ruby/object:Gem::Dependency
62
90
  name: rake
63
91
  requirement: !ruby/object:Gem::Requirement
64
92
  requirements:
65
93
  - - "~>"
66
94
  - !ruby/object:Gem::Version
67
- version: '10.0'
95
+ version: '12.0'
68
96
  type: :development
69
97
  prerelease: false
70
98
  version_requirements: !ruby/object:Gem::Requirement
71
99
  requirements:
72
100
  - - "~>"
73
101
  - !ruby/object:Gem::Version
74
- version: '10.0'
102
+ version: '12.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.8'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.8'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.69'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '0.69'
75
131
  description: This gem allows easy conversion and management of xcode asset catalogs.
76
132
  email:
77
133
  - tobias.strebitzer@magloft.com
@@ -81,6 +137,9 @@ extensions: []
81
137
  extra_rdoc_files: []
82
138
  files:
83
139
  - ".gitignore"
140
+ - ".rubocop.yml"
141
+ - Gemfile
142
+ - Gemfile.lock
84
143
  - README.md
85
144
  - Rakefile
86
145
  - acbaker.gemspec
@@ -116,14 +175,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
175
  version: '0'
117
176
  required_rubygems_version: !ruby/object:Gem::Requirement
118
177
  requirements:
119
- - - ">="
178
+ - - "~>"
120
179
  - !ruby/object:Gem::Version
121
- version: 1.3.6
180
+ version: '2.4'
122
181
  requirements: []
123
182
  rubyforge_project:
124
- rubygems_version: 2.4.5.1
183
+ rubygems_version: 2.5.2
125
184
  signing_key:
126
185
  specification_version: 4
127
186
  summary: Convert any source images into xcode asset catalogs.
128
187
  test_files: []
129
- has_rdoc: