acbaker 0.0.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e9ae87d8d0116132643efd054dd902f11f7415dd
4
- data.tar.gz: 4caa61508232fa88cfefc656a6ff7df2030d14f7
2
+ SHA256:
3
+ metadata.gz: 48bc435fe2f091ac41f92db9b3ceb0442ac40ef3a8267d88b89a929f51e995ea
4
+ data.tar.gz: af9958ef2aa4a6fa0ca1b1564628610eaca49b9792ebcb07649dc12f5f158968
5
5
  SHA512:
6
- metadata.gz: 320faf834aa04eebed124a329f5e6081cf194735ea7e9653c8e8081e4b824cb0c3e51455e6900011430a2eea1f687e5e5102ae0f23b3282d033a28a7fe6bf2cd
7
- data.tar.gz: 0f67714166dbdd5642d293f41b32f32cd6a1f61442ac231fda37625b05e9e4a8b79ef1d7dd30b494081e79823d80783b82c67fe5265221a0fe942b5cf42458d1
6
+ metadata.gz: 607ceae4931cef50443dd2bfaa4409ca8458fe334f559c7efb9a054304ae85a92d3bb7bb166922a91b2224ee0df6324e33bba9663305babbd9950c254c9cb0e1
7
+ data.tar.gz: 946b6f6d02c5aac0568d5e238b4ae60160c2d2bb54e3259cf7311011f1412fca2442ea13151e18e435a8e30a2f9cbb7de6359c63249fb91eb8062baffae3ee83
@@ -0,0 +1,257 @@
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
+ Style/TernaryParentheses:
10
+ Enabled: true
11
+ EnforcedStyle: require_parentheses_when_complex
12
+
13
+ # specs sometimes have useless assignments, which is fine
14
+ Lint/UselessAssignment:
15
+ Exclude:
16
+ - '**/spec/**/*'
17
+
18
+ # We could potentially enable the 2 below:
19
+ Layout/FirstHashElementIndentation:
20
+ Enabled: false
21
+
22
+ Layout/HashAlignment:
23
+ Enabled: false
24
+
25
+ # HoundCI doesn't like this rule
26
+ Layout/DotPosition:
27
+ Enabled: false
28
+
29
+ # We allow !! as it's an easy way to convert ot boolean
30
+ Style/DoubleNegation:
31
+ Enabled: false
32
+
33
+ Style/NumericPredicate:
34
+ Enabled: false
35
+
36
+ # Sometimes we allow a rescue block that doesn't contain code
37
+ Lint/SuppressedException:
38
+ Enabled: false
39
+
40
+ Style/RescueStandardError:
41
+ Enabled: false
42
+
43
+ # Cop supports --auto-correct.
44
+ Lint/UnusedBlockArgument:
45
+ Enabled: false
46
+
47
+ # Needed for $verbose
48
+ Style/GlobalVars:
49
+ Enabled: false
50
+
51
+ # We want to allow class Fastlane::Class
52
+ Style/ClassAndModuleChildren:
53
+ Enabled: false
54
+
55
+ # $? Exit
56
+ Style/SpecialGlobalVars:
57
+ Enabled: false
58
+
59
+ Metrics/AbcSize:
60
+ Enabled: false
61
+
62
+ Metrics/MethodLength:
63
+ Enabled: false
64
+
65
+ Metrics/ModuleLength:
66
+ Enabled: true
67
+ Max: 110
68
+
69
+ Metrics/CyclomaticComplexity:
70
+ Enabled: false
71
+
72
+ Metrics/BlockNesting:
73
+ Max: 5
74
+
75
+ Metrics/BlockLength:
76
+ Enabled: false
77
+
78
+ # The %w might be confusing for new users
79
+ Style/WordArray:
80
+ MinSize: 19
81
+
82
+ # raise and fail are both okay
83
+ Style/SignalException:
84
+ Enabled: false
85
+
86
+ # Better too much 'return' than one missing
87
+ Style/RedundantReturn:
88
+ Enabled: false
89
+
90
+ # Having if in the same line might not always be good
91
+ Style/IfUnlessModifier:
92
+ Enabled: false
93
+
94
+ # and and or is okay
95
+ Style/AndOr:
96
+ Enabled: false
97
+
98
+ # Configuration parameters: CountComments.
99
+ Metrics/ClassLength:
100
+ Max: 400
101
+
102
+ # Configuration parameters: AllowURI, URISchemes.
103
+ Metrics/LineLength:
104
+ Enabled: false
105
+ Max: 370
106
+
107
+ # Configuration parameters: CountKeywordArgs.
108
+ Metrics/ParameterLists:
109
+ Max: 17
110
+
111
+ Metrics/PerceivedComplexity:
112
+ Max: 25
113
+
114
+ # Sometimes it's easier to read without guards
115
+ Style/GuardClause:
116
+ Enabled: false
117
+
118
+ # We allow both " and '
119
+ Style/StringLiterals:
120
+ Enabled: false
121
+
122
+ # something = if something_else
123
+ # that's confusing
124
+ Style/ConditionalAssignment:
125
+ Enabled: false
126
+
127
+ # Better to have too much self than missing a self
128
+ Style/RedundantSelf:
129
+ Enabled: false
130
+
131
+ # e.g.
132
+ # def self.is_supported?(platform)
133
+ # we may never use `platform`
134
+ Lint/UnusedMethodArgument:
135
+ Enabled: false
136
+
137
+ # the let(:key) { ... }
138
+ Lint/ParenthesesAsGroupedExpression:
139
+ Exclude:
140
+ - '**/spec/**/*'
141
+
142
+ # This would reject is_ in front of methods
143
+ # We use `is_supported?` everywhere already
144
+ Naming/PredicateName:
145
+ Enabled: false
146
+
147
+ # We allow the $
148
+ Style/PerlBackrefs:
149
+ Enabled: false
150
+
151
+ # Disable '+ should be surrounded with a single space' for xcodebuild_spec.rb
152
+ Layout/SpaceAroundOperators:
153
+ Exclude:
154
+ - '**/spec/actions_specs/xcodebuild_spec.rb'
155
+
156
+ # We're not there yet
157
+ Style/Documentation:
158
+ Enabled: false
159
+
160
+ # Added after upgrade to 0.38.0
161
+ Style/MutableConstant:
162
+ Enabled: false
163
+
164
+ # length > 0 is good
165
+ Style/ZeroLengthPredicate:
166
+ Enabled: false
167
+
168
+ # Adds complexity
169
+ Style/IfInsideElse:
170
+ Enabled: false
171
+
172
+ Style/RescueModifier:
173
+ Enabled: false
174
+
175
+ Naming/VariableNumber:
176
+ Enabled: false
177
+
178
+ Style/ClassVars:
179
+ Enabled: false
180
+
181
+ Style/FrozenStringLiteralComment:
182
+ Enabled: false
183
+
184
+ Layout/EmptyLinesAroundAttributeAccessor:
185
+ Enabled: true
186
+
187
+ Layout/SpaceAroundMethodCallOperator:
188
+ Enabled: true
189
+
190
+ Lint/DeprecatedOpenSSLConstant:
191
+ Enabled: true
192
+
193
+ Lint/DuplicateElsifCondition:
194
+ Enabled: true
195
+
196
+ Lint/MixedRegexpCaptureTypes:
197
+ Enabled: true
198
+
199
+ Lint/RaiseException:
200
+ Enabled: true
201
+
202
+ Lint/StructNewOverride:
203
+ Enabled: true
204
+
205
+ Style/AccessorGrouping:
206
+ Enabled: true
207
+
208
+ Style/ArrayCoercion:
209
+ Enabled: true
210
+
211
+ Style/BisectedAttrAccessor:
212
+ Enabled: true
213
+
214
+ Style/CaseLikeIf:
215
+ Enabled: true
216
+
217
+ Style/ExponentialNotation:
218
+ Enabled: true
219
+
220
+ Style/HashAsLastArrayItem:
221
+ Enabled: true
222
+
223
+ Style/HashEachMethods:
224
+ Enabled: true
225
+
226
+ Style/HashLikeCase:
227
+ Enabled: true
228
+
229
+ Style/HashTransformKeys:
230
+ Enabled: true
231
+
232
+ Style/HashTransformValues:
233
+ Enabled: true
234
+
235
+ Style/RedundantAssignment:
236
+ Enabled: true
237
+
238
+ Style/RedundantFetchBlock:
239
+ Enabled: true
240
+
241
+ Style/RedundantFileExtensionInRequire:
242
+ Enabled: true
243
+
244
+ Style/RedundantRegexpCharacterClass:
245
+ Enabled: true
246
+
247
+ Style/RedundantRegexpEscape:
248
+ Enabled: true
249
+
250
+ Style/SlicingWithRange:
251
+ Enabled: true
252
+
253
+ AllCops:
254
+ TargetRubyVersion: "2.4.0"
255
+ Exclude:
256
+ - './tmp/**/*'
257
+ - './Gemfile'
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acbaker (2.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.1)
13
+ coderay (1.1.3)
14
+ commander (4.5.2)
15
+ highline (~> 2.0.0)
16
+ diff-lcs (1.4.4)
17
+ highline (2.0.3)
18
+ json (2.3.1)
19
+ method_source (1.0.0)
20
+ minitest (5.14.1)
21
+ parallel (1.19.2)
22
+ parser (2.7.1.4)
23
+ ast (~> 2.4.1)
24
+ pry (0.13.1)
25
+ coderay (~> 1.1)
26
+ method_source (~> 1.0)
27
+ rainbow (3.0.0)
28
+ rake (12.3.3)
29
+ regexp_parser (1.7.1)
30
+ rexml (3.2.4)
31
+ rmagick (3.2.0)
32
+ rspec (3.9.0)
33
+ rspec-core (~> 3.9.0)
34
+ rspec-expectations (~> 3.9.0)
35
+ rspec-mocks (~> 3.9.0)
36
+ rspec-core (3.9.2)
37
+ rspec-support (~> 3.9.3)
38
+ rspec-expectations (3.9.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.9.0)
41
+ rspec-mocks (3.9.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-support (3.9.3)
45
+ rubocop (0.88.0)
46
+ parallel (~> 1.10)
47
+ parser (>= 2.7.1.1)
48
+ rainbow (>= 2.2.2, < 4.0)
49
+ regexp_parser (>= 1.7)
50
+ rexml
51
+ rubocop-ast (>= 0.1.0, < 1.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (>= 1.4.0, < 2.0)
54
+ rubocop-ast (0.2.0)
55
+ parser (>= 2.7.0.1)
56
+ ruby-progressbar (1.10.1)
57
+ unicode-display_width (1.7.0)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ acbaker!
64
+ minitest (~> 5.11)
65
+ pry (~> 0.12)
66
+ rake (~> 12.0)
67
+ rspec (~> 3.8)
68
+ rubocop (~> 0.69)
69
+
70
+ BUNDLED WITH
71
+ 2.1.4
data/README.md CHANGED
@@ -20,6 +20,12 @@ USAGE
20
20
  CHANGELOG
21
21
  ---------
22
22
 
23
+ * **0.1.1**
24
+ * Fix aspect ratio bug in center processor
25
+
26
+ * **0.1.0**
27
+ * Bigfixes
28
+
23
29
  * **0.0.9**
24
30
  * Added Constraint Filter
25
31
 
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_ruby_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,61 +62,64 @@ 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
- filename_array = []
78
- filename_array.push(@type)
79
- filename_array.push(image_spec['idiom']) if image_spec['idiom']
80
- filename_array.push(image_spec['orientation']) if image_spec['orientation']
81
- filename_array.push(version)
82
-
83
- # Add subtype
84
- if image_spec['subtype']
85
- if image_spec['subtype'] == '736h'
86
- filename_array.push('retina-hd-55')
87
- elsif image_spec['subtype'] == '667h'
88
- filename_array.push('retina-hd-47')
72
+ if image_spec["filename"]
73
+ filename = image_spec["filename"]
74
+ else
75
+ filename_array = []
76
+ filename_array.push(@type)
77
+ filename_array.push(image_spec['idiom']) if image_spec['idiom']
78
+ filename_array.push(image_spec['orientation']) if image_spec['orientation']
79
+ filename_array.push(version)
80
+
81
+ # Add subtype
82
+ if image_spec['subtype']
83
+ case image_spec['subtype']
84
+ when '736h'
85
+ filename_array.push('retina-hd-55')
86
+ when '667h'
87
+ filename_array.push('retina-hd-47')
88
+ else
89
+ filename_array.push(image_spec['subtype'])
90
+ end
91
+ end
92
+
93
+ # Add extent
94
+ filename_array.push(image_spec['extent']) if image_spec['extent']
95
+
96
+ # Add size
97
+ filename_array.push(image_spec['size'])
98
+
99
+ if scale > 1
100
+ filename = "#{filename_array.join('-')}@#{scale}x.png"
89
101
  else
90
- filename_array.push(image_spec['subtype'])
102
+ filename = "#{filename_array.join('-')}.png"
91
103
  end
92
104
  end
93
-
94
- # Add extent
95
- filename_array.push(image_spec['extent']) if image_spec['extent']
96
-
97
- # Add size
98
- filename_array.push(image_spec['size'])
99
-
100
- if scale > 1
101
- filename = "#{filename_array.join('-')}@#{scale}x.png"
102
- else
103
- filename = "#{filename_array.join('-')}.png"
104
- end
105
-
105
+
106
106
  # save image
107
107
  image.write("#{target_directory}/#{filename}")
108
-
108
+
109
109
  # Trigger Callback proc
110
- block.call("#{target_directory}/#{filename}", index+1) if not block.nil?
111
-
110
+ block&.call("#{target_directory}/#{filename}", index + 1)
111
+
112
112
  # Update json data
113
113
  image_spec['filename'] = filename
114
-
115
114
  end
116
115
 
117
116
  # Save Contents.json
118
117
  @json_data.delete('processors')
119
- File.open(json_output_file,"w") do |f|
118
+ File.open(json_output_file, "w") do |f|
120
119
  f.write(JSON.pretty_generate(@json_data))
121
120
  end
122
-
121
+
123
122
  true
124
123
  end
125
-
126
124
  end
127
125
  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,16 +2,19 @@ module Acbaker
2
2
  module Processors
3
3
  class Base
4
4
  attr_accessor :asset_pack, :options
5
-
6
- def initialize(asset_pack, options={})
5
+
6
+ def defaults
7
+ {}
8
+ end
9
+
10
+ def initialize(asset_pack, options = {})
7
11
  @asset_pack = asset_pack
8
12
  @options = options ? defaults.merge(options) : defaults
9
13
  end
10
-
11
- def run(image, image_spec, width=nil, height=nil)
14
+
15
+ def run(image, image_spec, width = nil, height = nil)
12
16
  throw "Acbaker::Processors::Base should be extended"
13
17
  end
14
-
15
18
  end
16
19
  end
17
20
  end
@@ -1,31 +1,31 @@
1
+ require 'pry'
2
+
1
3
  module Acbaker
2
4
  module Processors
3
5
  class Center < Base
4
-
5
6
  def defaults
6
- {"max-width" => "50%", "background-color" => "#FFFFFF", "gravity" => "Center"}
7
+ { "max-width" => "50%", "background-color" => "#FFFFFF", "gravity" => "Center" }
7
8
  end
8
-
9
- def run(image, image_spec, width=nil, height=nil)
9
+
10
+ def run(image, image_spec, width = nil, height = nil)
10
11
  transform_width = width.to_f
11
12
  transform_height = height.to_f
12
- target_ratio = transform_width / transform_height
13
- image_ratio = image.columns / image.rows
14
-
13
+ image_ratio = image.rows.to_f / image.columns
14
+
15
15
  # calculate dimensions
16
16
  if @options['max-width']
17
17
  if @options['max-width'][-1] == "%"
18
18
  rel_width = (@options['max-width'][0..-2].to_f / 100)
19
- transform_width = transform_width * rel_width
19
+ transform_width *= rel_width
20
20
  else
21
21
  transform_width = @options['max-width'].to_f
22
22
  end
23
23
  transform_height = transform_width * image_ratio
24
24
  end
25
-
25
+
26
26
  # resize image
27
27
  image.resize!(transform_width.to_i, transform_height.to_i)
28
-
28
+
29
29
  # create canvas
30
30
  canvas = Magick::Image.new(width, height)
31
31
  if @options['background-color'] == :transparent
@@ -33,13 +33,10 @@ module Acbaker
33
33
  else
34
34
  canvas = canvas.color_floodfill(1, 1, Magick::Pixel.from_color(@options['background-color']))
35
35
  end
36
-
36
+
37
37
  # place image
38
- image = canvas.composite(image, Magick::CenterGravity, Magick::OverCompositeOp)
39
-
40
- image
38
+ canvas.composite(image, Magick::CenterGravity, Magick::OverCompositeOp)
41
39
  end
42
-
43
40
  end
44
41
  end
45
42
  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,12 @@ 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
- image = canvas.composite(image, gravity, Magick::OverCompositeOp)
27
-
28
- image
25
+ canvas.composite(image, gravity, Magick::OverCompositeOp)
29
26
  end
30
-
31
27
  end
32
28
  end
33
29
  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,12 @@ 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
- image = canvas.composite(image, gravity, Magick::OverCompositeOp)
27
-
28
- image
25
+ canvas.composite(image, gravity, Magick::OverCompositeOp)
29
26
  end
30
-
31
27
  end
32
28
  end
33
29
  end
@@ -1,3 +1,3 @@
1
1
  module Acbaker
2
- VERSION = "0.0.9"
2
+ VERSION = "2.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,77 +1,133 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acbaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 2.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: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2020-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
15
15
  requirement: !ruby/object:Gem::Requirement
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'
48
- - - '>='
47
+ version: '3.1'
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'
58
- - - '>='
57
+ version: '3.1'
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
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '12.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '12.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
66
108
  - !ruby/object:Gem::Version
67
- version: '10.0'
109
+ version: '3.8'
68
110
  type: :development
69
111
  prerelease: false
70
112
  version_requirements: !ruby/object:Gem::Requirement
71
113
  requirements:
72
- - - ~>
114
+ - - "~>"
73
115
  - !ruby/object:Gem::Version
74
- version: '10.0'
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
@@ -80,7 +136,10 @@ executables:
80
136
  extensions: []
81
137
  extra_rdoc_files: []
82
138
  files:
83
- - .gitignore
139
+ - ".gitignore"
140
+ - ".rubocop.yml"
141
+ - Gemfile
142
+ - Gemfile.lock
84
143
  - README.md
85
144
  - Rakefile
86
145
  - acbaker.gemspec
@@ -111,19 +170,17 @@ require_paths:
111
170
  - lib
112
171
  required_ruby_version: !ruby/object:Gem::Requirement
113
172
  requirements:
114
- - - '>='
173
+ - - ">="
115
174
  - !ruby/object:Gem::Version
116
- version: '0'
175
+ version: '2.4'
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: '0'
122
181
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.4.5
182
+ rubygems_version: 3.1.2
125
183
  signing_key:
126
184
  specification_version: 4
127
185
  summary: Convert any source images into xcode asset catalogs.
128
186
  test_files: []
129
- has_rdoc: