diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index ff3d12df..b660514a 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -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] diff --git a/spec/sprites_spec.rb b/spec/sprites_spec.rb index b4f90337..331729d7 100644 --- a/spec/sprites_spec.rb +++ b/spec/sprites_spec.rb @@ -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