even more cleanup
This commit is contained in:
parent
9eeff5a9fe
commit
aa4999370f
@ -70,9 +70,7 @@ module Compass
|
|||||||
# Calculates the overal image dimensions
|
# Calculates the overal image dimensions
|
||||||
# collects image sizes and input parameters for each sprite
|
# collects image sizes and input parameters for each sprite
|
||||||
def compute_image_positions!
|
def compute_image_positions!
|
||||||
imgs = @images.sort { |a,b| a.width <=> b.width }
|
fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images)
|
||||||
|
|
||||||
fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(imgs)
|
|
||||||
|
|
||||||
current_y = 0
|
current_y = 0
|
||||||
fitter.fit!.each do |row|
|
fitter.fit!.each do |row|
|
||||||
|
@ -107,7 +107,10 @@ module Compass
|
|||||||
base.image_for($1)
|
base.image_for($1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def <=>(other)
|
||||||
|
other.width <=> self.width
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def dimensions
|
def dimensions
|
||||||
|
@ -10,7 +10,7 @@ module Compass
|
|||||||
def_delegators :rows, :[]
|
def_delegators :rows, :[]
|
||||||
|
|
||||||
def initialize(images)
|
def initialize(images)
|
||||||
@images = images
|
@images = images.sort
|
||||||
@rows = []
|
@rows = []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -14,7 +14,11 @@ class RowFitterTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_images(dims)
|
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
|
end
|
||||||
|
|
||||||
def basic_dims
|
def basic_dims
|
||||||
@ -22,8 +26,8 @@ class RowFitterTest < Test::Unit::TestCase
|
|||||||
[ 100, 10 ],
|
[ 100, 10 ],
|
||||||
[ 80, 10 ],
|
[ 80, 10 ],
|
||||||
[ 50, 10 ],
|
[ 50, 10 ],
|
||||||
[ 20, 10 ],
|
[ 35, 10 ],
|
||||||
[ 35, 10 ]
|
[ 20, 10 ]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -53,30 +57,8 @@ class RowFitterTest < Test::Unit::TestCase
|
|||||||
assert_equal 3, row_fitter.rows.length
|
assert_equal 3, row_fitter.rows.length
|
||||||
|
|
||||||
assert_equal [ images[0] ], row_fitter[0].images
|
assert_equal [ images[0] ], row_fitter[0].images
|
||||||
assert_equal [ images[1], images[3] ], row_fitter[1].images
|
assert_equal [ images[1], images[4] ], row_fitter[1].images
|
||||||
assert_equal [ images[2], images[4] ], row_fitter[2].images
|
assert_equal [ images[2], images[3] ], 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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user