From c62b8e718d76b2c4936955cde289fc9287020822 Mon Sep 17 00:00:00 2001 From: Nico Hagenburger Date: Sun, 17 Oct 2010 15:44:29 +0200 Subject: [PATCH] added default spacing --- .../sass_extensions/functions/sprites.rb | 3 ++- spec/sprites_spec.rb | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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