spritely 2.0.0 → 2.1.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
- SHA1:
3
- metadata.gz: ae40c9a7ce9d7836c6b37b3b3ccc626b65145525
4
- data.tar.gz: 5749341869e454dfc773f11bc5bfb56a46b8c26c
2
+ SHA256:
3
+ metadata.gz: 31b8d97d90ad2aff2af8f2a9b70e8498af3d33a84479f73d5fe55ce60bf169a0
4
+ data.tar.gz: 971bc7f7712fe8a0be34964a546cd15797d7a30f3daaae0989e3e996dd3aa3b8
5
5
  SHA512:
6
- metadata.gz: f7ff4dff485cc7469d0aeecf8d403a392318993adb7bbd33d30f50c850b7dd4c56bbac761b5818861469a675550bfb2c9a34ffa85678e3e88941660a9fccebd5
7
- data.tar.gz: 1d159336eaaaa280286f94b87bcc029a58bf1d61af3faf44d060975eee901490178eb0c6d45785902ccf18809497d90a01734bea77766938eaa538cb9d6f93be
6
+ metadata.gz: 4b6b3aef9dda6a35f3d09f6201ae3c117908464cd9de1e218dfc8edeb9654db4d8a9df624571db66def425cd8b072a9e244a911f266d5271cddaf8eeabab026e
7
+ data.tar.gz: 6dee0e5c12f995690e50eaeee5f761e75169732cc7857f08daf08fe1f8de1afbc4b927e12c7692cb461a79c0e9c5880a928e712f3dec19a5130993df123d4385
@@ -2,12 +2,20 @@ require 'sprockets'
2
2
  require 'spritely/sass_functions'
3
3
  require 'spritely/sprockets/preprocessor'
4
4
  require 'spritely/sprockets/transformer'
5
+ require 'logger'
5
6
 
6
7
  if defined?(::Rails::Engine)
7
8
  require 'spritely/engine'
8
9
  end
9
10
 
10
11
  module Spritely
12
+ def self.logger
13
+ @logger ||= if defined?(::Rails.logger) && ::Rails.logger
14
+ ::Rails.logger
15
+ else
16
+ Logger.new($stderr)
17
+ end
18
+ end
11
19
  end
12
20
 
13
21
  ::Sprockets.register_mime_type 'text/sprite', extensions: ['.png.sprite']
@@ -24,11 +24,15 @@ module Spritely
24
24
  end
25
25
 
26
26
  def outer_height
27
- height + spacing
27
+ spacing_above + height + spacing_below
28
28
  end
29
29
 
30
- def spacing
31
- options[:spacing].to_i
30
+ def spacing_above
31
+ options[:spacing_above].to_i
32
+ end
33
+
34
+ def spacing_below
35
+ (options[:spacing_below] || options[:spacing]).to_i
32
36
  end
33
37
 
34
38
  def repeated?
@@ -60,7 +64,7 @@ module Spritely
60
64
 
61
65
  def add_image!(left_position)
62
66
  images << Image.new(data).tap do |image|
63
- image.top = top
67
+ image.top = top + spacing_above
64
68
  image.left = left_position
65
69
  end
66
70
  end
@@ -6,23 +6,24 @@ module Spritely
6
6
  #
7
7
  # //= directory foo/bar
8
8
  # //= repeat arrow true
9
- # //= spacing arrow 10
9
+ # //= spacing-below arrow 10
10
10
  # //= position another-image right
11
- # //= spacing 5
11
+ # //= spacing-above 5
12
+ # //= spacing-below 5
12
13
  #
13
14
  # To this:
14
15
  #
15
16
  # {
16
17
  # directory: 'foo/bar',
17
- # global: { spacing: 5 },
18
+ # global: { spacing_above: '5', spacing_below: '5' },
18
19
  # images: {
19
- # 'arrow' => { repeat: 'true', spacing: '10' },
20
- # 'another-image' => { position: 'right', spacing: '5' }
20
+ # 'arrow' => { repeat: 'true', spacing_above: '10', spacing_below: '5' },
21
+ # 'another-image' => { position: 'right', spacing_above: '5', spacing_below: '5' }
21
22
  # }
22
23
  # }
23
24
  class Preprocessor < ::Sprockets::DirectiveProcessor
24
- GLOBAL_DIRECTIVES = %w(position spacing).freeze
25
- IMAGE_DIRECTIVES = %w(repeat position spacing).freeze
25
+ GLOBAL_DIRECTIVES = %w(position spacing spacing-above spacing-below).freeze
26
+ IMAGE_DIRECTIVES = %w(repeat position spacing spacing-above spacing-below).freeze
26
27
 
27
28
  def _call(input)
28
29
  @sprite_directives = { directory: nil, global: {}, images: {} }
@@ -51,14 +52,18 @@ module Spritely
51
52
  private
52
53
 
53
54
  def process_image_option(directive, image, value)
55
+ check_if_deprecated_directive(directive)
56
+
54
57
  @sprite_directives[:images][image] ||= {}
55
- @sprite_directives[:images][image][directive.to_sym] = value
58
+ @sprite_directives[:images][image][directive.tr('-', '_').to_sym] = value
56
59
  end
57
60
 
58
61
  def process_global_option(directive, value)
59
62
  raise ArgumentError, "'#{directive}' is not a valid global option" unless GLOBAL_DIRECTIVES.include?(directive)
60
63
 
61
- @sprite_directives[:global][directive.to_sym] = value
64
+ check_if_deprecated_directive(directive)
65
+
66
+ @sprite_directives[:global][directive.tr('-', '_').to_sym] = value
62
67
  end
63
68
 
64
69
  def merge_global_options!
@@ -66,6 +71,12 @@ module Spritely
66
71
  options.merge!(@sprite_directives[:global]) { |key, left, right| left }
67
72
  end
68
73
  end
74
+
75
+ def check_if_deprecated_directive(directive)
76
+ if directive == 'spacing'
77
+ Spritely.logger.warn "The `spacing` directive is deprecated and has been replaced by `spacing-below`. It will be removed in Spritely 3.0. (called from #{@filename})"
78
+ end
79
+ end
69
80
  end
70
81
  end
71
82
  end
@@ -1,3 +1,3 @@
1
1
  module Spritely
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  //= repeat background true
2
- //= spacing football 100
3
- //= spacing mario 10
2
+ //= spacing-above football 10
3
+ //= spacing-below football 100
4
+ //= spacing-below mario 10
4
5
  //= position mario right
5
- //= spacing 5
6
+ //= spacing-below 5
@@ -1 +1 @@
1
- //= spacing 5
1
+ //= spacing-below 5
@@ -19,7 +19,7 @@ describe 'Stylesheet generation', :integration do
19
19
  it { should include(<<-CSS.strip_heredoc
20
20
  #mario {
21
21
  background-image: url(#{background_image_url});
22
- background-position: -150px -806px;
22
+ background-position: -150px -816px;
23
23
  width: 200px;
24
24
  height: 214px; }
25
25
  CSS
@@ -3,7 +3,7 @@ require 'ostruct'
3
3
 
4
4
  describe Spritely::ImageSet do
5
5
  let(:path) { "#{__dir__}/../fixtures/test/foo.png" }
6
- let(:options) { {repeat: 'true', spacing: '10', position: 'right'} }
6
+ let(:options) { {repeat: 'true', spacing_above: '5', spacing_below: '10', position: 'right'} }
7
7
 
8
8
  subject { Spritely::ImageSet.new(path, options) }
9
9
 
@@ -14,8 +14,9 @@ describe Spritely::ImageSet do
14
14
  its(:height) { should eq(1) }
15
15
  its(:name) { should eq('foo') }
16
16
  its(:left) { should eq(0) }
17
- its(:spacing) { should eq(10) }
18
- its(:outer_height) { should eq(11) }
17
+ its(:spacing_above) { should eq(5) }
18
+ its(:spacing_below) { should eq(10) }
19
+ its(:outer_height) { should eq(16) }
19
20
 
20
21
  describe '#top' do
21
22
  before { subject.top = 123 }
@@ -72,9 +73,9 @@ describe Spritely::ImageSet do
72
73
  end
73
74
 
74
75
  it 'should set the position of the images' do
75
- expect(first_image.top).to eq(123)
76
+ expect(first_image.top).to eq(128)
76
77
  expect(first_image.left).to eq(0)
77
- expect(second_image.top).to eq(123)
78
+ expect(second_image.top).to eq(128)
78
79
  expect(second_image.left).to eq(1)
79
80
  end
80
81
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spritely::Sprockets::Preprocessor do
4
- let(:data) { "//= spacing some-new-image 789\n//= position some-new-image right\n//= repeat another-image true\n//= repeat yet-another-image false\n//= spacing 901\n//= position left" }
4
+ let(:data) { "//= spacing-below some-new-image 789\n//= position some-new-image right\n//= repeat another-image true\n//= repeat yet-another-image false\n//= spacing-below 901\n//= spacing-above 101\n//= position left" }
5
5
  let(:input) { {
6
6
  data: data,
7
7
  filename: "sprites/foo.png.sprite",
@@ -15,15 +15,27 @@ describe Spritely::Sprockets::Preprocessor do
15
15
 
16
16
  expect(input[:metadata][:sprite_directives]).to eq(
17
17
  directory: nil,
18
- global: { spacing: '901', position: 'left' },
18
+ global: { spacing_above: '101', spacing_below: '901', position: 'left' },
19
19
  images: {
20
- "some-new-image" => { spacing: '789', position: 'right' },
21
- "another-image" => { repeat: 'true', spacing: '901', position: 'left' },
22
- "yet-another-image" => { repeat: 'false', spacing: '901', position: 'left' }
20
+ "some-new-image" => { spacing_above: '101', spacing_below: '789', position: 'right' },
21
+ "another-image" => { repeat: 'true', spacing_above: '101', spacing_below: '901', position: 'left' },
22
+ "yet-another-image" => { repeat: 'false', spacing_above: '101', spacing_below: '901', position: 'left' }
23
23
  }
24
24
  )
25
25
  end
26
26
 
27
+ describe 'deprecation warnings' do
28
+ describe 'spacing directive' do
29
+ let(:data) { "//= spacing true" }
30
+
31
+ it 'warns the user' do
32
+ deprecation_warning = 'The `spacing` directive is deprecated and has been replaced by `spacing-below`. It will be removed in Spritely 3.0. (called from sprites/foo.png.sprite)'
33
+
34
+ expect { preprocessor._call(input) }.to output(Regexp.new(Regexp.escape(deprecation_warning))).to_stderr
35
+ end
36
+ end
37
+ end
38
+
27
39
  describe 'overriding the directory' do
28
40
  let(:data) { "//= directory foo/sprites" }
29
41
  let(:input) { {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spritely
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Robbin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-22 00:00:00.000000000 Z
11
+ date: 2018-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chunky_png
@@ -235,41 +235,41 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  version: '0'
236
236
  requirements: []
237
237
  rubyforge_project:
238
- rubygems_version: 2.6.11
238
+ rubygems_version: 2.7.6
239
239
  signing_key:
240
240
  specification_version: 4
241
241
  summary: Hooks into the Sprockets asset packaging system to allow you to easily generate
242
242
  sprite maps
243
243
  test_files:
244
- - spec/fixtures/correct-empty-sprite.png
245
- - spec/fixtures/correct-renamed-sprite.png
246
- - spec/fixtures/correct-sprite.png
244
+ - spec/spec_helper.rb
245
+ - spec/integration/stylesheet_spec.rb
246
+ - spec/integration/precompilation_spec.rb
247
+ - spec/support/rails_app_helpers.rb
247
248
  - spec/fixtures/correct-weird-sprite.png
248
- - spec/fixtures/rails-app/app/assets/images/application/background.png
249
- - spec/fixtures/rails-app/app/assets/images/application/fool.png
250
- - spec/fixtures/rails-app/app/assets/images/application/football.png
251
- - spec/fixtures/rails-app/app/assets/images/application/mario.png
249
+ - spec/fixtures/correct-renamed-sprite.png
250
+ - spec/fixtures/rails-app-changes/app/assets/images/application/dropdown-arrow.png
251
+ - spec/fixtures/rails-app-changes/app/assets/stylesheets/sprites.css.scss
252
+ - spec/fixtures/test/foo.png
252
253
  - spec/fixtures/rails-app/app/assets/images/empty/fool.png
253
254
  - spec/fixtures/rails-app/app/assets/images/foo/fool.png
254
- - spec/fixtures/rails-app/app/assets/images/sprites/application.png.sprite
255
- - spec/fixtures/rails-app/app/assets/images/sprites/empty.png.sprite
256
255
  - spec/fixtures/rails-app/app/assets/images/sprites/foo.png.sprite
257
256
  - spec/fixtures/rails-app/app/assets/images/sprites/weird.png.sprite
257
+ - spec/fixtures/rails-app/app/assets/images/sprites/application.png.sprite
258
+ - spec/fixtures/rails-app/app/assets/images/sprites/empty.png.sprite
259
+ - spec/fixtures/rails-app/app/assets/images/application/fool.png
260
+ - spec/fixtures/rails-app/app/assets/images/application/background.png
261
+ - spec/fixtures/rails-app/app/assets/images/application/football.png
262
+ - spec/fixtures/rails-app/app/assets/images/application/mario.png
258
263
  - spec/fixtures/rails-app/app/assets/images/weird/sprite-images/mario.png
259
- - spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss
260
264
  - spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss
265
+ - spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss
261
266
  - spec/fixtures/rails-app/config/initializers/assets.rb
262
- - spec/fixtures/rails-app-changes/app/assets/images/application/dropdown-arrow.png
263
- - spec/fixtures/rails-app-changes/app/assets/stylesheets/sprites.css.scss
264
- - spec/fixtures/test/foo.png
265
- - spec/integration/precompilation_spec.rb
266
- - spec/integration/stylesheet_spec.rb
267
- - spec/spec_helper.rb
267
+ - spec/fixtures/correct-sprite.png
268
+ - spec/fixtures/correct-empty-sprite.png
268
269
  - spec/spritely/collection_spec.rb
269
- - spec/spritely/generators/chunky_png_spec.rb
270
270
  - spec/spritely/image_set_spec.rb
271
- - spec/spritely/image_spec.rb
271
+ - spec/spritely/sprockets/preprocessor_spec.rb
272
272
  - spec/spritely/sass_functions_spec.rb
273
+ - spec/spritely/image_spec.rb
274
+ - spec/spritely/generators/chunky_png_spec.rb
273
275
  - spec/spritely/sprite_map_spec.rb
274
- - spec/spritely/sprockets/preprocessor_spec.rb
275
- - spec/support/rails_app_helpers.rb