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
|
end
|
||||||
|
|
||||||
def get_var_file(var)
|
def get_var_file(var)
|
||||||
options.get_var "#{name}_#{var}"
|
options.get_var "#{base.name}_#{name}_#{var}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Value of <tt> $#{name}-repeat </tt> or <tt> $repeat </tt>
|
# Value of <tt> $#{name}-repeat </tt> or <tt> $repeat </tt>
|
||||||
def repeat
|
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
|
end
|
||||||
|
|
||||||
# Value of <tt> $#{name}-position </tt> or <tt> $position </tt> defaults to <tt>0px</tt>
|
# Value of <tt> $#{name}-position </tt> or <tt> $position </tt> defaults to <tt>0px</tt>
|
||||||
def position
|
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
|
end
|
||||||
|
|
||||||
# Offset within the sprite
|
# Offset within the sprite
|
||||||
def offset
|
def offset
|
||||||
(position.unitless? || position.unit_str == "px") ? position.value : 0
|
@offset ||= (position.unitless? || position.unit_str == "px") ? position.value : 0
|
||||||
end
|
end
|
||||||
|
|
||||||
# Spacing between this image and the next
|
# Spacing between this image and the next
|
||||||
def spacing
|
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
|
end
|
||||||
|
|
||||||
# MD5 hash of this file
|
# 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 += "\n$#{name}-sprites: sprite-map(\"#{uri}\", \n$layout: $#{name}-layout, \n$cleanup: $#{name}-clean-up,\n"
|
||||||
content += sprites.map do |sprite_name|
|
content += sprites.map do |sprite_name|
|
||||||
%Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position,
|
%Q{ $#{name}-#{sprite_name}-position: $#{name}-#{sprite_name}-position,
|
||||||
$#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing,
|
$#{name}-#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing,
|
||||||
$#{sprite_name}-repeat: $#{name}-#{sprite_name}-repeat}
|
$#{name}-#{sprite_name}-repeat: $#{name}-#{sprite_name}-repeat}
|
||||||
end.join(",\n")
|
end.join(",\n")
|
||||||
content += ");"
|
content += ");"
|
||||||
end
|
end
|
||||||
|
@ -52,7 +52,7 @@ class SpritesImageTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test 'image type is "global"' do
|
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
|
assert_equal 'global', image.repeat
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ class SpritesImageTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test 'image position' do
|
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
|
assert_equal 100, image.position.value
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class SpritesImageTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test 'offset' do
|
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
|
assert_equal 100, image.offset
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ class SpriteMapTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should layout vertical with position" do
|
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)
|
assert_equal [0, 10, 0, 0], base.images.map(&:left)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ class SpriteMapTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should layout horizontaly with position" do
|
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)
|
assert_equal [0, 10, 0, 0], base.images.map(&:top)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -198,5 +198,10 @@ class SpriteMapTest < Test::Unit::TestCase
|
|||||||
assert_equal 'nested/squares', base.path
|
assert_equal 'nested/squares', base.path
|
||||||
end
|
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
|
end
|
Loading…
Reference in New Issue
Block a user