spritely 1.0.0 → 1.1.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/sass_functions.rb +19 -7
- data/lib/spritely/version.rb +1 -1
- data/spec/spritely/sass_functions_spec.rb +32 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab534f8d3de68e48fe062b507a94502cc9f7ab5d
|
4
|
+
data.tar.gz: ff98e8e98cf0bf235bf0d2c09087d3682c54876b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 849dcbfe7926d77b285eb087a0adabb641e423c25f1583c755a025d5d60b7a7f94337591ac119a928cfbec4ecf0d31a998f10656771c11fc18abe0b548004d33
|
7
|
+
data.tar.gz: 550db56989efc700924c785c6846673968e9c3b777d128c889f400a081f54af2a9838a8c6970d9a72108e8b4f2280f7b63191b3489edda126566f662046d3bbe
|
@@ -27,16 +27,24 @@ module Spritely
|
|
27
27
|
|
28
28
|
::Sass::Script::Functions.declare :spritely_background, [:sprite_name, :image_name]
|
29
29
|
|
30
|
-
def spritely_width(sprite_name, image_name)
|
31
|
-
image =
|
30
|
+
def spritely_width(sprite_name, image_name = nil)
|
31
|
+
image = if image_name
|
32
|
+
find_image(sprite_name, image_name)
|
33
|
+
else
|
34
|
+
find_sprite_map(sprite_name)
|
35
|
+
end
|
32
36
|
|
33
37
|
Sass::Script::Number.new(image.width, ['px'])
|
34
38
|
end
|
35
39
|
|
36
40
|
::Sass::Script::Functions.declare :spritely_width, [:sprite_name, :image_name]
|
37
41
|
|
38
|
-
def spritely_height(sprite_name, image_name)
|
39
|
-
image =
|
42
|
+
def spritely_height(sprite_name, image_name = nil)
|
43
|
+
image = if image_name
|
44
|
+
find_image(sprite_name, image_name)
|
45
|
+
else
|
46
|
+
find_sprite_map(sprite_name)
|
47
|
+
end
|
40
48
|
|
41
49
|
Sass::Script::Number.new(image.height, ['px'])
|
42
50
|
end
|
@@ -46,15 +54,19 @@ module Spritely
|
|
46
54
|
private
|
47
55
|
|
48
56
|
def find_image(sprite_name, image_name)
|
57
|
+
sprite_map = find_sprite_map(sprite_name)
|
58
|
+
|
59
|
+
sprite_map.find(image_name.value) || raise(Sass::SyntaxError, "No image '#{image_name.value}' found in sprite map '#{sprite_map.name}'.")
|
60
|
+
end
|
61
|
+
|
62
|
+
def find_sprite_map(sprite_name)
|
49
63
|
sprockets_context.link_asset("sprites/#{sprite_name.value}.png")
|
50
64
|
|
51
|
-
|
65
|
+
sprite_maps.fetch(sprite_name.value) do |name|
|
52
66
|
asset = sprockets_environment.find_asset("sprites/#{name}.png.sprite") || raise(Sass::SyntaxError, "No sprite map '#{name}' found.")
|
53
67
|
|
54
68
|
sprite_maps[name] = SpriteMap.new(name, sprockets_environment, asset.metadata[:sprite_directives])
|
55
69
|
end
|
56
|
-
|
57
|
-
sprite_map.find(image_name.value) || raise(Sass::SyntaxError, "No image '#{image_name.value}' found in sprite map '#{sprite_map.name}'.")
|
58
70
|
end
|
59
71
|
|
60
72
|
def sprite_maps
|
data/lib/spritely/version.rb
CHANGED
@@ -3,7 +3,7 @@ require 'sprockets'
|
|
3
3
|
|
4
4
|
describe Spritely::SassFunctions do
|
5
5
|
let(:asset) { double(metadata: { sprite_directives: 'directives' }) }
|
6
|
-
let(:sprite_map) { double(name: 'test') }
|
6
|
+
let(:sprite_map) { double(name: 'test', width: 100, height: 200) }
|
7
7
|
let(:image) { double(left: 10, top: 12, width: 25, height: 50) }
|
8
8
|
|
9
9
|
before do
|
@@ -12,7 +12,7 @@ describe Spritely::SassFunctions do
|
|
12
12
|
allow(sprite_map).to receive(:find).with('bar').and_return(image)
|
13
13
|
end
|
14
14
|
|
15
|
-
shared_examples "a sprite function that checks sprite map
|
15
|
+
shared_examples "a sprite function that checks sprite map existence" do
|
16
16
|
context "the sprite map doesn't exist" do
|
17
17
|
let(:asset) { nil }
|
18
18
|
|
@@ -20,6 +20,10 @@ describe Spritely::SassFunctions do
|
|
20
20
|
expect { subject }.to raise_error(Sass::SyntaxError, "No sprite map 'test' found.")
|
21
21
|
end
|
22
22
|
end
|
23
|
+
end
|
24
|
+
|
25
|
+
shared_examples "a sprite function that checks sprite map and image existence" do
|
26
|
+
it_should_behave_like "a sprite function that checks sprite map existence"
|
23
27
|
|
24
28
|
context "the image doesn't exist in the sprite map" do
|
25
29
|
let(:image) { nil }
|
@@ -59,19 +63,39 @@ describe Spritely::SassFunctions do
|
|
59
63
|
end
|
60
64
|
|
61
65
|
describe '#spritely_width' do
|
62
|
-
|
66
|
+
describe "image width" do
|
67
|
+
subject { evaluate(".width { width: spritely-width('test', 'bar'); }") }
|
63
68
|
|
64
|
-
|
69
|
+
it_should_behave_like "a sprite function that checks sprite map and image existence"
|
70
|
+
|
71
|
+
it { should eq(".width {\n width: 25px; }\n") }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "sprite width" do
|
75
|
+
subject { evaluate(".width { width: spritely-width('test'); }") }
|
65
76
|
|
66
|
-
|
77
|
+
it_should_behave_like "a sprite function that checks sprite map existence"
|
78
|
+
|
79
|
+
it { should eq(".width {\n width: 100px; }\n") }
|
80
|
+
end
|
67
81
|
end
|
68
82
|
|
69
83
|
describe '#spritely_height' do
|
70
|
-
|
84
|
+
describe "image width" do
|
85
|
+
subject { evaluate(".height { height: spritely-height('test', 'bar'); }") }
|
71
86
|
|
72
|
-
|
87
|
+
it_should_behave_like "a sprite function that checks sprite map and image existence"
|
88
|
+
|
89
|
+
it { should eq(".height {\n height: 50px; }\n") }
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "sprite width" do
|
93
|
+
subject { evaluate(".height { height: spritely-height('test'); }") }
|
73
94
|
|
74
|
-
|
95
|
+
it_should_behave_like "a sprite function that checks sprite map existence"
|
96
|
+
|
97
|
+
it { should eq(".height {\n height: 200px; }\n") }
|
98
|
+
end
|
75
99
|
end
|
76
100
|
|
77
101
|
def evaluate(value)
|
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.
|
4
|
+
version: 1.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: 2016-
|
11
|
+
date: 2016-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|