diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index d68fd586..b8e97d4c 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -9,6 +9,13 @@ module Compass::SassExtensions::Functions::Sprites self[variable_name.to_s.gsub(/-/,"_")] 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 def sprite_path(map) Sass::Script::String.new(map.name_and_hash) diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index e1ef64a8..3284f995 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -807,11 +807,37 @@ class SpritesTest < Test::Unit::TestCase } .colors-blue { background-position:0 0; - }.colors-yellow { + } + .colors-yellow { background-position:0 -10px; } CSS assert_correct clean(css), clean(other_css) 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