From c9593794bdfab5f7ce5edecd8d12f988c3741450 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 17 Sep 2011 12:02:51 -0400 Subject: [PATCH] better sorting of images coming into sprites, fixes one rbx error --- lib/compass/sass_extensions/sprites/row_fitter.rb | 8 +++++++- test/units/sprites/sprite_map_test.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/compass/sass_extensions/sprites/row_fitter.rb b/lib/compass/sass_extensions/sprites/row_fitter.rb index b5afff0f..834c57fa 100644 --- a/lib/compass/sass_extensions/sprites/row_fitter.rb +++ b/lib/compass/sass_extensions/sprites/row_fitter.rb @@ -10,7 +10,13 @@ module Compass def_delegators :rows, :[] def initialize(images) - @images = images.sort {|a,b| a.height <=> b.height } + @images = images.sort do |a,b| + if a.height == b.height + b.width <=> a.width + else + a.height <=> b.height + end + end @rows = [] end diff --git a/test/units/sprites/sprite_map_test.rb b/test/units/sprites/sprite_map_test.rb index ff72467b..9f869d4b 100644 --- a/test/units/sprites/sprite_map_test.rb +++ b/test/units/sprites/sprite_map_test.rb @@ -111,7 +111,7 @@ class SpriteMapTest < Test::Unit::TestCase base.generate assert_equal 400, base.width assert_equal 60, base.height - assert_equal [[0, 0], [20, 120], [20, 20], [20, 0], [20, 160]], base.images.map {|i| [i.top, i.left]} + assert_equal [[0, 0], [20, 120], [20, 0], [20, 100], [20, 160]], base.images.map {|i| [i.top, i.left]} assert File.exists?(base.filename) FileUtils.rm base.filename end