fix a bug in sprites when the offset position is absolute.
This commit is contained in:
parent
50963d7dd2
commit
638fd8f543
@ -60,7 +60,8 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
file = File.join(Compass.configuration.images_path, relative_file)
|
file = File.join(Compass.configuration.images_path, relative_file)
|
||||||
width, height = Compass::SassExtensions::Functions::ImageSize::ImageProperties.new(file).size
|
width, height = Compass::SassExtensions::Functions::ImageSize::ImageProperties.new(file).size
|
||||||
sprite_name = Compass::Sprites.sprite_name(relative_file)
|
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 << {
|
@images << {
|
||||||
:name => sprite_name,
|
:name => sprite_name,
|
||||||
:file => file,
|
:file => file,
|
||||||
@ -69,9 +70,10 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
:width => width,
|
:width => width,
|
||||||
:repeat => repeat_for(sprite_name),
|
:repeat => repeat_for(sprite_name),
|
||||||
:spacing => spacing_for(sprite_name),
|
:spacing => spacing_for(sprite_name),
|
||||||
:position => position_for(sprite_name),
|
:position => position,
|
||||||
:digest => Digest::MD5.file(file).hexdigest
|
:digest => Digest::MD5.file(file).hexdigest
|
||||||
}
|
}
|
||||||
|
@width = [@width, width + offset].max
|
||||||
end
|
end
|
||||||
@images.each_with_index do |image, index|
|
@images.each_with_index do |image, index|
|
||||||
if index == 0
|
if index == 0
|
||||||
@ -329,7 +331,7 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
if offset_x.unit_str == "%"
|
if offset_x.unit_str == "%"
|
||||||
x = offset_x # CE: Shouldn't this be a percentage of the total width?
|
x = offset_x # CE: Shouldn't this be a percentage of the total width?
|
||||||
else
|
else
|
||||||
x = offset_x.value - image[:left]
|
x = offset_x.value + image[:left]
|
||||||
x = Sass::Script::Number.new(x, x == 0 ? [] : ["px"])
|
x = Sass::Script::Number.new(x, x == 0 ? [] : ["px"])
|
||||||
end
|
end
|
||||||
y = offset_y.value - image[:top]
|
y = offset_y.value - image[:top]
|
||||||
|
@ -277,7 +277,7 @@ describe Compass::Sprites do
|
|||||||
}
|
}
|
||||||
|
|
||||||
.adjusted-px-1 {
|
.adjusted-px-1 {
|
||||||
background-position: -6px 0;
|
background-position: 14px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.adjusted-px-2 {
|
.adjusted-px-2 {
|
||||||
@ -315,7 +315,7 @@ describe Compass::Sprites do
|
|||||||
}
|
}
|
||||||
|
|
||||||
.adjusted-px-1 {
|
.adjusted-px-1 {
|
||||||
background-position: -6px 0;
|
background-position: 14px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.adjusted-px-2 {
|
.adjusted-px-2 {
|
||||||
@ -349,6 +349,30 @@ describe Compass::Sprites do
|
|||||||
image_md5('squares-*.png').should == '0187306f3858136feee87d3017e7f307'
|
image_md5('squares-*.png').should == '0187306f3858136feee87d3017e7f307'
|
||||||
end
|
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
|
it "should provide a nice errors for lemonade's old users" do
|
||||||
proc do
|
proc do
|
||||||
render <<-SCSS
|
render <<-SCSS
|
||||||
|
Loading…
Reference in New Issue
Block a user