tests and fitter cleanup

This commit is contained in:
Scott Davis 2011-05-17 15:46:45 -04:00
parent fc034092aa
commit 7794b7202f
3 changed files with 36 additions and 4 deletions

View File

@ -6,6 +6,7 @@ require 'compass/sass_extensions/sprites/image_helper'
#classes #classes
require 'compass/sass_extensions/sprites/sprite_map' require 'compass/sass_extensions/sprites/sprite_map'
require 'compass/sass_extensions/sprites/image' 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/image_row'
require 'compass/sass_extensions/sprites/base' require 'compass/sass_extensions/sprites/base'
require 'compass/sass_extensions/sprites/engines' require 'compass/sass_extensions/sprites/engines'

View File

@ -4,7 +4,6 @@ module Compass
module Processing module Processing
def smart_packing def smart_packing
fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images) fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images)
current_y = 0 current_y = 0
fitter.fit!.each do |row| fitter.fit!.each do |row|
current_x = 0 current_x = 0
@ -12,7 +11,6 @@ module Compass
image.left = current_x image.left = current_x
image.top = current_y image.top = current_y
current_x += image.width current_x += image.width
image.left = image.position.unit_str == "%" ? (@width - image.width) * (image.position.value / 100) : image.position.value
end end
current_y += row.height current_y += row.height
end end

View File

@ -604,4 +604,37 @@ class SpritesTest < Test::Unit::TestCase
CSS CSS
end end
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 end