From 6cba5520aa0cf196cfbec456f735050eefdf9ffd Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Sat, 17 Sep 2011 00:45:35 -0400 Subject: [PATCH] fixed issue with showing positions and made the internal api consistant with the documentation --- lib/compass/sass_extensions/sprites/image.rb | 10 +++++----- lib/compass/sprite_importer.rb | 6 +++--- test/units/sprites/image_test.rb | 6 +++--- test/units/sprites/sprite_map_test.rb | 9 +++++++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/compass/sass_extensions/sprites/image.rb b/lib/compass/sass_extensions/sprites/image.rb index 1b41b18f..9ea024e4 100644 --- a/lib/compass/sass_extensions/sprites/image.rb +++ b/lib/compass/sass_extensions/sprites/image.rb @@ -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 $#{name}-repeat or $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 # Value of $#{name}-position or $position defaults to 0px 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 diff --git a/lib/compass/sprite_importer.rb b/lib/compass/sprite_importer.rb index 589f36e5..9262ac08 100644 --- a/lib/compass/sprite_importer.rb +++ b/lib/compass/sprite_importer.rb @@ -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 diff --git a/test/units/sprites/image_test.rb b/test/units/sprites/image_test.rb index ffac255d..823fb0e6 100644 --- a/test/units/sprites/image_test.rb +++ b/test/units/sprites/image_test.rb @@ -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 diff --git a/test/units/sprites/sprite_map_test.rb b/test/units/sprites/sprite_map_test.rb index a70157fc..ff72467b 100644 --- a/test/units/sprites/sprite_map_test.rb +++ b/test/units/sprites/sprite_map_test.rb @@ -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 \ No newline at end of file