fixed issue with showing positions and made the internal api consistant with the documentation
This commit is contained in:
parent
660c5697db
commit
6cba5520aa
@ -49,27 +49,27 @@ module Compass
|
||||
end
|
||||
|
||||
def get_var_file(var)
|
||||
options.get_var "#{name}_#{var}"
|
||||
options.get_var "#{base.name}_#{name}_#{var}"
|
||||
end
|
||||
|
||||
# Value of <tt> $#{name}-repeat </tt> or <tt> $repeat </tt>
|
||||
def repeat
|
||||
(get_var_file("repeat") || options.get_var("repeat") || Sass::Script::String.new("no-repeat")).value
|
||||
@repeat ||= (get_var_file("repeat") || options.get_var("repeat") || Sass::Script::String.new("no-repeat")).value
|
||||
end
|
||||
|
||||
# Value of <tt> $#{name}-position </tt> or <tt> $position </tt> defaults to <tt>0px</tt>
|
||||
def position
|
||||
get_var_file("position") || options.get_var("position") || Sass::Script::Number.new(0, ["px"])
|
||||
@position||= get_var_file("position") || options.get_var("position") || Sass::Script::Number.new(0, ["px"])
|
||||
end
|
||||
|
||||
# Offset within the sprite
|
||||
def offset
|
||||
(position.unitless? || position.unit_str == "px") ? position.value : 0
|
||||
@offset ||= (position.unitless? || position.unit_str == "px") ? position.value : 0
|
||||
end
|
||||
|
||||
# Spacing between this image and the next
|
||||
def spacing
|
||||
(get_var_file("spacing") || options.get_var("spacing") || Sass::Script::Number.new(0, ['px'])).value
|
||||
@spacing ||= (get_var_file("spacing") || options.get_var("spacing") || Sass::Script::Number.new(0, ['px'])).value
|
||||
end
|
||||
|
||||
# MD5 hash of this file
|
||||
|
@ -167,9 +167,9 @@ $#{name}-#{sprite_name}-repeat: $#{name}-repeat !default;
|
||||
|
||||
content += "\n$#{name}-sprites: sprite-map(\"#{uri}\", \n$layout: $#{name}-layout, \n$cleanup: $#{name}-clean-up,\n"
|
||||
content += sprites.map do |sprite_name|
|
||||
%Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position,
|
||||
$#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing,
|
||||
$#{sprite_name}-repeat: $#{name}-#{sprite_name}-repeat}
|
||||
%Q{ $#{name}-#{sprite_name}-position: $#{name}-#{sprite_name}-position,
|
||||
$#{name}-#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing,
|
||||
$#{name}-#{sprite_name}-repeat: $#{name}-#{sprite_name}-repeat}
|
||||
end.join(",\n")
|
||||
content += ");"
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ class SpritesImageTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
test 'image type is "global"' do
|
||||
image = test_image "ten_by_ten_repeat" => Sass::Script::String.new('global')
|
||||
image = test_image "selectors_ten_by_ten_repeat" => Sass::Script::String.new('global')
|
||||
assert_equal 'global', image.repeat
|
||||
end
|
||||
|
||||
@ -61,7 +61,7 @@ class SpritesImageTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
test 'image position' do
|
||||
image = test_image "ten_by_ten_position" => Sass::Script::Number.new(100, ["px"])
|
||||
image = test_image "selectors_ten_by_ten_position" => Sass::Script::Number.new(100, ["px"])
|
||||
assert_equal 100, image.position.value
|
||||
end
|
||||
|
||||
@ -72,7 +72,7 @@ class SpritesImageTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
test 'offset' do
|
||||
image = test_image "ten_by_ten_position" => Sass::Script::Number.new(100, ["px"])
|
||||
image = test_image "selectors_ten_by_ten_position" => Sass::Script::Number.new(100, ["px"])
|
||||
assert_equal 100, image.offset
|
||||
end
|
||||
|
||||
|
@ -92,7 +92,7 @@ class SpriteMapTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
it "should layout vertical with position" do
|
||||
base = sprite_map_test("ten_by_ten_active_position" => Sass::Script::Number.new(10, ['px']))
|
||||
base = sprite_map_test("selectors_ten_by_ten_active_position" => Sass::Script::Number.new(10, ['px']))
|
||||
assert_equal [0, 10, 0, 0], base.images.map(&:left)
|
||||
end
|
||||
|
||||
@ -158,7 +158,7 @@ class SpriteMapTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
it "should layout horizontaly with position" do
|
||||
base = horizontal("ten_by_ten_active_position" => Sass::Script::Number.new(10, ['px']))
|
||||
base = horizontal("selectors_ten_by_ten_active_position" => Sass::Script::Number.new(10, ['px']))
|
||||
assert_equal [0, 10, 0, 0], base.images.map(&:top)
|
||||
end
|
||||
|
||||
@ -198,5 +198,10 @@ class SpriteMapTest < Test::Unit::TestCase
|
||||
assert_equal 'nested/squares', base.path
|
||||
end
|
||||
|
||||
test "should have correct position on ten-by-ten" do
|
||||
percent = Sass::Script::Number.new(50, ['%'])
|
||||
base = sprite_map_test(@options.merge('selectors_ten_by_ten_position' => percent))
|
||||
assert_equal percent, base.image_for('ten-by-ten').position
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user