diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index ab24be7a..c676ba11 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -4,11 +4,12 @@ module Compass::SassExtensions::Functions::Sprites path, name = Compass::Sprites.path_and_name(uri) y = 0 last_spacing = 0 + default_spacing = number_from_var("#{name}-spacing") images = Compass::Sprites.sprites(name) images.each do |image| current_spacing = number_from_var("#{name}-#{image[:name]}-spacing") if y > 0 - y += current_spacing > last_spacing ? current_spacing : last_spacing + y += [current_spacing, last_spacing, default_spacing].max end image[:y] = y y += image[:height] diff --git a/spec/sprites_spec.rb b/spec/sprites_spec.rb index 580525fe..dbc2df2e 100644 --- a/spec/sprites_spec.rb +++ b/spec/sprites_spec.rb @@ -196,5 +196,26 @@ describe Compass::Sprites do } CSS end + + it "should calculate the default spacing between images" do + css = render <<-SCSS + $squares-spacing: 22px; + @import "squares/*.png"; + @include all-squares-sprites; + SCSS + css.should == <<-CSS + .squares-sprite, .squares-10x10, .squares-20x20 { + background: url('/squares.png') no-repeat; + } + + .squares-10x10 { + background-position: 0 0; + } + + .squares-20x20 { + background-position: 0 -32px; + } + CSS + end end \ No newline at end of file