Sass Colors will no longer cause an error if you use them as sprite names. closes #381
This commit is contained in:
parent
325306dcec
commit
84d207f827
@ -34,6 +34,7 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
#
|
#
|
||||||
# background: url('/images/icons.png?12345678') 0 -24px no-repeat;
|
# background: url('/images/icons.png?12345678') 0 -24px no-repeat;
|
||||||
def sprite(map, sprite, offset_x = ZERO, offset_y = ZERO)
|
def sprite(map, sprite, offset_x = ZERO, offset_y = ZERO)
|
||||||
|
sprite = convert_sprite(sprite)
|
||||||
verify_map(map)
|
verify_map(map)
|
||||||
unless sprite.is_a?(Sass::Script::String)
|
unless sprite.is_a?(Sass::Script::String)
|
||||||
raise Sass::SyntaxError, %Q(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
raise Sass::SyntaxError, %Q(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
||||||
@ -56,6 +57,7 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
|
|
||||||
# Returns the path to the original image file for the sprite with the given name
|
# Returns the path to the original image file for the sprite with the given name
|
||||||
def sprite_file(map, sprite)
|
def sprite_file(map, sprite)
|
||||||
|
sprite = convert_sprite(sprite)
|
||||||
verify_map(map, "sprite")
|
verify_map(map, "sprite")
|
||||||
verify_sprite(sprite)
|
verify_sprite(sprite)
|
||||||
if image = map.image_for(sprite.value)
|
if image = map.image_for(sprite.value)
|
||||||
@ -68,6 +70,7 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
|
|
||||||
# Returns voolean if sprite has a parent
|
# Returns voolean if sprite has a parent
|
||||||
def sprite_does_not_have_parent(map, sprite)
|
def sprite_does_not_have_parent(map, sprite)
|
||||||
|
sprite = convert_sprite(sprite)
|
||||||
verify_map map
|
verify_map map
|
||||||
verify_sprite sprite
|
verify_sprite sprite
|
||||||
Sass::Script::Bool.new map.image_for(sprite.value).parent.nil?
|
Sass::Script::Bool.new map.image_for(sprite.value).parent.nil?
|
||||||
@ -77,6 +80,7 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
|
|
||||||
# Returns boolean if sprite has the selector
|
# Returns boolean if sprite has the selector
|
||||||
def sprite_has_selector(map, sprite, selector)
|
def sprite_has_selector(map, sprite, selector)
|
||||||
|
sprite = convert_sprite(sprite)
|
||||||
verify_map map
|
verify_map map
|
||||||
verify_sprite sprite
|
verify_sprite sprite
|
||||||
unless VALID_SELECTORS.include?(selector.value)
|
unless VALID_SELECTORS.include?(selector.value)
|
||||||
@ -118,6 +122,7 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
#
|
#
|
||||||
# background-position: 3px -36px;
|
# background-position: 3px -36px;
|
||||||
def sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO)
|
def sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO)
|
||||||
|
sprite = convert_sprite(sprite)
|
||||||
verify_map(map, "sprite-position")
|
verify_map(map, "sprite-position")
|
||||||
unless sprite && sprite.is_a?(Sass::Script::String)
|
unless sprite && sprite.is_a?(Sass::Script::String)
|
||||||
raise Sass::SyntaxError, %Q(The second argument to sprite-position must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
raise Sass::SyntaxError, %Q(The second argument to sprite-position must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
||||||
@ -147,6 +152,13 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def convert_sprite(sprite)
|
||||||
|
if sprite.is_a?(Sass::Script::Color)
|
||||||
|
return Sass::Script::String.new(sprite.to_s)
|
||||||
|
end
|
||||||
|
sprite
|
||||||
|
end
|
||||||
|
|
||||||
def verify_map(map, error = "sprite")
|
def verify_map(map, error = "sprite")
|
||||||
unless map.is_a?(Compass::SassExtensions::Sprites::Base)
|
unless map.is_a?(Compass::SassExtensions::Sprites::Base)
|
||||||
missing_sprite!(error)
|
missing_sprite!(error)
|
||||||
|
@ -578,4 +578,14 @@ class SpritesTest < Test::Unit::TestCase
|
|||||||
assert_equal 2, map_files('selectors-*.png').size, "File was removed"
|
assert_equal 2, map_files('selectors-*.png').size, "File was removed"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should generate a sprite if the sprite is a colorname" do
|
||||||
|
css = render <<-SCSS
|
||||||
|
@import "colors/*.png";
|
||||||
|
a {
|
||||||
|
@include colors-sprite(blue);
|
||||||
|
}
|
||||||
|
SCSS
|
||||||
|
assert !css.empty?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user