even more cleanup

This commit is contained in:
John Bintz 2011-05-16 11:50:01 -04:00
parent 9eeff5a9fe
commit aa4999370f
4 changed files with 15 additions and 32 deletions

View File

@ -70,9 +70,7 @@ module Compass
# Calculates the overal image dimensions
# collects image sizes and input parameters for each sprite
def compute_image_positions!
imgs = @images.sort { |a,b| a.width <=> b.width }
fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(imgs)
fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images)
current_y = 0
fitter.fit!.each do |row|

View File

@ -107,7 +107,10 @@ module Compass
base.image_for($1)
end
end
def <=>(other)
other.width <=> self.width
end
private
def dimensions

View File

@ -10,7 +10,7 @@ module Compass
def_delegators :rows, :[]
def initialize(images)
@images = images
@images = images.sort
@rows = []
end

View File

@ -14,7 +14,11 @@ class RowFitterTest < Test::Unit::TestCase
end
def create_images(dims)
dims.collect { |width, height| stub(:width => width, :height => height) }
dims.collect { |width, height|
image = Compass::SassExtensions::Sprites::Image.new('blah', 'blah', {})
image.stubs(:width => width, :height => height)
image
}
end
def basic_dims
@ -22,8 +26,8 @@ class RowFitterTest < Test::Unit::TestCase
[ 100, 10 ],
[ 80, 10 ],
[ 50, 10 ],
[ 20, 10 ],
[ 35, 10 ]
[ 35, 10 ],
[ 20, 10 ]
]
end
@ -53,30 +57,8 @@ class RowFitterTest < Test::Unit::TestCase
assert_equal 3, row_fitter.rows.length
assert_equal [ images[0] ], row_fitter[0].images
assert_equal [ images[1], images[3] ], row_fitter[1].images
assert_equal [ images[2], images[4] ], row_fitter[2].images
end
it 'should use the scan placement algorithm and get images from the front' do
images = create_images(
[
[ 100, 10 ],
[ 35, 10 ],
[ 80, 10 ],
[ 50, 10 ],
[ 20, 10 ],
]
)
row_fitter(images)
row_fitter.fit!(:scan)
assert_equal 3, row_fitter.rows.length
assert_equal [ images[0] ], row_fitter[0].images
assert_equal [ images[1], images[3] ], row_fitter[1].images
assert_equal [ images[2], images[4] ], row_fitter[2].images
assert_equal [ images[1], images[4] ], row_fitter[1].images
assert_equal [ images[2], images[3] ], row_fitter[2].images
end
end