fix a bug in sprites when the offset position is absolute.

This commit is contained in:
Chris Eppstein 2010-12-18 18:39:35 -08:00
parent 50963d7dd2
commit 638fd8f543
2 changed files with 31 additions and 5 deletions

View File

@ -60,7 +60,8 @@ module Compass::SassExtensions::Functions::Sprites
file = File.join(Compass.configuration.images_path, relative_file)
width, height = Compass::SassExtensions::Functions::ImageSize::ImageProperties.new(file).size
sprite_name = Compass::Sprites.sprite_name(relative_file)
@width = [@width, width].max
position = position_for(sprite_name)
offset = (position.unitless? || position.unit_str == "px") ? position.value : 0
@images << {
:name => sprite_name,
:file => file,
@ -69,9 +70,10 @@ module Compass::SassExtensions::Functions::Sprites
:width => width,
:repeat => repeat_for(sprite_name),
:spacing => spacing_for(sprite_name),
:position => position_for(sprite_name),
:position => position,
:digest => Digest::MD5.file(file).hexdigest
}
@width = [@width, width + offset].max
end
@images.each_with_index do |image, index|
if index == 0
@ -329,7 +331,7 @@ module Compass::SassExtensions::Functions::Sprites
if offset_x.unit_str == "%"
x = offset_x # CE: Shouldn't this be a percentage of the total width?
else
x = offset_x.value - image[:left]
x = offset_x.value + image[:left]
x = Sass::Script::Number.new(x, x == 0 ? [] : ["px"])
end
y = offset_y.value - image[:top]

View File

@ -277,7 +277,7 @@ describe Compass::Sprites do
}
.adjusted-px-1 {
background-position: -6px 0;
background-position: 14px 0;
}
.adjusted-px-2 {
@ -315,7 +315,7 @@ describe Compass::Sprites do
}
.adjusted-px-1 {
background-position: -6px 0;
background-position: 14px 0;
}
.adjusted-px-2 {
@ -348,6 +348,30 @@ describe Compass::Sprites do
image_size('squares-*.png').should == [20, 30]
image_md5('squares-*.png').should == '0187306f3858136feee87d3017e7f307'
end
it "should allow the position of a sprite to be specified in absolute pixels" do
css = render <<-SCSS
$squares-ten-by-ten-position: 10px;
$squares-twenty-by-twenty-position: 10px;
@import "squares/*.png";
@include all-squares-sprites;
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-89a274044e.png') no-repeat;
}
.squares-ten-by-ten {
background-position: 10px 0;
}
.squares-twenty-by-twenty {
background-position: 10px -10px;
}
CSS
image_size('squares-*.png').should == [30, 30]
image_md5('squares-*.png').should == '262766d3e342f72b052f5708da6a1bf3'
end
it "should provide a nice errors for lemonade's old users" do
proc do