From 370044ba77e9d96774a3606885ceb02130aff648 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 16 May 2011 11:35:00 -0400 Subject: [PATCH] put in the row fitter --- Gemfile.lock | 2 +- lib/compass/sass_extensions/sprites/base.rb | 14 ++++---------- .../sass_extensions/sprites/image_group.rb | 18 ------------------ .../sass_extensions/sprites/row_fitter.rb | 2 ++ test/units/sprites/image_group_test.rb | 9 --------- 5 files changed, 7 insertions(+), 38 deletions(-) delete mode 100644 lib/compass/sass_extensions/sprites/image_group.rb delete mode 100644 test/units/sprites/image_group_test.rb diff --git a/Gemfile.lock b/Gemfile.lock index 152232a4..ee5d990d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT PATH remote: . specs: - compass (0.11.1.d9ca08f) + compass (0.11.1.cc26b98) chunky_png (~> 1.1) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/lib/compass/sass_extensions/sprites/base.rb b/lib/compass/sass_extensions/sprites/base.rb index f734118a..4710c615 100644 --- a/lib/compass/sass_extensions/sprites/base.rb +++ b/lib/compass/sass_extensions/sprites/base.rb @@ -71,16 +71,10 @@ module Compass # collects image sizes and input parameters for each sprite def compute_image_positions! imgs = @images.sort { |a,b| a.width <=> b.width } - rows = [::Compass::SassExtensions::Sprites::ImageRow.new(@width)] - imgs.each do |image| - next if rows.last.add(image) - - rows << ::Compass::SassExtensions::Sprites::ImageRow.new(@width) - unless rows.last.add(image) - raise "Image failed to be added" - end - - end + + fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(imgs) + rows = fitter.fit! + current_y = 0 rows.each do |row| current_x = 0 diff --git a/lib/compass/sass_extensions/sprites/image_group.rb b/lib/compass/sass_extensions/sprites/image_group.rb deleted file mode 100644 index 0b251805..00000000 --- a/lib/compass/sass_extensions/sprites/image_group.rb +++ /dev/null @@ -1,18 +0,0 @@ -module Compass - module SassExtensions - module Sprites - class ImageGroup - attr_reader :images - - def initialize(images = []) - @images = images - end - - def best_fitting_rows - - end - end - end - end -end - diff --git a/lib/compass/sass_extensions/sprites/row_fitter.rb b/lib/compass/sass_extensions/sprites/row_fitter.rb index eaa81bd8..b48f3c23 100644 --- a/lib/compass/sass_extensions/sprites/row_fitter.rb +++ b/lib/compass/sass_extensions/sprites/row_fitter.rb @@ -8,6 +8,7 @@ module Compass attr_reader :images, :rows def_delegators :rows, :[] + def initialize(images) @images = images @rows = [] @@ -15,6 +16,7 @@ module Compass def fit!(style = :scan) send("#{style}_fit") + @rows end def width diff --git a/test/units/sprites/image_group_test.rb b/test/units/sprites/image_group_test.rb deleted file mode 100644 index 842b11eb..00000000 --- a/test/units/sprites/image_group_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'test_helper' -require 'compass/sass_extensions/sprites/image_group' - -class ImageGroupTest < Test::Unit::TestCase - def setup - end - -end -