spritely 1.1.0 → 1.2.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: ab534f8d3de68e48fe062b507a94502cc9f7ab5d
4
- data.tar.gz: ff98e8e98cf0bf235bf0d2c09087d3682c54876b
3
+ metadata.gz: 55045aef9a86227f8a36323391b7e3e310feb6ef
4
+ data.tar.gz: c0fca28f4f25ad8010743f7ac402d42582101d1d
5
5
  SHA512:
6
- metadata.gz: 849dcbfe7926d77b285eb087a0adabb641e423c25f1583c755a025d5d60b7a7f94337591ac119a928cfbec4ecf0d31a998f10656771c11fc18abe0b548004d33
7
- data.tar.gz: 550db56989efc700924c785c6846673968e9c3b777d128c889f400a081f54af2a9838a8c6970d9a72108e8b4f2280f7b63191b3489edda126566f662046d3bbe
6
+ metadata.gz: a842ca5a5e5b4fea18f01b5e389bff09fa1666d3a86a7c284fdf8f62143eb36ad60031b593d16b5f97dfd2d0c58485262993eb358771818cf1a3359622dee89c
7
+ data.tar.gz: f964e9e738031bb14e61d516cb836a152812002ca0d396809ac4d772f31d1343c763c457f174ccc9dad065865a3838e578d0b5edaf345cb3e26f3d1797b623d0
@@ -9,17 +9,18 @@ module Spritely
9
9
 
10
10
  def_delegators :collection, :find, :width, :height, :images
11
11
 
12
- attr_reader :name, :glob, :environment, :options
12
+ attr_reader :name, :environment, :options, :directory, :glob
13
13
 
14
14
  def initialize(name, environment, options)
15
15
  @name = name
16
- @glob = [name, "*.png"].join("/")
17
16
  @environment = environment
18
- @options = options
17
+ @options = options.dup
18
+ @directory = @options.delete(:directory) || name
19
+ @glob = [directory, "*.png"].join("/")
19
20
  end
20
21
 
21
22
  def inspect
22
- "#<Spritely::SpriteMap name=#{name} options=#{options}>"
23
+ "#<Spritely::SpriteMap name=#{name} directory=#{directory} options=#{options}>"
23
24
  end
24
25
 
25
26
  def cache_key
@@ -4,6 +4,7 @@ module Spritely
4
4
  module Sprockets
5
5
  # Converts Sprockets directives from this:
6
6
  #
7
+ # //= directory foo/bar
7
8
  # //= repeat arrow true
8
9
  # //= spacing arrow 10
9
10
  # //= position another-image right
@@ -12,6 +13,7 @@ module Spritely
12
13
  # To this:
13
14
  #
14
15
  # {
16
+ # directory: 'foo/bar',
15
17
  # global: { spacing: 5 },
16
18
  # images: {
17
19
  # 'arrow' => { repeat: 'true', spacing: '10' },
@@ -23,7 +25,7 @@ module Spritely
23
25
  IMAGE_DIRECTIVES = %w(repeat position spacing).freeze
24
26
 
25
27
  def _call(input)
26
- @sprite_directives = { global: {}, images: {} }
28
+ @sprite_directives = { directory: nil, global: {}, images: {} }
27
29
 
28
30
  super.tap do
29
31
  merge_global_options!
@@ -32,6 +34,10 @@ module Spritely
32
34
  end
33
35
  end
34
36
 
37
+ def process_directory_directive(value)
38
+ @sprite_directives[:directory] = value
39
+ end
40
+
35
41
  (GLOBAL_DIRECTIVES + IMAGE_DIRECTIVES).uniq.each do |directive|
36
42
  define_method("process_#{directive}_directive") do |image_or_value, value_or_nil = nil|
37
43
  if value_or_nil
@@ -1,3 +1,3 @@
1
1
  module Spritely
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1 @@
1
+ //= directory weird/sprite-images
@@ -15,6 +15,20 @@ describe 'Precompilation', :integration do
15
15
  expect(sprite_files.length).to eq(1)
16
16
  end
17
17
 
18
+ it 'should compile a sprite that has no directives' do
19
+ runner %~Rails.application.assets["sprites/empty.png"].write_to("compiled-sprite.png")~
20
+ compiled_sprite = ChunkyPNG::Image.from_file('compiled-sprite.png')
21
+ correct_sprite = ChunkyPNG::Image.from_file(File.join(__dir__, '..', 'fixtures', 'correct-empty-sprite.png'))
22
+ expect(compiled_sprite).to eq(correct_sprite)
23
+ end
24
+
25
+ it 'should compile all of the assets from a custom directory' do
26
+ runner %~Rails.application.assets["sprites/weird.png"].write_to("compiled-sprite.png")~
27
+ compiled_sprite = ChunkyPNG::Image.from_file('compiled-sprite.png')
28
+ correct_sprite = ChunkyPNG::Image.from_file(File.join(__dir__, '..', 'fixtures', 'correct-weird-sprite.png'))
29
+ expect(compiled_sprite).to eq(correct_sprite)
30
+ end
31
+
18
32
  it 'should compile all of the assets necessary when sprites have been pre-generated' do
19
33
  render_asset('sprites.css')
20
34
  compile_assets
@@ -1,16 +1,25 @@
1
1
  require 'spec_helper'
2
+ require 'active_support/core_ext/hash/except'
2
3
 
3
4
  describe Spritely::SpriteMap do
4
- let(:options) { { global: {}, images: { 'some-new-image' => { x: '123', y: '456' }, 'another-image' => { repeat: 'true' } } } }
5
+ let(:directory) { nil }
6
+ let(:options) { { directory: directory, global: {}, images: { 'some-new-image' => { x: '123', y: '456' }, 'another-image' => { repeat: 'true' } } } }
5
7
  let(:environment) { double(paths: ["#{__dir__}/../fixtures"]) }
6
8
 
7
9
  subject { Spritely::SpriteMap.new('test', environment, options) }
8
10
 
9
11
  its(:name) { should eq('test') }
10
- its(:glob) { should eq('test/*.png') }
11
12
  its(:environment) { should eq(environment) }
12
- its(:options) { should eq(options) }
13
- its(:inspect) { should eq("#<Spritely::SpriteMap name=test options=#{options}>") }
13
+ its(:options) { should eq(options.except(:directory)) }
14
+ its(:directory) { should eq('test') }
15
+ its(:glob) { should eq('test/*.png') }
16
+ its(:inspect) { should eq("#<Spritely::SpriteMap name=test directory=test options=#{options.except(:directory)}>") }
17
+
18
+ context 'the directory is set' do
19
+ let(:directory) { 'test/sprite-images' }
20
+
21
+ its(:directory) { should eq('test/sprite-images') }
22
+ end
14
23
 
15
24
  describe '#cache_key' do
16
25
  before { allow(subject).to receive(:collection).and_return(double(to_s: 'collection cache value')) }
@@ -21,7 +30,7 @@ describe Spritely::SpriteMap do
21
30
  describe '#collection' do
22
31
  let(:collection) { double(find: 'find value', width: 'width value', height: 'height value', images: 'images value') }
23
32
 
24
- before { allow(Spritely::Collection).to receive(:create).with(["#{__dir__}/../fixtures/test/foo.png"], options).and_return(collection) }
33
+ before { allow(Spritely::Collection).to receive(:create).with(["#{__dir__}/../fixtures/test/foo.png"], options.except(:directory)).and_return(collection) }
25
34
 
26
35
  its(:collection) { should eq(collection) }
27
36
 
@@ -14,6 +14,7 @@ describe Spritely::Sprockets::Preprocessor do
14
14
  preprocessor._call(input)
15
15
 
16
16
  expect(input[:metadata][:sprite_directives]).to eq(
17
+ directory: nil,
17
18
  global: { spacing: '901', position: 'left' },
18
19
  images: {
19
20
  "some-new-image" => { spacing: '789', position: 'right' },
@@ -23,6 +24,25 @@ describe Spritely::Sprockets::Preprocessor do
23
24
  )
24
25
  end
25
26
 
27
+ describe 'overriding the directory' do
28
+ let(:data) { "//= directory foo/sprites" }
29
+ let(:input) { {
30
+ data: data,
31
+ filename: "sprites/foo.png.sprite",
32
+ metadata: {}
33
+ } }
34
+
35
+ it 'saves the processed options as part of the metadata' do
36
+ preprocessor._call(input)
37
+
38
+ expect(input[:metadata][:sprite_directives]).to eq(
39
+ directory: 'foo/sprites',
40
+ global: {},
41
+ images: {}
42
+ )
43
+ end
44
+ end
45
+
26
46
  describe 'invalid global option' do
27
47
  let(:data) { "//= repeat true" }
28
48
 
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: 1.1.0
4
+ version: 1.2.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: 2016-06-09 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chunky_png
@@ -183,16 +183,22 @@ files:
183
183
  - lib/spritely/sprockets/preprocessor.rb
184
184
  - lib/spritely/sprockets/transformer.rb
185
185
  - lib/spritely/version.rb
186
+ - spec/fixtures/correct-empty-sprite.png
186
187
  - spec/fixtures/correct-sprite.png
188
+ - spec/fixtures/correct-weird-sprite.png
187
189
  - spec/fixtures/rails-app-changes/app/assets/images/application/dropdown-arrow.png
188
190
  - spec/fixtures/rails-app-changes/app/assets/stylesheets/sprites.css.scss
189
191
  - spec/fixtures/rails-app/app/assets/images/application/background.png
190
192
  - spec/fixtures/rails-app/app/assets/images/application/fool.png
191
193
  - spec/fixtures/rails-app/app/assets/images/application/football.png
192
194
  - spec/fixtures/rails-app/app/assets/images/application/mario.png
195
+ - spec/fixtures/rails-app/app/assets/images/empty/fool.png
193
196
  - spec/fixtures/rails-app/app/assets/images/foo/fool.png
194
197
  - spec/fixtures/rails-app/app/assets/images/sprites/application.png.sprite
198
+ - spec/fixtures/rails-app/app/assets/images/sprites/empty.png.sprite
195
199
  - spec/fixtures/rails-app/app/assets/images/sprites/foo.png.sprite
200
+ - spec/fixtures/rails-app/app/assets/images/sprites/weird.png.sprite
201
+ - spec/fixtures/rails-app/app/assets/images/weird/sprite-images/mario.png
196
202
  - spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss
197
203
  - spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss
198
204
  - spec/fixtures/rails-app/config/initializers/assets.rb
@@ -234,14 +240,20 @@ specification_version: 4
234
240
  summary: Hooks into the Sprockets asset packaging system to allow you to easily generate
235
241
  sprite maps
236
242
  test_files:
243
+ - spec/fixtures/correct-empty-sprite.png
237
244
  - spec/fixtures/correct-sprite.png
245
+ - spec/fixtures/correct-weird-sprite.png
238
246
  - spec/fixtures/rails-app/app/assets/images/application/background.png
239
247
  - spec/fixtures/rails-app/app/assets/images/application/fool.png
240
248
  - spec/fixtures/rails-app/app/assets/images/application/football.png
241
249
  - spec/fixtures/rails-app/app/assets/images/application/mario.png
250
+ - spec/fixtures/rails-app/app/assets/images/empty/fool.png
242
251
  - spec/fixtures/rails-app/app/assets/images/foo/fool.png
243
252
  - spec/fixtures/rails-app/app/assets/images/sprites/application.png.sprite
253
+ - spec/fixtures/rails-app/app/assets/images/sprites/empty.png.sprite
244
254
  - spec/fixtures/rails-app/app/assets/images/sprites/foo.png.sprite
255
+ - spec/fixtures/rails-app/app/assets/images/sprites/weird.png.sprite
256
+ - spec/fixtures/rails-app/app/assets/images/weird/sprite-images/mario.png
245
257
  - spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss
246
258
  - spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss
247
259
  - spec/fixtures/rails-app/config/initializers/assets.rb