diff --git a/lib/compass/sass_extensions/sprites.rb b/lib/compass/sass_extensions/sprites.rb index 48e2d959..faf6afec 100644 --- a/lib/compass/sass_extensions/sprites.rb +++ b/lib/compass/sass_extensions/sprites.rb @@ -6,6 +6,7 @@ require 'compass/sass_extensions/sprites/image_helper' #classes require 'compass/sass_extensions/sprites/sprite_map' require 'compass/sass_extensions/sprites/image' +require 'compass/sass_extensions/sprites/row_fitter' require 'compass/sass_extensions/sprites/image_row' require 'compass/sass_extensions/sprites/base' require 'compass/sass_extensions/sprites/engines' diff --git a/lib/compass/sass_extensions/sprites/processing.rb b/lib/compass/sass_extensions/sprites/processing.rb index 68b64160..cd371ba7 100644 --- a/lib/compass/sass_extensions/sprites/processing.rb +++ b/lib/compass/sass_extensions/sprites/processing.rb @@ -4,7 +4,6 @@ module Compass module Processing def smart_packing fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images) - current_y = 0 fitter.fit!.each do |row| current_x = 0 @@ -12,10 +11,9 @@ module Compass image.left = current_x image.top = current_y current_x += image.width - image.left = image.position.unit_str == "%" ? (@width - image.width) * (image.position.value / 100) : image.position.value end current_y += row.height - end + end end diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index 23a45996..ccdf32cf 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -604,4 +604,37 @@ class SpritesTest < Test::Unit::TestCase CSS end -end \ No newline at end of file + it "should generate a sprite using smart packing" do + css = render <<-SCSS + $image_row-smart-pack: true; + @import "image_row/*.png"; + @include all-image_row-sprites; + SCSS + assert_correct css, <<-CSS + .image_row-sprite, .image_row-large, .image_row-large_square, .image_row-medium, .image_row-small, .image_row-tall { + background: url('/image_row-7738758b32.png') no-repeat; + } + + .image_row-large { + background-position: 0 0; + } + + .image_row-large_square { + background-position: -100px -20px; + } + + .image_row-medium { + background-position: 0 -20px; + } + + .image_row-small { + background-position: -140px -20px; + } + + .image_row-tall { + background-position: -160px -20px; + } + CSS + end + +end