diff --git a/lib/compass/sprite_importer.rb b/lib/compass/sprite_importer.rb index e596e9a7..d46403d9 100644 --- a/lib/compass/sprite_importer.rb +++ b/lib/compass/sprite_importer.rb @@ -104,8 +104,9 @@ $#{name}-spacing: 0 !default; $#{name}-repeat: no-repeat !default; $#{name}-prefix: '' !default; $#{name}-clean-up: true !default; +$#{name}-layout:vertical !default; -#{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\", $cleanup: $#{name}-clean-up);" : generate_overrides(uri, name) } +#{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\", $layout: $#{name}-layout, $cleanup: $#{name}-clean-up);" : generate_overrides(uri, name) } // All sprites should extend this class // The #{name}-sprite mixin will do so for you. @@ -160,7 +161,7 @@ $#{name}-#{sprite_name}-repeat: $#{name}-repeat !default; SCSS end.join - content += "\n$#{name}-sprites: sprite-map(\"#{uri}\", \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| %Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position, $#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing, diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index 723dac7d..456b0063 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -603,5 +603,33 @@ class SpritesTest < Test::Unit::TestCase } CSS end + + it "should calculate corret sprite demsions when givin spacing via issue#253" do + css = render <<-SCSS + $squares-layout:horizontal; + @import "squares/*.png"; + .foo { + @include sprite-background-position($squares-sprites, "twenty-by-twenty"); + } + .bar { + @include sprite-background-position($squares-sprites, "ten-by-ten"); + } + SCSS + assert_equal [30, 20], image_size('squares-s*.png') + other_css = <<-CSS + .squares-sprite { + background: url('/squares-s161c60ad78.png') no-repeat; + } -end \ No newline at end of file + .foo { + background-position: -10px 0; + } + + .bar { + background-position: 0 0; + } + CSS + assert_correct css.gsub("\n", '').gsub(' ', ''), other_css.gsub("\n", '').gsub(' ', '') + end + +end diff --git a/test/units/sprites/image_test.rb b/test/units/sprites/image_test.rb index 6caef387..afcc0c7c 100644 --- a/test/units/sprites/image_test.rb +++ b/test/units/sprites/image_test.rb @@ -26,6 +26,7 @@ class SpritesImageTest < Test::Unit::TestCase options.stubs(:get_var).with("#{sprite_name}-repeat").returns(::OpenStruct.new(:value => @repeat)) options.stubs(:get_var).with("#{sprite_name}-spacing").returns(::OpenStruct.new(:value => @spacing)) options.stubs(:get_var).with("#{sprite_name}-position").returns(::OpenStruct.new(:value => @position)) + options.stubs(:get_var).with("layout").returns(::OpenStruct.new(:value => 'vertical')) options end diff --git a/test/units/sprites/sprite_map_test.rb b/test/units/sprites/sprite_map_test.rb index 8abb762e..9afa868a 100644 --- a/test/units/sprites/sprite_map_test.rb +++ b/test/units/sprites/sprite_map_test.rb @@ -12,7 +12,7 @@ class SpriteMapTest < Test::Unit::TestCase config.images_path = @images_tmp_path Compass.add_configuration(config) Compass.configure_sass_plugin! - @options = {'cleanup' => Sass::Script::Bool.new(true)} + @options = {'cleanup' => Sass::Script::Bool.new(true), 'layout' => Sass::Script::String.new('vertical')} @base = sprite_map_test(@options) end @@ -83,5 +83,37 @@ class SpriteMapTest < Test::Unit::TestCase @base.generate assert !File.exists?(file), "Sprite file did not get removed" end + + it "should have a vertical layout" do + assert_equal [0, 10, 20, 30], @base.images.map(&:top) + assert_equal [0, 0, 0, 0], @base.images.map(&:left) + end + + + # Horizontal tests + def horizontal + opts = @options.merge("layout" => Sass::Script::String.new('horizontal')) + sprite_map_test(opts) + end + + it "should have a horizontal layout" do + base = horizontal + assert_equal 10, base.height + assert_equal 40, base.width + end + + it "should layout images horizontaly" do + base = horizontal + assert_equal [0, 10, 20, 30], base.images.map(&:left) + assert_equal [0, 0, 0, 0], base.images.map(&:top) + end + + it "should generate a horrizontal sprite" do + base = horizontal + base.generate + assert File.exists?(base.filename) + FileUtils.rm base.filename + end + end \ No newline at end of file