added default spacing

This commit is contained in:
Nico Hagenburger 2010-10-17 15:44:29 +02:00 committed by Chris Eppstein
parent 3e7cd28635
commit 7077b76225
2 changed files with 23 additions and 1 deletions

View File

@ -4,11 +4,12 @@ module Compass::SassExtensions::Functions::Sprites
path, name = Compass::Sprites.path_and_name(uri) path, name = Compass::Sprites.path_and_name(uri)
y = 0 y = 0
last_spacing = 0 last_spacing = 0
default_spacing = number_from_var("#{name}-spacing")
images = Compass::Sprites.sprites(name) images = Compass::Sprites.sprites(name)
images.each do |image| images.each do |image|
current_spacing = number_from_var("#{name}-#{image[:name]}-spacing") current_spacing = number_from_var("#{name}-#{image[:name]}-spacing")
if y > 0 if y > 0
y += current_spacing > last_spacing ? current_spacing : last_spacing y += [current_spacing, last_spacing, default_spacing].max
end end
image[:y] = y image[:y] = y
y += image[:height] y += image[:height]

View File

@ -197,4 +197,25 @@ describe Compass::Sprites do
CSS CSS
end 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 end