added sprite_names sass function and test closes #620

This commit is contained in:
Scott Davis 2012-01-02 01:01:11 -05:00
parent 6c98ff1d5c
commit f4dda8a5d0
2 changed files with 34 additions and 1 deletions

View File

@ -9,6 +9,13 @@ module Compass::SassExtensions::Functions::Sprites
self[variable_name.to_s.gsub(/-/,"_")] self[variable_name.to_s.gsub(/-/,"_")]
end end
end end
#Returns a list of all sprite names
def sprite_names(map)
Sass::Script::List.new(map.sprite_names.map { |f| Sass::Script::String.new(f) }, ' ')
end
Sass::Script::Functions.declare :sprite_names, [:map]
# Returns the system path of the sprite file # Returns the system path of the sprite file
def sprite_path(map) def sprite_path(map)
Sass::Script::String.new(map.name_and_hash) Sass::Script::String.new(map.name_and_hash)

View File

@ -807,11 +807,37 @@ class SpritesTest < Test::Unit::TestCase
} }
.colors-blue { .colors-blue {
background-position:0 0; background-position:0 0;
}.colors-yellow { }
.colors-yellow {
background-position:0 -10px; background-position:0 -10px;
} }
CSS CSS
assert_correct clean(css), clean(other_css) assert_correct clean(css), clean(other_css)
end end
it "should have a sprite_name function that returns the names of the sprites in a sass list" do
css = render <<-SCSS
$colors-inline:true;
@import "colors/*.png";
@each $color in sprite_names($colors-sprites) {
.\#{$color} {
width:0px;
}
}
SCSS
other_css = <<-CSS
.colors-sprite {
background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAUCAAAAACRhfOKAAAAHElEQVR42mM5wQADLP8JMRlIUIvE/IdgctLTNgCHDhEQVD4ceAAAAABJRU5ErkJggg==');
}
.blue {
width:0px;
}
.yellow {
width:0px;
}
CSS
assert_correct clean(css), clean(other_css)
end
end end