acbaker 0.1.0 → 2.0.1

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: 63f6fe7ce930381613423574f872ea32100bdde4
4
- data.tar.gz: d84c56f9ed65a617412540fd089d264ee51e7659
2
+ SHA256:
3
+ metadata.gz: 60d9f08dd1435635035cd1c2843eb8220823ae51aaa672b6663a117b5149b716
4
+ data.tar.gz: b633f8517f998d3c82f83de7476a08e05234622d5473a096815db788c58a4031
5
5
  SHA512:
6
- metadata.gz: 04307cd0be90d0d2605067b1d80e7bc0222916d90c377b65f1eff209f9b04e780f48b89b9351b11cf84547a9d8934129577f30d1da1dce91d0005a898f7a4105
7
- data.tar.gz: 5ed62131acc3c62e733c67f44d5896a829f987edd0080ecae97aa519d5622676449c99503c284629217d955cbeb09d5e3f2e1261e3b465ec7b51be183e39bfe2
6
+ metadata.gz: 8db2ec514658c9be0e0e6259bedcaa0a92fefe0072626059396543076d3e68576fbce01a1bf8c758a4e7ef09017b049da9457bbde2c97e3f71d780295c2d12c9
7
+ data.tar.gz: 93c9b84d9e8b9456c3c3481ffa710c3c9bf0e4225fbf9e5f865d185f41f4022ec2df33715cc9182522fa17d28f65c49e904b678d83da0fc25d6511d7a57ca9dd
@@ -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,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acbaker (2.0.1)
5
+ commander (>= 4.4, < 4.4.7)
6
+ highline (>= 1.7.2, < 2.0.0)
7
+ json (~> 2.2)
8
+ rmagick (~> 3.1, >= 3.1.0)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ ast (2.4.1)
14
+ coderay (1.1.3)
15
+ commander (4.4.6)
16
+ highline (~> 1.7.2)
17
+ diff-lcs (1.4.4)
18
+ highline (1.7.10)
19
+ json (2.3.1)
20
+ method_source (1.0.0)
21
+ minitest (5.14.1)
22
+ parallel (1.19.2)
23
+ parser (2.7.1.4)
24
+ ast (~> 2.4.1)
25
+ pry (0.13.1)
26
+ coderay (~> 1.1)
27
+ method_source (~> 1.0)
28
+ rainbow (3.0.0)
29
+ rake (12.3.3)
30
+ regexp_parser (1.7.1)
31
+ rexml (3.2.4)
32
+ rmagick (3.2.0)
33
+ rspec (3.9.0)
34
+ rspec-core (~> 3.9.0)
35
+ rspec-expectations (~> 3.9.0)
36
+ rspec-mocks (~> 3.9.0)
37
+ rspec-core (3.9.2)
38
+ rspec-support (~> 3.9.3)
39
+ rspec-expectations (3.9.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-mocks (3.9.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.9.0)
45
+ rspec-support (3.9.3)
46
+ rubocop (0.88.0)
47
+ parallel (~> 1.10)
48
+ parser (>= 2.7.1.1)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.7)
51
+ rexml
52
+ rubocop-ast (>= 0.1.0, < 1.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 1.4.0, < 2.0)
55
+ rubocop-ast (0.2.0)
56
+ parser (>= 2.7.0.1)
57
+ ruby-progressbar (1.10.1)
58
+ unicode-display_width (1.7.0)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ acbaker!
65
+ minitest (~> 5.11)
66
+ pry (~> 0.12)
67
+ rake (~> 12.0)
68
+ rspec (~> 3.8)
69
+ rubocop (~> 0.69)
70
+
71
+ BUNDLED WITH
72
+ 2.1.4
data/README.md CHANGED
@@ -20,6 +20,9 @@ USAGE
20
20
  CHANGELOG
21
21
  ---------
22
22
 
23
+ * **0.1.1**
24
+ * Fix aspect ratio bug in center processor
25
+
23
26
  * **0.1.0**
24
27
  * Bigfixes
25
28
 
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,17 @@ 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 "highline", '< 2.0.0', ">= 1.7.2"
17
+ s.add_dependency "commander", ">= 4.4", "< 4.4.7"
18
+ s.add_dependency "json", "~> 2.2"
19
+ s.add_dependency "rmagick", "~> 3.1", ">= 3.1.0"
20
+ s.add_development_dependency "minitest", "~> 5.11"
21
+ s.add_development_dependency "pry", "~> 0.12"
22
+ s.add_development_dependency "rake", "~> 12.0"
23
+ s.add_development_dependency "rspec", "~> 3.8"
24
+ s.add_development_dependency "rubocop", "~> 0.69"
21
25
  s.files = `git ls-files`.split("\n")
22
26
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
23
- s.require_path = 'lib'
27
+ s.require_path = "lib"
24
28
  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,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
@@ -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.1.0"
2
+ VERSION = "2.0.1"
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,159 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acbaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 2.0.1
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-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "<"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.7.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "<"
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.7.2
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: commander
15
35
  requirement: !ruby/object:Gem::Requirement
16
36
  requirements:
17
- - - ~>
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '4.4'
40
+ - - "<"
18
41
  - !ruby/object:Gem::Version
19
- version: '4.1'
42
+ version: 4.4.7
20
43
  type: :runtime
21
44
  prerelease: false
22
45
  version_requirements: !ruby/object:Gem::Requirement
23
46
  requirements:
24
- - - ~>
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '4.4'
50
+ - - "<"
25
51
  - !ruby/object:Gem::Version
26
- version: '4.1'
52
+ version: 4.4.7
27
53
  - !ruby/object:Gem::Dependency
28
54
  name: json
29
55
  requirement: !ruby/object:Gem::Requirement
30
56
  requirements:
31
- - - ~>
57
+ - - "~>"
32
58
  - !ruby/object:Gem::Version
33
- version: '1.8'
59
+ version: '2.2'
34
60
  type: :runtime
35
61
  prerelease: false
36
62
  version_requirements: !ruby/object:Gem::Requirement
37
63
  requirements:
38
- - - ~>
64
+ - - "~>"
39
65
  - !ruby/object:Gem::Version
40
- version: '1.8'
66
+ version: '2.2'
41
67
  - !ruby/object:Gem::Dependency
42
68
  name: rmagick
43
69
  requirement: !ruby/object:Gem::Requirement
44
70
  requirements:
45
- - - ~>
71
+ - - "~>"
46
72
  - !ruby/object:Gem::Version
47
- version: '2.13'
48
- - - '>='
73
+ version: '3.1'
74
+ - - ">="
49
75
  - !ruby/object:Gem::Version
50
- version: 2.13.4
76
+ version: 3.1.0
51
77
  type: :runtime
52
78
  prerelease: false
53
79
  version_requirements: !ruby/object:Gem::Requirement
54
80
  requirements:
55
- - - ~>
81
+ - - "~>"
56
82
  - !ruby/object:Gem::Version
57
- version: '2.13'
58
- - - '>='
83
+ version: '3.1'
84
+ - - ">="
59
85
  - !ruby/object:Gem::Version
60
- version: 2.13.4
86
+ version: 3.1.0
87
+ - !ruby/object:Gem::Dependency
88
+ name: minitest
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '5.11'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '5.11'
101
+ - !ruby/object:Gem::Dependency
102
+ name: pry
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '0.12'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '0.12'
61
115
  - !ruby/object:Gem::Dependency
62
116
  name: rake
63
117
  requirement: !ruby/object:Gem::Requirement
64
118
  requirements:
65
- - - ~>
119
+ - - "~>"
66
120
  - !ruby/object:Gem::Version
67
- version: '10.0'
121
+ version: '12.0'
68
122
  type: :development
69
123
  prerelease: false
70
124
  version_requirements: !ruby/object:Gem::Requirement
71
125
  requirements:
72
- - - ~>
126
+ - - "~>"
73
127
  - !ruby/object:Gem::Version
74
- version: '10.0'
128
+ version: '12.0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: rspec
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '3.8'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '3.8'
143
+ - !ruby/object:Gem::Dependency
144
+ name: rubocop
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.69'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '0.69'
75
157
  description: This gem allows easy conversion and management of xcode asset catalogs.
76
158
  email:
77
159
  - tobias.strebitzer@magloft.com
@@ -80,7 +162,10 @@ executables:
80
162
  extensions: []
81
163
  extra_rdoc_files: []
82
164
  files:
83
- - .gitignore
165
+ - ".gitignore"
166
+ - ".rubocop.yml"
167
+ - Gemfile
168
+ - Gemfile.lock
84
169
  - README.md
85
170
  - Rakefile
86
171
  - acbaker.gemspec
@@ -111,19 +196,17 @@ require_paths:
111
196
  - lib
112
197
  required_ruby_version: !ruby/object:Gem::Requirement
113
198
  requirements:
114
- - - '>='
199
+ - - ">="
115
200
  - !ruby/object:Gem::Version
116
- version: '0'
201
+ version: '2.4'
117
202
  required_rubygems_version: !ruby/object:Gem::Requirement
118
203
  requirements:
119
- - - '>='
204
+ - - ">="
120
205
  - !ruby/object:Gem::Version
121
- version: 1.3.6
206
+ version: '0'
122
207
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.4.5
208
+ rubygems_version: 3.1.2
125
209
  signing_key:
126
210
  specification_version: 4
127
211
  summary: Convert any source images into xcode asset catalogs.
128
212
  test_files: []
129
- has_rdoc: