spritely 0.3.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spritely.rb +11 -34
- data/lib/spritely/collection.rb +12 -11
- data/lib/spritely/engine.rb +4 -0
- data/lib/spritely/generators/base.rb +0 -16
- data/lib/spritely/generators/chunky_png.rb +1 -4
- data/lib/spritely/image_set.rb +2 -2
- data/lib/spritely/sass_functions.rb +30 -29
- data/lib/spritely/sprite_map.rb +14 -31
- data/lib/spritely/sprockets/preprocessor.rb +65 -0
- data/lib/spritely/sprockets/transformer.rb +43 -0
- data/lib/spritely/version.rb +1 -1
- data/spec/fixtures/rails-app-changes/app/assets/stylesheets/sprites.css.scss +10 -18
- data/spec/fixtures/rails-app/app/assets/images/sprites/application.png.sprite +5 -0
- data/spec/fixtures/rails-app/app/assets/images/sprites/foo.png.sprite +1 -0
- data/spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss +6 -14
- data/spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss +4 -6
- data/spec/integration/precompilation_spec.rb +2 -14
- data/spec/spec_helper.rb +0 -4
- data/spec/spritely/collection_spec.rb +9 -8
- data/spec/spritely/generators/chunky_png_spec.rb +8 -13
- data/spec/spritely/image_set_spec.rb +2 -8
- data/spec/spritely/sass_functions_spec.rb +38 -37
- data/spec/spritely/sprite_map_spec.rb +16 -52
- data/spec/spritely/sprockets/preprocessor_spec.rb +33 -0
- data/spec/support/rails_app_helpers.rb +4 -5
- metadata +38 -49
- data/lib/generators/spritely/install_generator.rb +0 -17
- data/lib/spritely/adapters/sprockets_2.rb +0 -13
- data/lib/spritely/adapters/sprockets_3.rb +0 -11
- data/lib/spritely/cache.rb +0 -51
- data/lib/spritely/options.rb +0 -59
- data/lib/spritely/sprockets/manifest.rb +0 -20
- data/spec/generators/spritely/install_generator_spec.rb +0 -28
- data/spec/spritely/cache_spec.rb +0 -24
- data/spec/spritely/options_spec.rb +0 -29
- data/spec/spritely_spec.rb +0 -41
- data/spec/support/shared_examples.rb +0 -40
- data/spec/support/shared_examples/sprockets_2_sass_functions_helpers.rb +0 -13
- data/spec/support/shared_examples/sprockets_3_sass_functions_helpers.rb +0 -15
data/lib/spritely/version.rb
CHANGED
@@ -1,26 +1,18 @@
|
|
1
|
-
$application-sprite: spritely-map("application/*.png",
|
2
|
-
$background-repeat: true,
|
3
|
-
$football-spacing: 100px,
|
4
|
-
$mario-spacing: 10px,
|
5
|
-
$mario-position: right,
|
6
|
-
$spacing: 5px
|
7
|
-
);
|
8
|
-
|
9
1
|
body {
|
10
|
-
background-image: spritely-url(
|
11
|
-
background-position: spritely-position(
|
2
|
+
background-image: spritely-url("application");
|
3
|
+
background-position: spritely-position("application", "background");
|
12
4
|
}
|
13
5
|
|
14
6
|
#mario {
|
15
|
-
background-image: spritely-url(
|
16
|
-
background-position: spritely-position(
|
17
|
-
width: spritely-width(
|
18
|
-
height: spritely-height(
|
7
|
+
background-image: spritely-url("application");
|
8
|
+
background-position: spritely-position("application", "mario");
|
9
|
+
width: spritely-width("application", "mario");
|
10
|
+
height: spritely-height("application", "mario");
|
19
11
|
}
|
20
12
|
|
21
13
|
#arrow {
|
22
|
-
background-image: spritely-url(
|
23
|
-
background-position: spritely-position(
|
24
|
-
width: spritely-width(
|
25
|
-
height: spritely-height(
|
14
|
+
background-image: spritely-url("application");
|
15
|
+
background-position: spritely-position("application", "dropdown-arrow");
|
16
|
+
width: spritely-width("application", "dropdown-arrow");
|
17
|
+
height: spritely-height("application", "dropdown-arrow");
|
26
18
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
//= spacing 5
|
@@ -1,19 +1,11 @@
|
|
1
|
-
$application-sprite: spritely-map("application/*.png",
|
2
|
-
$background-repeat: true,
|
3
|
-
$football-spacing: 100px,
|
4
|
-
$mario-spacing: 10px,
|
5
|
-
$mario-position: right,
|
6
|
-
$spacing: 5px
|
7
|
-
);
|
8
|
-
|
9
1
|
body {
|
10
|
-
background-image: spritely-url(
|
11
|
-
background-position: spritely-position(
|
2
|
+
background-image: spritely-url("application");
|
3
|
+
background-position: spritely-position("application", "background");
|
12
4
|
}
|
13
5
|
|
14
6
|
#mario {
|
15
|
-
background-image: spritely-url(
|
16
|
-
background-position: spritely-position(
|
17
|
-
width: spritely-width(
|
18
|
-
height: spritely-height(
|
7
|
+
background-image: spritely-url("application");
|
8
|
+
background-position: spritely-position("application", "mario");
|
9
|
+
width: spritely-width("application", "mario");
|
10
|
+
height: spritely-height("application", "mario");
|
19
11
|
}
|
@@ -1,8 +1,6 @@
|
|
1
|
-
$foo-sprite: spritely-map("foo/*.png", $spacing: 5px);
|
2
|
-
|
3
1
|
#foo {
|
4
|
-
background-image: spritely-url(
|
5
|
-
background-position: spritely-position(
|
6
|
-
width: spritely-width(
|
7
|
-
height: spritely-height(
|
2
|
+
background-image: spritely-url("foo");
|
3
|
+
background-position: spritely-position("foo", "fool");
|
4
|
+
width: spritely-width("foo", "fool");
|
5
|
+
height: spritely-height("foo", "fool");
|
8
6
|
}
|
@@ -1,14 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Precompilation', :integration do
|
4
|
-
it 'should create the sprite in the right location' do
|
5
|
-
render_asset('sprites.css')
|
6
|
-
expect(File).to exist(File.join('app', 'assets', 'images', 'sprites', 'application.png'))
|
7
|
-
end
|
8
|
-
|
9
4
|
it 'should compile the correct-looking sprite file' do
|
10
5
|
render_asset('sprites.css')
|
11
|
-
|
6
|
+
runner %~Rails.application.assets["sprites/application.png"].write_to("compiled-sprite.png")~
|
7
|
+
compiled_sprite = ChunkyPNG::Image.from_file('compiled-sprite.png')
|
12
8
|
correct_sprite = ChunkyPNG::Image.from_file(File.join(__dir__, '..', 'fixtures', 'correct-sprite.png'))
|
13
9
|
expect(compiled_sprite).to eq(correct_sprite)
|
14
10
|
end
|
@@ -26,14 +22,6 @@ describe 'Precompilation', :integration do
|
|
26
22
|
expect(sprite_files.length).to eq(1)
|
27
23
|
end
|
28
24
|
|
29
|
-
it 'should compile even if the sprite files no longer exist' do
|
30
|
-
compile_assets
|
31
|
-
FileUtils.rm_rf(Dir.glob(File.join('app', 'assets', 'images', 'sprites', '*.png')))
|
32
|
-
compile_assets
|
33
|
-
expect(File).to exist(File.join('app', 'assets', 'images', 'sprites', 'application.png'))
|
34
|
-
expect(File).to exist(File.join('app', 'assets', 'images', 'sprites', 'foo.png'))
|
35
|
-
end
|
36
|
-
|
37
25
|
it 'should correctly compile a new sprite image and CSS when files change' do
|
38
26
|
compile_assets
|
39
27
|
FileUtils.cp_r "#{__dir__}/../fixtures/rails-app-changes/.", "."
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'rspec/its'
|
3
|
-
require 'generator_spec/generator_example_group'
|
4
3
|
require 'spritely'
|
5
4
|
|
6
5
|
require 'pry-byebug'
|
@@ -12,9 +11,6 @@ RSpec.configure do |config|
|
|
12
11
|
c.syntax = :expect
|
13
12
|
end
|
14
13
|
|
15
|
-
config.include "Sprockets#{Spritely.sprockets_version}SassFunctionsHelpers".constantize, :sass_functions
|
16
|
-
|
17
14
|
config.include RailsAppHelpers, :integration
|
18
|
-
config.include GeneratorSpec::GeneratorExampleGroup, :generator
|
19
15
|
config.around(:each, :integration) { |example| within_rails_app(&example) }
|
20
16
|
end
|
@@ -4,15 +4,15 @@ describe Spritely::Collection do
|
|
4
4
|
let(:first_set) { double(repeated?: true, name: 'foo', width: 1, outer_height: 10, images: [1]) }
|
5
5
|
let(:second_set) { double(repeated?: false, name: 'bar', width: 100, outer_height: 100, images: [2, 3]) }
|
6
6
|
|
7
|
-
subject { Spritely::Collection.new(['file-1.png', 'file-2.png'], {'file-1' => {repeat: true}}) }
|
7
|
+
subject { Spritely::Collection.new(['file-1.png', 'file-2.png'], { global: { spacing: '5' }, images: { 'file-1' => { repeat: 'true' } } }) }
|
8
8
|
|
9
9
|
before do
|
10
|
-
allow(Spritely::ImageSet).to receive(:new).with('file-1.png', repeat: true).and_return(first_set)
|
11
|
-
allow(Spritely::ImageSet).to receive(:new).with('file-2.png',
|
10
|
+
allow(Spritely::ImageSet).to receive(:new).with('file-1.png', repeat: 'true').and_return(first_set)
|
11
|
+
allow(Spritely::ImageSet).to receive(:new).with('file-2.png', spacing: '5').and_return(second_set)
|
12
12
|
end
|
13
13
|
|
14
14
|
its(:files) { should eq(['file-1.png', 'file-2.png']) }
|
15
|
-
its(:options) { should eq({'file-1' => {repeat: true}}) }
|
15
|
+
its(:options) { should eq({ global: { spacing: '5' }, images: { 'file-1' => { repeat: 'true' } } }) }
|
16
16
|
its(:images) { should eq([1, 2, 3]) }
|
17
17
|
its(:height) { should eq(110) }
|
18
18
|
|
@@ -29,12 +29,12 @@ describe Spritely::Collection do
|
|
29
29
|
describe '#width' do
|
30
30
|
let(:third_set) { double(repeated?: false, width: 65, height: 100) }
|
31
31
|
|
32
|
-
subject { Spritely::Collection.new(['file-1.png', 'file-2.png', 'file-3.png'], {}) }
|
32
|
+
subject { Spritely::Collection.new(['file-1.png', 'file-2.png', 'file-3.png'], { global: {}, images: {} }) }
|
33
33
|
|
34
34
|
before do
|
35
|
-
allow(Spritely::ImageSet).to receive(:new).with('file-1.png',
|
36
|
-
allow(Spritely::ImageSet).to receive(:new).with('file-2.png',
|
37
|
-
allow(Spritely::ImageSet).to receive(:new).with('file-3.png',
|
35
|
+
allow(Spritely::ImageSet).to receive(:new).with('file-1.png', {}).and_return(first_set)
|
36
|
+
allow(Spritely::ImageSet).to receive(:new).with('file-2.png', {}).and_return(second_set)
|
37
|
+
allow(Spritely::ImageSet).to receive(:new).with('file-3.png', {}).and_return(third_set)
|
38
38
|
end
|
39
39
|
|
40
40
|
its(:width) { should eq(100) }
|
@@ -77,6 +77,7 @@ describe Spritely::Collection do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
its(:cache_key) { should eq('foobar') }
|
80
|
+
its(:to_s) { should eq('foobar') }
|
80
81
|
end
|
81
82
|
|
82
83
|
describe '#position!' do
|
@@ -1,32 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Spritely::Generators::ChunkyPng do
|
4
|
-
let(:png_canvas) { double(metadata: {}) }
|
4
|
+
let(:png_canvas) { double(metadata: {}, to_blob: "final PNG content") }
|
5
|
+
let(:images) { [OpenStruct.new(data: 'first image data', left: 1, top: 10), OpenStruct.new(data: 'second image data', left: 2, top: 20)] }
|
6
|
+
let(:sprite_map) { double(images: images, width: 100, height: 200, filename: 'blah.png', cache_key: 'cachevalue') }
|
5
7
|
|
6
8
|
subject { Spritely::Generators::ChunkyPng.new(sprite_map) }
|
7
9
|
|
8
|
-
include_examples "a generator"
|
9
|
-
|
10
10
|
before { allow(::ChunkyPNG::Image).to receive(:new).with(100, 200).and_return(png_canvas) }
|
11
11
|
|
12
|
+
its(:sprite_map) { should eq(sprite_map) }
|
13
|
+
|
12
14
|
describe '#build!' do
|
13
15
|
before do
|
14
16
|
allow(::ChunkyPNG::Image).to receive(:from_blob).with('first image data').and_return('first image chunk')
|
15
17
|
allow(::ChunkyPNG::Image).to receive(:from_blob).with('second image data').and_return('second image chunk')
|
16
18
|
end
|
17
19
|
|
18
|
-
it 'should append each image to the PNG canvas' do
|
20
|
+
it 'should append each image to the PNG canvas and output to string' do
|
19
21
|
expect(png_canvas).to receive(:replace!).with('first image chunk', 1, 10)
|
20
22
|
expect(png_canvas).to receive(:replace!).with('second image chunk', 2, 20)
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#save!' do
|
26
|
-
it 'should save the PNG canvas' do
|
27
|
-
expect(png_canvas).to receive(:save).with('blah.png', :fast_rgba)
|
28
|
-
subject.save!
|
29
|
-
expect(png_canvas.metadata).to include('cache_key' => 'cachevalue')
|
23
|
+
expect(png_canvas).to receive(:to_blob).with(:fast_rgba)
|
24
|
+
expect(subject.build!).to eq('final PNG content')
|
30
25
|
end
|
31
26
|
end
|
32
27
|
end
|
@@ -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: '10', position: 'right'} }
|
7
7
|
|
8
8
|
subject { Spritely::ImageSet.new(path, options) }
|
9
9
|
|
@@ -26,12 +26,6 @@ describe Spritely::ImageSet do
|
|
26
26
|
describe '#repeated?' do
|
27
27
|
it { should be_repeated }
|
28
28
|
|
29
|
-
context 'repeat option is passed as truthy' do
|
30
|
-
let(:options) { {repeat: 'repeat'} }
|
31
|
-
|
32
|
-
it { should be_repeated }
|
33
|
-
end
|
34
|
-
|
35
29
|
context 'repeat option is passed as false' do
|
36
30
|
let(:options) { {repeat: false} }
|
37
31
|
|
@@ -85,7 +79,7 @@ describe Spritely::ImageSet do
|
|
85
79
|
end
|
86
80
|
|
87
81
|
context 'it is also positioned to the right' do
|
88
|
-
let(:options) { {position: 'right', repeat: true} }
|
82
|
+
let(:options) { {position: 'right', repeat: 'true'} }
|
89
83
|
|
90
84
|
its(:left) { should eq(0) }
|
91
85
|
|
@@ -1,54 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'sprockets'
|
3
|
-
require 'ostruct'
|
4
3
|
|
5
|
-
describe Spritely::SassFunctions
|
6
|
-
|
7
|
-
|
8
|
-
def filename; 'test.png'; end
|
9
|
-
def files; []; end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:directory) { __dir__ }
|
13
|
-
let(:sprite_map) { SpriteMapDouble.new }
|
4
|
+
describe Spritely::SassFunctions do
|
5
|
+
let(:asset) { double(metadata: { sprite_directives: 'directives' }) }
|
6
|
+
let(:sprite_map) { double(name: 'test') }
|
14
7
|
let(:image) { double(left: 10, top: 12, width: 25, height: 50) }
|
15
8
|
|
16
9
|
before do
|
17
|
-
allow(
|
18
|
-
allow(Spritely).to
|
19
|
-
allow(Spritely::SpriteMap).to receive(:create).and_return(sprite_map)
|
10
|
+
allow(sprockets_environment).to receive(:find_asset).with('sprites/test.png.sprite').and_return(asset)
|
11
|
+
allow(Spritely::SpriteMap).to receive(:new).with('test', sprockets_environment, 'directives').and_return(sprite_map)
|
20
12
|
allow(sprite_map).to receive(:find).with('bar').and_return(image)
|
21
13
|
end
|
22
14
|
|
23
|
-
shared_examples "a sprite function that checks image existence" do
|
24
|
-
|
15
|
+
shared_examples "a sprite function that checks sprite map and image existence" do
|
16
|
+
context "the sprite map doesn't exist" do
|
17
|
+
let(:asset) { nil }
|
25
18
|
|
26
|
-
|
27
|
-
|
19
|
+
it 'should raise a nice exception' do
|
20
|
+
expect { subject }.to raise_error(Sass::SyntaxError, "No sprite map 'test' found.")
|
21
|
+
end
|
28
22
|
end
|
29
|
-
end
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
subject
|
24
|
+
context "the image doesn't exist in the sprite map" do
|
25
|
+
let(:image) { nil }
|
34
26
|
|
35
|
-
|
27
|
+
it 'should raise a nice exception' do
|
28
|
+
expect { subject }.to raise_error(Sass::SyntaxError, "No image 'bar' found in sprite map 'test'.")
|
29
|
+
end
|
36
30
|
end
|
37
31
|
end
|
38
32
|
|
39
33
|
describe '#spritely_url' do
|
40
|
-
subject { evaluate(".background-image { background-image: spritely-url(
|
41
|
-
|
42
|
-
it_should_behave_like "a sprite function that resets the sprockets directory caches"
|
34
|
+
subject { evaluate(".background-image { background-image: spritely-url('test'); }") }
|
43
35
|
|
44
36
|
it { should eq(".background-image {\n background-image: url(sprites/test.png); }\n") }
|
45
37
|
end
|
46
38
|
|
47
39
|
describe '#spritely_position' do
|
48
|
-
subject { evaluate(".background-position { background-position: spritely-position(
|
40
|
+
subject { evaluate(".background-position { background-position: spritely-position('test', 'bar'); }") }
|
49
41
|
|
50
|
-
it_should_behave_like "a sprite function that checks image existence"
|
51
|
-
it_should_behave_like "a sprite function that resets the sprockets directory caches"
|
42
|
+
it_should_behave_like "a sprite function that checks sprite map and image existence"
|
52
43
|
|
53
44
|
it { should eq(".background-position {\n background-position: -10px -12px; }\n") }
|
54
45
|
|
@@ -60,29 +51,39 @@ describe Spritely::SassFunctions, :sass_functions do
|
|
60
51
|
end
|
61
52
|
|
62
53
|
describe '#spritely_background' do
|
63
|
-
subject { evaluate(".background { background: spritely-background(
|
54
|
+
subject { evaluate(".background { background: spritely-background('test', 'bar'); }") }
|
64
55
|
|
65
|
-
it_should_behave_like "a sprite function that checks image existence"
|
66
|
-
it_should_behave_like "a sprite function that resets the sprockets directory caches"
|
56
|
+
it_should_behave_like "a sprite function that checks sprite map and image existence"
|
67
57
|
|
68
58
|
it { should eq(".background {\n background: url(sprites/test.png) -10px -12px; }\n") }
|
69
59
|
end
|
70
60
|
|
71
61
|
describe '#spritely_width' do
|
72
|
-
subject { evaluate(".width { width: spritely-width(
|
62
|
+
subject { evaluate(".width { width: spritely-width('test', 'bar'); }") }
|
73
63
|
|
74
|
-
it_should_behave_like "a sprite function that checks image existence"
|
75
|
-
it_should_behave_like "a sprite function that resets the sprockets directory caches"
|
64
|
+
it_should_behave_like "a sprite function that checks sprite map and image existence"
|
76
65
|
|
77
66
|
it { should eq(".width {\n width: 25px; }\n") }
|
78
67
|
end
|
79
68
|
|
80
69
|
describe '#spritely_height' do
|
81
|
-
subject { evaluate(".height { height: spritely-height(
|
70
|
+
subject { evaluate(".height { height: spritely-height('test', 'bar'); }") }
|
82
71
|
|
83
|
-
it_should_behave_like "a sprite function that checks image existence"
|
84
|
-
it_should_behave_like "a sprite function that resets the sprockets directory caches"
|
72
|
+
it_should_behave_like "a sprite function that checks sprite map and image existence"
|
85
73
|
|
86
74
|
it { should eq(".height {\n height: 50px; }\n") }
|
87
75
|
end
|
76
|
+
|
77
|
+
def evaluate(value)
|
78
|
+
Sprockets::ScssProcessor.call(environment: sprockets_environment, data: value, filename: "test.scss", metadata: {}, cache: Sprockets::Cache.new)[:data]
|
79
|
+
end
|
80
|
+
|
81
|
+
def sprockets_environment
|
82
|
+
@sprockets_environment ||= Sprockets::CachedEnvironment.new(Sprockets::Environment.new).tap do |sprockets_environment|
|
83
|
+
sprockets_environment.context_class.class_eval do
|
84
|
+
def link_asset(path); end
|
85
|
+
def asset_path(path, options = {}); path; end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
88
89
|
end
|
@@ -1,48 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Spritely::SpriteMap do
|
4
|
-
let(:
|
5
|
-
let(:
|
4
|
+
let(:options) { { global: {}, images: { 'some-new-image' => { x: '123', y: '456' }, 'another-image' => { repeat: 'true' } } } }
|
5
|
+
let(:environment) { double(paths: ["#{__dir__}/../fixtures"]) }
|
6
6
|
|
7
|
-
subject { Spritely::SpriteMap.new('test
|
7
|
+
subject { Spritely::SpriteMap.new('test', environment, options) }
|
8
8
|
|
9
|
-
before do
|
10
|
-
allow(Spritely).to receive_message_chain(:environment, :paths).and_return(["#{__dir__}/../fixtures"])
|
11
|
-
allow(Spritely).to receive(:directory).and_return(File)
|
12
|
-
allow(Spritely::Options).to receive(:new).with(options_hash).and_return(options_object)
|
13
|
-
end
|
14
|
-
|
15
|
-
it { should be_a(Sass::Script::Literal) }
|
16
|
-
|
17
|
-
its(:glob) { should eq('test/*.png') }
|
18
|
-
its(:options) { should eq(options_object) }
|
19
9
|
its(:name) { should eq('test') }
|
20
|
-
its(:
|
21
|
-
its(:
|
22
|
-
|
23
|
-
|
24
|
-
let(:sprite_map) { double(needs_generation?: true) }
|
25
|
-
|
26
|
-
it 'should attempt to generate the sprite' do
|
27
|
-
allow(Spritely::SpriteMap).to receive(:new).with('test/*.png').and_return(sprite_map)
|
28
|
-
expect(sprite_map).to receive(:generate!)
|
29
|
-
Spritely::SpriteMap.create('test/*.png')
|
30
|
-
end
|
31
|
-
end
|
10
|
+
its(:glob) { should eq('test/*.png') }
|
11
|
+
its(:environment) { should eq(environment) }
|
12
|
+
its(:options) { should eq(options) }
|
13
|
+
its(:inspect) { should eq("#<Spritely::SpriteMap name=test options=#{options}>") }
|
32
14
|
|
33
15
|
describe '#cache_key' do
|
34
|
-
before
|
35
|
-
allow(subject).to receive(:collection).and_return('collection value')
|
36
|
-
allow(Spritely::Cache).to receive(:generate).with(options_object, 'collection value').and_return('cache value')
|
37
|
-
end
|
16
|
+
before { allow(subject).to receive(:collection).and_return(double(to_s: 'collection cache value')) }
|
38
17
|
|
39
|
-
its(:cache_key) { should eq('
|
18
|
+
its(:cache_key) { should eq('d9e141f6c3f40279f579b62a201c8f72') }
|
40
19
|
end
|
41
20
|
|
42
21
|
describe '#collection' do
|
43
22
|
let(:collection) { double(find: 'find value', width: 'width value', height: 'height value', images: 'images value') }
|
44
23
|
|
45
|
-
before { allow(Spritely::Collection).to receive(:create).with(["#{__dir__}/../fixtures/test/foo.png"],
|
24
|
+
before { allow(Spritely::Collection).to receive(:create).with(["#{__dir__}/../fixtures/test/foo.png"], options).and_return(collection) }
|
46
25
|
|
47
26
|
its(:collection) { should eq(collection) }
|
48
27
|
|
@@ -54,29 +33,14 @@ describe Spritely::SpriteMap do
|
|
54
33
|
end
|
55
34
|
end
|
56
35
|
|
57
|
-
describe '#
|
58
|
-
|
59
|
-
expect(Spritely::Generators::ChunkyPng).to receive(:create!).with(subject)
|
60
|
-
subject.generate!
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#needs_generation?' do
|
65
|
-
let(:file_exists) { false }
|
36
|
+
describe '#save!' do
|
37
|
+
let(:generator) { double }
|
66
38
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
context 'the sprite file already exists' do
|
72
|
-
let(:file_exists) { true }
|
73
|
-
|
74
|
-
before do
|
75
|
-
allow(subject).to receive(:cache_key).and_return('value')
|
76
|
-
allow(Spritely::Cache).to receive(:busted?).with('test.png', 'value').and_return(true)
|
77
|
-
end
|
39
|
+
it 'should start the ChunkyPNG generator' do
|
40
|
+
expect(Spritely::Generators::ChunkyPng).to receive(:new).with(subject).and_return(generator)
|
41
|
+
expect(generator).to receive(:build!)
|
78
42
|
|
79
|
-
|
43
|
+
subject.save!
|
80
44
|
end
|
81
45
|
end
|
82
46
|
|