Skip to content

Commit 266485d

Browse files
committed
Adding SASS Extension method
1 parent e0ba326 commit 266485d

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

lib/sprite/sass_extensions.rb

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
module Sprite::Sass::Extensions
22
def sprite_background(group, image)
33
sprite = sprite_data(group, image)
4-
# TODO
5-
""
4+
if sprite
5+
"url(http://github.com/'%3Cspan%20class=pl-s1%3E%3Cspan%20class=pl-kos%3E#{%3C/span%3E%3Cspan%20class=pl-s1%3Esprite%3C/span%3E%3Cspan%20class=pl-kos%3E[%3C/span%3E%3Cspan%20class=pl-pds%3E:img%3C/span%3E%3Cspan%20class=pl-kos%3E]%3C/span%3E%3Cspan%20class=pl-kos%3E}%3C/span%3E%3C/span%3E') no-repeat #{sprite[:x]}px #{sprite[:y]}px"
6+
else
7+
""
8+
end
69
end
710

811
def sprite_width(group, image)
912
sprite = sprite_data(group, image)
10-
# TODO
11-
""
13+
if sprite
14+
"#{sprite[:width]}px"
15+
else
16+
""
17+
end
1218
end
1319

1420
def sprite_height(group, image)
1521
sprite = sprite_data(group, image)
16-
# TODO
17-
""
22+
if sprite
23+
"#{sprite[:height]}px"
24+
else
25+
""
26+
end
1827
end
1928

2029
protected
2130
def sprite_data(group, image)
2231
unless @__sprite_data
23-
@__sprite_data = {
24-
"group_name" => {
25-
"image_name" => {
26-
:width => "",
27-
:height => "",
28-
:group => "dkajsdfk",
29-
:x => "",
30-
:y => ""
31-
}
32-
}
33-
}
32+
33+
# TODO: read template from !sprite_data
34+
sprite_data_path = "public/sass/sprites.yml"
35+
36+
# figure out the site root
37+
root = "./"
38+
39+
# read sprite data from yml
40+
@__sprite_data = File.open(File.join(root, sprite_data_path)) { |yf| YAML::load( yf ) }
3441
end
3542

36-
group_data = @__sprite_data[group]
43+
group_data = @__sprite_data[group.to_s]
3744
if group_data
38-
return group_data[image]
45+
return group_data[image.to_s]
3946
else
4047
nil
4148
end

0 commit comments

Comments
 (0)