spritely 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spritely/sass_functions.rb +5 -0
- data/lib/spritely/version.rb +1 -1
- data/spec/fixtures/rails-app/app/assets/images/foo/fool.png +0 -0
- data/spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss +8 -0
- data/spec/integration/stylesheet_spec.rb +10 -0
- data/spec/spritely/sass_functions_spec.rb +38 -21
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41e28bf3c683cf51ded0b5bf335e09274ba130c0
|
4
|
+
data.tar.gz: 0f2b23688154ab07300b3d14d7184d84af3d2eec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95f01f44df4c8d559fa3f2fbffa5cd5d972354d3471b025507747d99fc2d2e09cf9774062665e22586417c032f1763754779f4bfca9c1a3662b1cf1621166211
|
7
|
+
data.tar.gz: a23a5f9d76f0a8c34d127c2963ce740174c54b8efff1c633c3693c1b17e6b3d184404feb03b6f0de0c181a9e5c4c89d05d1ead3b049f9af3c949bc3bd8a813f0
|
@@ -4,6 +4,7 @@ module Spritely
|
|
4
4
|
module SassFunctions
|
5
5
|
def spritely_map(glob, kwargs = {})
|
6
6
|
SpriteMap.create(glob.value, kwargs).tap do |sprite_map|
|
7
|
+
reset_sprockets_directory_cache!
|
7
8
|
sprite_map.files.each do |file|
|
8
9
|
sprockets_context.depend_on(file)
|
9
10
|
sprockets_context.depend_on_asset(file)
|
@@ -57,6 +58,10 @@ module Spritely
|
|
57
58
|
def find_image(sprite_map, image_name)
|
58
59
|
sprite_map.find(image_name.value) || raise(Sass::SyntaxError, "No image '#{image_name.value}' found in sprite map '#{sprite_map.name}'.")
|
59
60
|
end
|
61
|
+
|
62
|
+
def reset_sprockets_directory_cache!
|
63
|
+
sprockets_context.environment.send(:trail).instance_variable_get(:@entries).delete(Spritely.directory.to_s)
|
64
|
+
end
|
60
65
|
end
|
61
66
|
end
|
62
67
|
|
data/lib/spritely/version.rb
CHANGED
Binary file
|
@@ -0,0 +1,8 @@
|
|
1
|
+
$foo-sprite: spritely-map("foo/*.png", $spacing: 5px);
|
2
|
+
|
3
|
+
#foo {
|
4
|
+
background-image: spritely-url($foo-sprite);
|
5
|
+
background-position: spritely-position($foo-sprite, "fool");
|
6
|
+
width: spritely-width($foo-sprite, "fool");
|
7
|
+
height: spritely-height($foo-sprite, "fool");
|
8
|
+
}
|
@@ -25,4 +25,14 @@ describe 'Stylesheet generation', :integration do
|
|
25
25
|
CSS
|
26
26
|
) }
|
27
27
|
end
|
28
|
+
|
29
|
+
describe 'multiple sprite maps across files' do
|
30
|
+
it 'should produce the correct asset URL for both sprites' do
|
31
|
+
compile_assets
|
32
|
+
compiled_css = File.read(Dir.glob(File.join('public', 'assets', 'application-*.css')).first)
|
33
|
+
expect(compiled_css).to include('url(/assets/sprites/application')
|
34
|
+
expect(compiled_css).to include('url(/assets/sprites/foo')
|
35
|
+
expect(compiled_css).to_not include('url(/sprites/')
|
36
|
+
end
|
37
|
+
end
|
28
38
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'sprockets'
|
2
3
|
|
3
4
|
describe Spritely::SassFunctions do
|
4
5
|
class SpriteMapDouble < Sass::Script::Literal
|
@@ -6,23 +7,15 @@ describe Spritely::SassFunctions do
|
|
6
7
|
def files; []; end
|
7
8
|
end
|
8
9
|
|
9
|
-
module AssetUrlModule
|
10
|
-
def asset_url(path)
|
11
|
-
Sass::Script::String.new("url(#{path})")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
10
|
let(:sprite_map) { SpriteMapDouble.new }
|
16
11
|
let(:image) { double(left: 10, top: 12, width: 25, height: 50) }
|
17
12
|
|
18
13
|
before do
|
14
|
+
allow(Spritely).to receive(:directory).and_return('spritely-directory')
|
19
15
|
allow(Spritely::SpriteMap).to receive(:create).and_return(sprite_map)
|
20
16
|
allow(sprite_map).to receive(:find).with('bar').and_return(image)
|
21
17
|
end
|
22
18
|
|
23
|
-
before(:all) { ::Sass::Script::Functions.send(:include, AssetUrlModule) }
|
24
|
-
after(:all) { ::Sass::Script::Functions.send(:undef_method, :asset_url) }
|
25
|
-
|
26
19
|
shared_examples "a sprite function that checks image existence" do
|
27
20
|
let(:image) { nil }
|
28
21
|
|
@@ -31,51 +24,75 @@ describe Spritely::SassFunctions do
|
|
31
24
|
end
|
32
25
|
end
|
33
26
|
|
27
|
+
shared_examples "a sprite function that resets the sprockets directory cache" do
|
28
|
+
it 'should clear out the trail entries' do
|
29
|
+
subject
|
30
|
+
expect(environment.send(:trail).instance_variable_get(:@entries)).to_not have_key('spritely-directory')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
34
|
describe '#spritely_url' do
|
35
|
-
subject { evaluate("spritely-url(spritely-map('test/*.png'))") }
|
35
|
+
subject { evaluate(".background-image { background-image: spritely-url(spritely-map('test/*.png')); }") }
|
36
|
+
|
37
|
+
it_should_behave_like "a sprite function that resets the sprockets directory cache"
|
36
38
|
|
37
|
-
it { should eq(
|
39
|
+
it { should eq(".background-image {\n background-image: url(sprites/test.png); }\n") }
|
38
40
|
end
|
39
41
|
|
40
42
|
describe '#spritely_position' do
|
41
|
-
subject { evaluate("spritely-position(spritely-map('test/*.png'), 'bar')") }
|
43
|
+
subject { evaluate(".background-position { background-position: spritely-position(spritely-map('test/*.png'), 'bar'); }") }
|
42
44
|
|
43
45
|
it_should_behave_like "a sprite function that checks image existence"
|
46
|
+
it_should_behave_like "a sprite function that resets the sprockets directory cache"
|
44
47
|
|
45
|
-
it { should eq(
|
48
|
+
it { should eq(".background-position {\n background-position: -10px -12px; }\n") }
|
46
49
|
|
47
50
|
context 'the positions are both 0' do
|
48
51
|
let(:image) { double(left: 0, top: 0) }
|
49
52
|
|
50
|
-
it { should eq(
|
53
|
+
it { should eq(".background-position {\n background-position: 0 0; }\n") }
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
54
57
|
describe '#spritely_background' do
|
55
|
-
subject { evaluate("spritely-background(spritely-map('test/*.png'), 'bar')") }
|
58
|
+
subject { evaluate(".background { background: spritely-background(spritely-map('test/*.png'), 'bar'); }") }
|
56
59
|
|
57
60
|
it_should_behave_like "a sprite function that checks image existence"
|
61
|
+
it_should_behave_like "a sprite function that resets the sprockets directory cache"
|
58
62
|
|
59
|
-
it { should eq(
|
63
|
+
it { should eq(".background {\n background: url(sprites/test.png) -10px -12px; }\n") }
|
60
64
|
end
|
61
65
|
|
62
66
|
describe '#spritely_width' do
|
63
|
-
subject { evaluate("spritely-width(spritely-map('test/*.png'), 'bar')") }
|
67
|
+
subject { evaluate(".width { width: spritely-width(spritely-map('test/*.png'), 'bar'); }") }
|
64
68
|
|
65
69
|
it_should_behave_like "a sprite function that checks image existence"
|
70
|
+
it_should_behave_like "a sprite function that resets the sprockets directory cache"
|
66
71
|
|
67
|
-
it { should eq(
|
72
|
+
it { should eq(".width {\n width: 25px; }\n") }
|
68
73
|
end
|
69
74
|
|
70
75
|
describe '#spritely_height' do
|
71
|
-
subject { evaluate("spritely-height(spritely-map('test/*.png'), 'bar')") }
|
76
|
+
subject { evaluate(".height { height: spritely-height(spritely-map('test/*.png'), 'bar'); }") }
|
72
77
|
|
73
78
|
it_should_behave_like "a sprite function that checks image existence"
|
79
|
+
it_should_behave_like "a sprite function that resets the sprockets directory cache"
|
74
80
|
|
75
|
-
it { should eq(
|
81
|
+
it { should eq(".height {\n height: 50px; }\n") }
|
76
82
|
end
|
77
83
|
|
78
84
|
def evaluate(value)
|
79
|
-
|
85
|
+
Sprockets::ScssTemplate.new { value }.evaluate(environment.context_class.new(environment, nil, nil), nil)
|
86
|
+
end
|
87
|
+
|
88
|
+
def environment
|
89
|
+
@environment ||= Sprockets::Environment.new.tap do |environment|
|
90
|
+
environment.send(:trail).instance_variable_set(:@entries, {'spritely-directory' => 'blah'})
|
91
|
+
environment.context_class.class_eval do
|
92
|
+
def asset_path(path, options = {})
|
93
|
+
path
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
80
97
|
end
|
81
98
|
end
|
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: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Robbin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|
@@ -166,7 +166,9 @@ files:
|
|
166
166
|
- spec/fixtures/rails-app/app/assets/images/application/fool.png
|
167
167
|
- spec/fixtures/rails-app/app/assets/images/application/football.png
|
168
168
|
- spec/fixtures/rails-app/app/assets/images/application/mario.png
|
169
|
+
- spec/fixtures/rails-app/app/assets/images/foo/fool.png
|
169
170
|
- spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss
|
171
|
+
- spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss
|
170
172
|
- spec/fixtures/test/foo.png
|
171
173
|
- spec/integration/precompilation_spec.rb
|
172
174
|
- spec/integration/stylesheet_spec.rb
|
@@ -213,7 +215,9 @@ test_files:
|
|
213
215
|
- spec/fixtures/rails-app/app/assets/images/application/fool.png
|
214
216
|
- spec/fixtures/rails-app/app/assets/images/application/football.png
|
215
217
|
- spec/fixtures/rails-app/app/assets/images/application/mario.png
|
218
|
+
- spec/fixtures/rails-app/app/assets/images/foo/fool.png
|
216
219
|
- spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss
|
220
|
+
- spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss
|
217
221
|
- spec/fixtures/test/foo.png
|
218
222
|
- spec/integration/precompilation_spec.rb
|
219
223
|
- spec/integration/stylesheet_spec.rb
|