From 5e89865192b4550bbe29ceb2e2790ce09676d0b8 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 26 Jul 2011 17:43:08 -0400 Subject: [PATCH 01/23] fixed rails 3.0.x --- lib/compass/app_integration/rails/actionpack30/railtie.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/compass/app_integration/rails/actionpack30/railtie.rb b/lib/compass/app_integration/rails/actionpack30/railtie.rb index 2e52ae3b..a3fc5498 100644 --- a/lib/compass/app_integration/rails/actionpack30/railtie.rb +++ b/lib/compass/app_integration/rails/actionpack30/railtie.rb @@ -40,10 +40,7 @@ module Compass initializer "compass.initialize_rails" do |app| # Configure compass for use within rails, and provide the project configuration # that came via the rails boot process. - Compass::AppIntegration::Rails.check_for_double_boot! - Compass.discover_extensions! - Compass.configure_sass_plugin! - Compass.handle_configuration_change! + Compass::AppIntegration::Rails.initialize!(app.config.compass) end end end \ No newline at end of file From 71494cecfeecb47a57ddb8711306bcbe4bbc5bed Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 26 Jul 2011 17:53:56 -0400 Subject: [PATCH 02/23] rename sprite_search_path to sprite_load_path for consistancy --- Gemfile.lock | 2 +- lib/compass/configuration.rb | 2 +- lib/compass/configuration/defaults.rb | 2 +- lib/compass/sprite_importer.rb | 2 +- test/units/sprites/importer_test.rb | 6 +++--- test/units/sprites/sprite_map_test.rb | 1 - 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f5ce76db..6afb9c26 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - compass (0.12.0.alpha.0.3f72a54) + compass (0.12.0.alpha.0.5e89865) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/lib/compass/configuration.rb b/lib/compass/configuration.rb index 58ad570d..91793a5c 100644 --- a/lib/compass/configuration.rb +++ b/lib/compass/configuration.rb @@ -24,7 +24,7 @@ module Compass attributes_for_directory(:fonts), attributes_for_directory(:extensions, nil), # Compilation options - :sprite_search_path, + :sprite_load_path, :output_style, :environment, :relative_assets, diff --git a/lib/compass/configuration/defaults.rb b/lib/compass/configuration/defaults.rb index abdd3efd..99a68c61 100644 --- a/lib/compass/configuration/defaults.rb +++ b/lib/compass/configuration/defaults.rb @@ -89,7 +89,7 @@ module Compass top_level.images_dir end - def default_sprite_search_path + def default_sprite_load_path [top_level.images_path] end diff --git a/lib/compass/sprite_importer.rb b/lib/compass/sprite_importer.rb index 5307b2cd..6b8f2d94 100644 --- a/lib/compass/sprite_importer.rb +++ b/lib/compass/sprite_importer.rb @@ -66,7 +66,7 @@ module Compass # Returns the Glob of image files for the uri def self.files(uri) - Compass.configuration.sprite_search_path.each do |folder| + Compass.configuration.sprite_load_path.each do |folder| files = Dir[File.join(folder, uri)].sort next if files.empty? return files diff --git a/test/units/sprites/importer_test.rb b/test/units/sprites/importer_test.rb index 9d058704..a726a413 100644 --- a/test/units/sprites/importer_test.rb +++ b/test/units/sprites/importer_test.rb @@ -29,11 +29,11 @@ class ImporterTest < Test::Unit::TestCase end config = Compass::Configuration::Data.new('config') config.images_path = @images_tmp_path - config.sprite_search_path = [@images_tmp_path, other_folder] + config.sprite_load_path = [@images_tmp_path, other_folder] Compass.add_configuration(config, "sprite_config") importer = Compass::SpriteImporter.new - assert_equal 2, Compass.configuration.sprite_search_path.compact.size - assert Compass.configuration.sprite_search_path.include?(other_folder) + assert_equal 2, Compass.configuration.sprite_load_path.compact.size + assert Compass.configuration.sprite_load_path.include?(other_folder) assert_equal ["bar", "my"], Compass::SpriteImporter.sprite_names(uri) FileUtils.rm_rf other_folder diff --git a/test/units/sprites/sprite_map_test.rb b/test/units/sprites/sprite_map_test.rb index 25d5a98e..abb64542 100644 --- a/test/units/sprites/sprite_map_test.rb +++ b/test/units/sprites/sprite_map_test.rb @@ -10,7 +10,6 @@ class SpriteMapTest < Test::Unit::TestCase FileUtils.cp_r @images_src_path, @images_tmp_path config = Compass::Configuration::Data.new('config') config.images_path = @images_tmp_path - config.sprite_search_path = [@images_tmp_path] Compass.add_configuration(config) Compass.configure_sass_plugin! @options = {'cleanup' => Sass::Script::Bool.new(true), 'layout' => Sass::Script::String.new('vertical')} From 0984b48b24dffbde40ecbeda43e5fe835acfa471 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Wed, 27 Jul 2011 02:11:45 -0400 Subject: [PATCH 03/23] adjust spritmap class to usr load path to get relative sprite names --- Gemfile.lock | 2 +- lib/compass/sass_extensions/sprites/sprite_map.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6afb9c26..5df9882b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - compass (0.12.0.alpha.0.5e89865) + compass (0.12.0.alpha.0.71494ce) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/lib/compass/sass_extensions/sprites/sprite_map.rb b/lib/compass/sass_extensions/sprites/sprite_map.rb index aa9179a1..8c7f670f 100644 --- a/lib/compass/sass_extensions/sprites/sprite_map.rb +++ b/lib/compass/sass_extensions/sprites/sprite_map.rb @@ -17,10 +17,18 @@ module Compass name, path = Compass::SpriteImporter.path_and_name(uri) files = Compass::SpriteImporter.files(uri) sprites = files.map do |sprite| - sprite.gsub("#{Compass.configuration.images_path}/", "") + relative_name(sprite) end new(sprites, path, name, context, kwargs) end + + def self.relative_name(sprite) + Compass.configuration.sprite_load_path.each do |path| + if sprite.include?(path) + return sprite.gsub("#{path}/", "") + end + end + end def initialize(sprites, path, name, context, kwargs) @image_names = sprites From 8c48248a725e66508f0bfc1c0d82c1ee0e36247d Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Wed, 27 Jul 2011 02:39:24 -0400 Subject: [PATCH 04/23] more importer tests --- Gemfile.lock | 2 +- lib/compass/sass_extensions/sprites/image.rb | 15 ++++++++++++- .../sass_extensions/sprites/layout_methods.rb | 2 +- .../sass_extensions/sprites/sprite_map.rb | 2 ++ test/units/sprites/image_test.rb | 22 ++++++++++++++++++- test/units/sprites/sprite_map_test.rb | 17 ++++++++++++++ 6 files changed, 56 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5df9882b..7b6092b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - compass (0.12.0.alpha.0.71494ce) + compass (0.12.0.alpha.0.0984b48) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/lib/compass/sass_extensions/sprites/image.rb b/lib/compass/sass_extensions/sprites/image.rb index 3a3e57cf..fc842b3d 100644 --- a/lib/compass/sass_extensions/sprites/image.rb +++ b/lib/compass/sass_extensions/sprites/image.rb @@ -17,7 +17,16 @@ module Compass # The Full path to the image def file - File.join(Compass.configuration.images_path, relative_file) + @file ||= find_file + end + + def find_file + Compass.configuration.sprite_load_path.each do |path| + f = File.join(path, relative_file) + if File.exists?(f) + return f + end + end end # Width of the image @@ -25,6 +34,10 @@ module Compass dimensions.first end + def size + @size ||= File.size(file) + end + # Height of the image def height dimensions.last diff --git a/lib/compass/sass_extensions/sprites/layout_methods.rb b/lib/compass/sass_extensions/sprites/layout_methods.rb index 48235588..eddfd088 100644 --- a/lib/compass/sass_extensions/sprites/layout_methods.rb +++ b/lib/compass/sass_extensions/sprites/layout_methods.rb @@ -16,7 +16,7 @@ module Compass calculate_horizontal_positions calculate_width else - @images.sort! {|a,b| File.size(b.file) <=> File.size(a.file)} #put small images first + @images.sort! {|a,b| b.size <=> b.size} #put small images first calculate_width calulate_vertical_postions calculate_height diff --git a/lib/compass/sass_extensions/sprites/sprite_map.rb b/lib/compass/sass_extensions/sprites/sprite_map.rb index 8c7f670f..e8c2e2e8 100644 --- a/lib/compass/sass_extensions/sprites/sprite_map.rb +++ b/lib/compass/sass_extensions/sprites/sprite_map.rb @@ -23,7 +23,9 @@ module Compass end def self.relative_name(sprite) + sprite = File.expand_path(sprite) Compass.configuration.sprite_load_path.each do |path| + path = File.expand_path(path) if sprite.include?(path) return sprite.gsub("#{path}/", "") end diff --git a/test/units/sprites/image_test.rb b/test/units/sprites/image_test.rb index 24b635b1..a3342138 100644 --- a/test/units/sprites/image_test.rb +++ b/test/units/sprites/image_test.rb @@ -15,7 +15,7 @@ class SpritesImageTest < Test::Unit::TestCase end let(:sprite_filename) { 'squares/ten-by-ten.png' } - let(:sprite_path) { File.join(@images_src_path, sprite_filename) } + let(:sprite_path) { File.join(@images_tmp_path, sprite_filename) } let(:sprite_name) { File.basename(sprite_filename, '.png') } @@ -91,4 +91,24 @@ class SpritesImageTest < Test::Unit::TestCase assert_equal 0, img.offset end + + test 'gets name for sprite in search path' do + Compass.reset_configuration! + uri = 'foo/*.png' + other_folder = File.join(@images_tmp_path, '../other-temp') + FileUtils.mkdir_p other_folder + FileUtils.mkdir_p File.join(other_folder, 'foo') + %w(my bar).each do |file| + FileUtils.touch(File.join(other_folder, "foo/#{file}.png")) + end + config = Compass::Configuration::Data.new('config') + config.images_path = @images_tmp_path + config.sprite_load_path = [@images_tmp_path, other_folder] + Compass.add_configuration(config, "sprite_config") + image = Compass::SassExtensions::Sprites::Image.new(sprite_map_test(options), "foo/my.png", options) + assert_equal File.join(other_folder, 'foo/my.png'), image.file + assert_equal 0, image.size + FileUtils.rm_rf other_folder + end + end diff --git a/test/units/sprites/sprite_map_test.rb b/test/units/sprites/sprite_map_test.rb index abb64542..319cc32e 100644 --- a/test/units/sprites/sprite_map_test.rb +++ b/test/units/sprites/sprite_map_test.rb @@ -121,5 +121,22 @@ class SpriteMapTest < Test::Unit::TestCase assert_equal sizes.max, File.size(@base.images.last.file) end + test "should get correct relative_name" do + Compass.reset_configuration! + uri = 'foo/*.png' + other_folder = File.join(@images_tmp_path, '../other-temp') + FileUtils.mkdir_p other_folder + FileUtils.mkdir_p File.join(other_folder, 'foo') + %w(my bar).each do |file| + FileUtils.touch(File.join(other_folder, "foo/#{file}.png")) + end + config = Compass::Configuration::Data.new('config') + config.images_path = @images_tmp_path + config.sprite_load_path = [@images_tmp_path, other_folder] + Compass.add_configuration(config, "sprite_config") + assert_equal 'foo/my.png', Compass::SassExtensions::Sprites::SpriteMap.relative_name(File.join(other_folder, 'foo/my.png')) + FileUtils.rm_rf other_folder + end + end \ No newline at end of file From 3a4d1e07b77bfab1282570e193dbbe1eab9766da Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Wed, 27 Jul 2011 03:01:28 -0400 Subject: [PATCH 05/23] reverted sorting back to one liner --- Gemfile.lock | 2 +- lib/compass/sass_extensions/sprites/layout_methods.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7b6092b5..aaf6f1eb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - compass (0.12.0.alpha.0.0984b48) + compass (0.12.0.alpha.0.8c48248) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/lib/compass/sass_extensions/sprites/layout_methods.rb b/lib/compass/sass_extensions/sprites/layout_methods.rb index eddfd088..56a219f6 100644 --- a/lib/compass/sass_extensions/sprites/layout_methods.rb +++ b/lib/compass/sass_extensions/sprites/layout_methods.rb @@ -16,7 +16,7 @@ module Compass calculate_horizontal_positions calculate_width else - @images.sort! {|a,b| b.size <=> b.size} #put small images first + @images.sort! {|a,b| b.size <=> a.size} calculate_width calulate_vertical_postions calculate_height From b57822c1348b97ce77529473d49fe990085b298e Mon Sep 17 00:00:00 2001 From: Joeri Samson Date: Wed, 27 Jul 2011 17:31:10 +0200 Subject: [PATCH 06/23] Failing test for changing http_path with rails --- test/units/rails_configuration_test.rb | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/units/rails_configuration_test.rb diff --git a/test/units/rails_configuration_test.rb b/test/units/rails_configuration_test.rb new file mode 100644 index 00000000..da298538 --- /dev/null +++ b/test/units/rails_configuration_test.rb @@ -0,0 +1,50 @@ +require 'test_helper' +require 'compass' +require 'stringio' + +class ConfigurationTest < Test::Unit::TestCase + + setup do + Compass.reset_configuration! + end + + after do + Compass.reset_configuration! + end + + def test_defaults + contents = StringIO.new(<<-CONFIG) + project_type = :rails + CONFIG + config = Compass.configuration_for(contents, "config/compass.rb") + + Compass.add_project_configuration(config, :project_type => "rails") + + assert_equal 'public/images', Compass.configuration.images_dir + assert_equal 'public/stylesheets', Compass.configuration.css_dir + assert_equal 'public/fonts', Compass.configuration.fonts_dir + + assert_equal '/', Compass.configuration.http_path + assert_equal '/images', Compass.configuration.http_images_path + assert_equal '/stylesheets', Compass.configuration.http_stylesheets_path + assert_equal '/fonts', Compass.configuration.http_fonts_path + + # Other default values must wait until I have a better idea of how to mock Sass::Util.app_geq + end + + def test_http_path_change + contents = StringIO.new(<<-CONFIG) + project_type = :rails + + http_path = "/test/alternative_path" + CONFIG + config = Compass.configuration_for(contents, "config/compass.rb") + + Compass.add_project_configuration(config, :project_type => "rails") + + assert_equal '/test/alternative_path', Compass.configuration.http_path + assert_equal '/test/alternative_path/images', Compass.configuration.http_images_path + assert_equal '/test/alternative_path/stylesheets', Compass.configuration.http_stylesheets_path + assert_equal '/test/alternative_path/fonts', Compass.configuration.http_fonts_path + end +end From ec7c4b2e9caef7885a5850f199f8917a6c9cb1fd Mon Sep 17 00:00:00 2001 From: Joeri Samson Date: Wed, 27 Jul 2011 17:32:01 +0200 Subject: [PATCH 07/23] Fix failing test for change to http_path in rails --- .../app_integration/rails/configuration_defaults.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/compass/app_integration/rails/configuration_defaults.rb b/lib/compass/app_integration/rails/configuration_defaults.rb index 06aaf311..dffb7bc8 100644 --- a/lib/compass/app_integration/rails/configuration_defaults.rb +++ b/lib/compass/app_integration/rails/configuration_defaults.rb @@ -50,19 +50,21 @@ module Compass end def default_http_images_path - "#{top_level.http_path}images" + # Relies on the fact that this will be loaded after the "normal" + # defaults, so that method_missing finds http_root_relative + http_root_relative "images" end def default_http_javascripts_path - "#{top_level.http_path}javascripts" + http_root_relative "javascripts" end def default_http_fonts_path - "#{top_level.http_path}fonts" + http_root_relative "fonts" end def default_http_stylesheets_path - "#{top_level.http_path}stylesheets" + http_root_relative "stylesheets" end def default_extensions_dir From 289c452d648764284d39beaa8e75d58ea5e85f62 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Wed, 27 Jul 2011 21:31:56 -0400 Subject: [PATCH 08/23] patched image functions to accept a real path --- Gemfile.lock | 2 +- lib/compass/sass_extensions/functions/image_size.rb | 12 ++++++++++-- lib/compass/sass_extensions/functions/sprites.rb | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index aaf6f1eb..a3433dd2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - compass (0.12.0.alpha.0.8c48248) + compass (0.12.0.alpha.0.ec7c4b2) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/lib/compass/sass_extensions/functions/image_size.rb b/lib/compass/sass_extensions/functions/image_size.rb index 175d3dba..0490e703 100644 --- a/lib/compass/sass_extensions/functions/image_size.rb +++ b/lib/compass/sass_extensions/functions/image_size.rb @@ -1,14 +1,22 @@ module Compass::SassExtensions::Functions::ImageSize # Returns the width of the image relative to the images directory def image_width(image_file) - image_path = real_path(image_file) + image_path = if File.exists?(image_file.value) + image_file.value + else + real_path(image_file) + end width = ImageProperties.new(image_path).size.first Sass::Script::Number.new(width,["px"]) end # Returns the height of the image relative to the images directory def image_height(image_file) - image_path = real_path(image_file) + image_path = if File.exists?(image_file.value) + image_file.value + else + real_path(image_file) + end height = ImageProperties.new(image_path).size.last Sass::Script::Number.new(height, ["px"]) end diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index d006d3ee..d2f74b61 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -61,7 +61,7 @@ module Compass::SassExtensions::Functions::Sprites verify_map(map, "sprite") verify_sprite(sprite) if image = map.image_for(sprite.value) - Sass::Script::String.new(image.relative_file) + Sass::Script::String.new(image.file) else missing_image!(map, sprite) end From acfd1e43a2d7332fde7e960adb890ca86f573ed9 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 18:49:06 -0400 Subject: [PATCH 09/23] fixed trig functions closes #498 --- lib/compass/sass_extensions/functions/trig.rb | 3 ++- test/units/sass_extensions_test.rb | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/compass/sass_extensions/functions/trig.rb b/lib/compass/sass_extensions/functions/trig.rb index 95c38508..5ee9436d 100644 --- a/lib/compass/sass_extensions/functions/trig.rb +++ b/lib/compass/sass_extensions/functions/trig.rb @@ -19,9 +19,10 @@ module Compass::SassExtensions::Functions::Trig private def trig(operation, number) if number.numerator_units == ["deg"] && number.denominator_units == [] - Sass::Script::Number.new(Math.send(operation, Math::PI * number.value / 360)) + Sass::Script::Number.new(Math.send(operation, (number.value * Math::PI / 180))) else Sass::Script::Number.new(Math.send(operation, number.value), number.numerator_units, number.denominator_units) end end + end diff --git a/test/units/sass_extensions_test.rb b/test/units/sass_extensions_test.rb index 569d49f0..8b8aeabd 100644 --- a/test/units/sass_extensions_test.rb +++ b/test/units/sass_extensions_test.rb @@ -65,18 +65,21 @@ class SassExtensionsTest < Test::Unit::TestCase end def test_trig_functions + assert_equal "0.841", evaluate("sin(1)") assert_equal "0.841px", evaluate("sin(1px)") assert_equal "0.0", evaluate("sin(pi())") assert_equal "1", evaluate("sin(pi() / 2)") - assert_equal "1", evaluate("sin(180deg)") + assert_equal "0.0", evaluate("sin(180deg)") assert_equal "-1", evaluate("sin(3* pi() / 2)") assert_equal "-1", evaluate("cos(pi())") - assert_equal "-1", evaluate("cos(360deg)") + assert_equal "1", evaluate("cos(360deg)") + assert_equal "-0.176", evaluate("sin(270)") assert_equal "1", evaluate("cos(2*pi())") assert_equal "0.0", evaluate("cos(pi() / 2)") assert_equal "0.0", evaluate("cos(3* pi() / 2)") assert_equal "0.0", evaluate("tan(pi())") assert_equal "0.0", evaluate("tan(360deg)") + assert_equal "0.959", evaluate("sin(360)") assert evaluate("tan(pi()/2 - 0.0001)").to_f > 1000, evaluate("tan(pi()/2 - 0.0001)") assert evaluate("tan(pi()/2 + 0.0001)").to_f < -1000, evaluate("tan(pi()/2 - 0.0001)") end From 26b2d1fcba92b03646f0f7812e38c0314e14f080 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 22:08:05 -0400 Subject: [PATCH 10/23] added test for diagonal layout --- test/units/sprites/sprite_map_test.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/units/sprites/sprite_map_test.rb b/test/units/sprites/sprite_map_test.rb index 319cc32e..b922b1f0 100644 --- a/test/units/sprites/sprite_map_test.rb +++ b/test/units/sprites/sprite_map_test.rb @@ -88,7 +88,22 @@ class SpriteMapTest < Test::Unit::TestCase assert_equal [0, 10, 20, 30], @base.images.map(&:top) assert_equal [0, 0, 0, 0], @base.images.map(&:left) end + + def diagonal + opts = @options.merge("layout" => Sass::Script::String.new('diagonal')) + sprite_map_test(opts) + end + + it "should generate a diagonal sprite" do + base = diagonal + base.generate + assert_equal 40, base.width + assert_equal 40, base.height + assert_equal [[0,0], [10,10], [20,20], [30,30]], base.images.map {|i| [i.top, i.left]} + assert File.exists?(base.filename) + FileUtils.rm base.filename + end # Horizontal tests def horizontal @@ -114,7 +129,7 @@ class SpriteMapTest < Test::Unit::TestCase assert File.exists?(base.filename) FileUtils.rm base.filename end - + it "should generate vertical sprites in decending order" do sizes = @base.images.map{|image| File.size(image.file) } assert_equal sizes.min, File.size(@base.images.first.file) From 08e92fadb2c547d3498e9410ca2016fdd8c35e2d Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 22:08:27 -0400 Subject: [PATCH 11/23] layout for diagonal sprite --- .../sass_extensions/sprites/layout_methods.rb | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/lib/compass/sass_extensions/sprites/layout_methods.rb b/lib/compass/sass_extensions/sprites/layout_methods.rb index 56a219f6..f194e742 100644 --- a/lib/compass/sass_extensions/sprites/layout_methods.rb +++ b/lib/compass/sass_extensions/sprites/layout_methods.rb @@ -3,23 +3,52 @@ module Compass module Sprites module LayoutMethods HORIZONTAL = 'horizontal' + DIAGONAL = 'diagonal' def horizontal? @kwargs.get_var('layout').value == HORIZONTAL end + def diagonal? + @kwargs.get_var('layout').value == DIAGONAL + end + # Calculates the overal image dimensions # collects image sizes and input parameters for each sprite def compute_image_positions! - if horizontal? - calculate_height + case @kwargs.get_var('layout').value + when DIAGONAL + calculate_diagonal_dimensions + calculate_diagonal_positions + when HORIZONTAL + @height = height_for_horizontal_layout calculate_horizontal_positions - calculate_width + @width = width_for_horizontal_layout else @images.sort! {|a,b| b.size <=> a.size} - calculate_width + @width = width_for_vertical_layout calulate_vertical_postions - calculate_height + @height = height_for_vertical_layout + end + end + + def calculate_diagonal_dimensions + @width = @images.map {|image| image.width}.inject(0) {|width, sum| sum + width} + @height = @images.map {|image| image.height}.inject(0) {|height, sum| sum + height} + end + + def calculate_diagonal_positions + previous = nil + @images.each_with_index do |image, index| + if previous.nil? + previous = image + image.top = 0 + image.left = 0 + next + end + image.top = previous.top + previous.height + image.left = previous.left + previous.width + previous = image end end @@ -41,20 +70,6 @@ module Compass end end - - def calculate_dimensions! - calculate_width - calculate_height - end - - def calculate_height - @height = if horizontal? - height_for_horizontal_layout - else - height_for_vertical_layout - end - end - def height_for_vertical_layout last = @images.last last.top + last.height @@ -64,14 +79,6 @@ module Compass @height = @images.map {|image| image.height + image.spacing}.max end - def calculate_width - @width = if horizontal? - width_for_horizontal_layout - else - width_for_vertical_layout - end - end - def width_for_horizontal_layout @images.inject(0) { |sum, image| sum += (image.width + image.offset) } end From 5f2cf884b60ea510f49e65ad6f62c3fa7358b260 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 22:13:13 -0400 Subject: [PATCH 12/23] docs for diagonal layout --- doc-src/content/help/tutorials/spriting.markdown | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc-src/content/help/tutorials/spriting.markdown b/doc-src/content/help/tutorials/spriting.markdown index 6a5b9ad7..dfd4fd5c 100644 --- a/doc-src/content/help/tutorials/spriting.markdown +++ b/doc-src/content/help/tutorials/spriting.markdown @@ -55,11 +55,20 @@ is located within it. ## Layout Control -If you prefer horizontal sprites to the `vertical` default just set the magic variable `$-layout` variable. +Set the `$-layout` variable to the preferred layout method. + +* vertical - default +* horizontal - lays images out side by side +* diagonal - lays images out corner to corner none of the spacing of padding options are taken into account + +Example: $icon-layout:horizontal; @import "icon/*.png"; - + + $dropcap-layout:diagonal + @import "dropcap/*.png"; + ## Selector Control From d4227346af53bfe9c4175c98c0d1bfa1b1c2ec40 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 23:34:59 -0400 Subject: [PATCH 13/23] new tests --- .../sprites/public/images/image_row/large.png | Bin 0 -> 2857 bytes .../public/images/image_row/large_square.png | Bin 0 -> 2826 bytes .../public/images/image_row/medium.png | Bin 0 -> 2832 bytes .../sprites/public/images/image_row/small.png | Bin 0 -> 2809 bytes .../sprites/public/images/image_row/tall.png | Bin 0 -> 2817 bytes test/units/sprites/image_row_test.rb | 57 +++++++++++++++ test/units/sprites/row_fitter_test.rb | 66 ++++++++++++++++++ 7 files changed, 123 insertions(+) create mode 100644 test/fixtures/sprites/public/images/image_row/large.png create mode 100644 test/fixtures/sprites/public/images/image_row/large_square.png create mode 100644 test/fixtures/sprites/public/images/image_row/medium.png create mode 100644 test/fixtures/sprites/public/images/image_row/small.png create mode 100644 test/fixtures/sprites/public/images/image_row/tall.png create mode 100644 test/units/sprites/image_row_test.rb create mode 100644 test/units/sprites/row_fitter_test.rb diff --git a/test/fixtures/sprites/public/images/image_row/large.png b/test/fixtures/sprites/public/images/image_row/large.png new file mode 100644 index 0000000000000000000000000000000000000000..f86cca9bea7ec5e8cb180e38df18b69c98d9d204 GIT binary patch literal 2857 zcmV+^3)b|BP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^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dcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0000~NklEC9m-3=6=p z01OK-EC9m-Ff72Z01OMjumHmXFf0JW0t^e_-U0vs|NjF3AI<|M5fVTn00000NkvXX Hu0mjf#Wz73 literal 0 HcmV?d00001 diff --git a/test/fixtures/sprites/public/images/image_row/large_square.png b/test/fixtures/sprites/public/images/image_row/large_square.png new file mode 100644 index 0000000000000000000000000000000000000000..b99cf980d85d38e570ab4c2bb1b57651f5786a2c GIT binary patch literal 2826 zcmV+l3-$DgP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpw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z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0000rNklIsf9D&+%|QV=NnMyaA{L9qVzF2(7K_DVu~;nr7%u<- c0RR630E6oTP1$C`#Q*>R07*qoM6N<$g6g+9ssI20 literal 0 HcmV?d00001 diff --git a/test/fixtures/sprites/public/images/image_row/medium.png b/test/fixtures/sprites/public/images/image_row/medium.png new file mode 100644 index 0000000000000000000000000000000000000000..faf62a6dc47abbf1820ecbcc552ee518c74130da GIT binary patch literal 2832 zcmV+r3-9!aP)K00009a7bBm000XU z000XU0RWnu7ytkYPiaF#P*7-ZbZ>KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpm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0^KL7v#|NjF3{pkZu TFNEVs00000NkvXXu0mjf?7ull literal 0 HcmV?d00001 diff --git a/test/units/sprites/image_row_test.rb b/test/units/sprites/image_row_test.rb new file mode 100644 index 00000000..4c92b88a --- /dev/null +++ b/test/units/sprites/image_row_test.rb @@ -0,0 +1,57 @@ +require 'test_helper' + +class ImageRowTest < Test::Unit::TestCase + include SpriteHelper + def setup + create_sprite_temp + file = StringIO.new("images_path = #{@images_src_path.inspect}\n") + Compass.add_configuration(file, "sprite_config") + @filenames = %w(large.png large_square.png medium.png tall.png small.png) + @image_files = Dir["#{@images_src_path}/image_row/*.png"].sort + @images = @image_files.map do |img| + img.gsub!("#{@images_src_path}/", '') + Compass::SassExtensions::Sprites::Image.new(nil, img, {}) + end + image_row(1000) + end + + def teardown + clean_up_sprites + end + + def image_row(max) + @image_row = Compass::SassExtensions::Sprites::ImageRow.new(max) + end + + def populate_row + @images.each do |image| + assert @image_row.add(image) + end + end + + it "should return false if image will not fit in row" do + image_row(100) + img = Compass::SassExtensions::Sprites::Image.new(nil, File.join('image_row', 'large.png'), {}) + assert !@image_row.add(img) + end + + it "should have 5 images" do + populate_row + assert_equal 5, @image_row.images.size + end + + it "should return max image width" do + populate_row + assert_equal 400, @image_row.width + end + + it "should return max image height" do + populate_row + assert_equal 40, @image_row.height + end + + it "should have an efficiency rating" do + populate_row + assert_equal 1 - (580.0 / 1000.0), @image_row.efficiency + end +end \ No newline at end of file diff --git a/test/units/sprites/row_fitter_test.rb b/test/units/sprites/row_fitter_test.rb new file mode 100644 index 00000000..38096ef8 --- /dev/null +++ b/test/units/sprites/row_fitter_test.rb @@ -0,0 +1,66 @@ +require 'test_helper' +require 'compass/sass_extensions/sprites/row_fitter' + +class RowFitterTest < Test::Unit::TestCase + include SpriteHelper + def setup + file = StringIO.new("images_path = #{@images_src_path.inspect}\n") + Compass.add_configuration(file, "sprite_config") + end + + def row_fitter(images = nil) + @row_fitter ||= Compass::SassExtensions::Sprites::RowFitter.new(images) + end + + def teardown + @row_fitter = nil + end + + def create_images(dims) + dims.collect { |width, height| + image = Compass::SassExtensions::Sprites::Image.new('blah', 'blah', {}) + image.stubs(:width => width, :height => height) + image + } + end + + def basic_dims + [ + [ 100, 10 ], + [ 80, 10 ], + [ 50, 10 ], + [ 35, 10 ], + [ 20, 10 ] + ] + end + + it 'should use the fast placement algorithm' do + images = create_images(basic_dims) + + row_fitter(images) + assert_equal 100, row_fitter.width + + row_fitter.fit!(:fast) + + assert_equal 4, row_fitter.rows.length + + assert_equal [ images[0] ], row_fitter[0].images + assert_equal [ images[1] ], row_fitter[1].images + assert_equal [ images[2], images[3] ], row_fitter[2].images + assert_equal [ images[4] ], row_fitter[3].images + end + + it 'should use the scan placement algorithm' do + images = create_images(basic_dims) + + 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[4] ], row_fitter[1].images + assert_equal [ images[2], images[3] ], row_fitter[2].images + end +end \ No newline at end of file From 87240723e7970dc48e2f29c6872e99ff72b4ec94 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 23:35:27 -0400 Subject: [PATCH 14/23] smart packing helper classes --- .../sass_extensions/sprites/image_row.rb | 47 ++++++++++ .../sass_extensions/sprites/row_fitter.rb | 86 +++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 lib/compass/sass_extensions/sprites/image_row.rb create mode 100644 lib/compass/sass_extensions/sprites/row_fitter.rb diff --git a/lib/compass/sass_extensions/sprites/image_row.rb b/lib/compass/sass_extensions/sprites/image_row.rb new file mode 100644 index 00000000..51ae0d73 --- /dev/null +++ b/lib/compass/sass_extensions/sprites/image_row.rb @@ -0,0 +1,47 @@ +require 'forwardable' + +module Compass + module SassExtensions + module Sprites + class ImageRow + extend Forwardable + + attr_reader :images, :max_width + def_delegators :@images, :last, :delete, :empty?, :length + + def initialize(max_width) + @images = [] + @max_width = max_width + end + + def add(image) + return false if !will_fit?(image) + @images << image + true + end + + alias :<< :add + + def height + images.map(&:height).max + end + + def width + images.map(&:width).max + end + + def total_width + images.inject(0) {|sum, img| sum + img.width } + end + + def efficiency + 1 - (total_width.to_f / max_width.to_f) + end + + def will_fit?(image) + (total_width + image.width) <= max_width + end + end + end + end +end \ No newline at end of file diff --git a/lib/compass/sass_extensions/sprites/row_fitter.rb b/lib/compass/sass_extensions/sprites/row_fitter.rb new file mode 100644 index 00000000..b5afff0f --- /dev/null +++ b/lib/compass/sass_extensions/sprites/row_fitter.rb @@ -0,0 +1,86 @@ +require 'forwardable' + +module Compass + module SassExtensions + module Sprites + class RowFitter + extend Forwardable + + attr_reader :images, :rows + def_delegators :rows, :[] + + def initialize(images) + @images = images.sort {|a,b| a.height <=> b.height } + @rows = [] + end + + def fit!(style = :scan) + send("#{style}_fit") + @rows + end + + def width + @width ||= @images.collect(&:width).max + end + + def height + @height ||= @rows.inject(0) {|sum, row| sum += row.height} + end + + def efficiency + @rows.inject(0) { |sum, row| sum += row.efficiency } ** @rows.length + end + + private + def new_row(image = nil) + row = Compass::SassExtensions::Sprites::ImageRow.new(width) + row.add(image) if image + row + end + + def fast_fit + row = new_row + @images.each do |image| + if !row.add(image) + @rows << row + row = new_row(image) + end + end + + @rows << row + end + + def scan_fit + fast_fit + + moved_images = [] + + begin + removed = false + + catch :done do + @rows.each do |row| + (@rows - [ row ]).each do |other_row| + other_row.images.each do |image| + if !moved_images.include?(image) + if row.will_fit?(image) + other_row.delete(image) + row << image + + @rows.delete(other_row) if other_row.empty? + removed = true + + moved_images << image + throw :done + end + end + end + end + end + end + end while removed + end + end + end + end +end \ No newline at end of file From ef4c897de59a6ba18cbb41ab6c174074c815b996 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 23:35:53 -0400 Subject: [PATCH 15/23] tests for smart packing --- test/units/sprites/sprite_map_test.rb | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/test/units/sprites/sprite_map_test.rb b/test/units/sprites/sprite_map_test.rb index b922b1f0..30b601b9 100644 --- a/test/units/sprites/sprite_map_test.rb +++ b/test/units/sprites/sprite_map_test.rb @@ -5,19 +5,16 @@ class SpriteMapTest < Test::Unit::TestCase def setup Hash.send(:include, Compass::SassExtensions::Functions::Sprites::VariableReader) - @images_src_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images') - @images_tmp_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images-tmp') - FileUtils.cp_r @images_src_path, @images_tmp_path - config = Compass::Configuration::Data.new('config') - config.images_path = @images_tmp_path - Compass.add_configuration(config) + create_sprite_temp + file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n") + Compass.add_configuration(file, "sprite_config") Compass.configure_sass_plugin! @options = {'cleanup' => Sass::Script::Bool.new(true), 'layout' => Sass::Script::String.new('vertical')} @base = sprite_map_test(@options) end def teardown - FileUtils.rm_r @images_tmp_path + clean_up_sprites @base = nil end @@ -89,6 +86,25 @@ class SpriteMapTest < Test::Unit::TestCase assert_equal [0, 0, 0, 0], @base.images.map(&:left) end + def smart + options = @options.merge("layout" => Sass::Script::String.new('smart')) + importer = Compass::SpriteImporter.new + uri = "image_row/*.png" + path, name = Compass::SpriteImporter.path_and_name(uri) + sprite_names = Compass::SpriteImporter.sprite_names(uri) + sass_engine = Compass::SpriteImporter.sass_engine(uri, name, importer, options) + Compass::SassExtensions::Sprites::SpriteMap.new(sprite_names.map {|n| "image_row/#{n}.png"}, path, name, sass_engine, options) + end + + it "should have a smart layout" do + base = smart + 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 File.exists?(base.filename) + FileUtils.rm base.filename + end def diagonal opts = @options.merge("layout" => Sass::Script::String.new('diagonal')) From 59722ef4ad48a1a52f73ac3828d0ded1d3fb0002 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 23:36:20 -0400 Subject: [PATCH 16/23] smart packing implimentation thanks @johnbintz --- lib/compass/sass_extensions/sprites.rb | 3 ++- .../sass_extensions/sprites/layout_methods.rb | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/compass/sass_extensions/sprites.rb b/lib/compass/sass_extensions/sprites.rb index 246836a7..b5f08a94 100644 --- a/lib/compass/sass_extensions/sprites.rb +++ b/lib/compass/sass_extensions/sprites.rb @@ -7,7 +7,8 @@ module Compass end end end - +require 'compass/sass_extensions/sprites/image_row' +require 'compass/sass_extensions/sprites/row_fitter' require 'compass/sass_extensions/sprites/image' require 'compass/sass_extensions/sprites/layout_methods' require 'compass/sass_extensions/sprites/sprite_methods' diff --git a/lib/compass/sass_extensions/sprites/layout_methods.rb b/lib/compass/sass_extensions/sprites/layout_methods.rb index f194e742..5a030231 100644 --- a/lib/compass/sass_extensions/sprites/layout_methods.rb +++ b/lib/compass/sass_extensions/sprites/layout_methods.rb @@ -4,6 +4,11 @@ module Compass module LayoutMethods HORIZONTAL = 'horizontal' DIAGONAL = 'diagonal' + SMART = 'smart' + + def smart? + @kwargs.get_var('layout').value == SMART + end def horizontal? @kwargs.get_var('layout').value == HORIZONTAL @@ -17,6 +22,10 @@ module Compass # collects image sizes and input parameters for each sprite def compute_image_positions! case @kwargs.get_var('layout').value + when SMART + require 'compass/sass_extensions/sprites/image_row' + require 'compass/sass_extensions/sprites/row_fitter' + calculate_smart_positions when DIAGONAL calculate_diagonal_dimensions calculate_diagonal_positions @@ -32,6 +41,23 @@ module Compass end end + def calculate_smart_positions + fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images) + current_y = 0 + fitter.fit!.each do |row| + current_x = 0 + row.images.each_with_index do |image, index| + image.left = current_x + image.top = current_y + current_x += image.width + end + current_y += row.height + end + @width = fitter.width + @height = fitter.height + end + + def calculate_diagonal_dimensions @width = @images.map {|image| image.width}.inject(0) {|width, sum| sum + width} @height = @images.map {|image| image.height}.inject(0) {|height, sum| sum + height} From 590123aeba5f03475fc37b2d3c327d0839d4508f Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 23:37:31 -0400 Subject: [PATCH 17/23] smart pack docs --- doc-src/content/help/tutorials/spriting.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/doc-src/content/help/tutorials/spriting.markdown b/doc-src/content/help/tutorials/spriting.markdown index dfd4fd5c..d6f8587b 100644 --- a/doc-src/content/help/tutorials/spriting.markdown +++ b/doc-src/content/help/tutorials/spriting.markdown @@ -60,6 +60,7 @@ Set the `$-layout` variable to the preferred layout method. * vertical - default * horizontal - lays images out side by side * diagonal - lays images out corner to corner none of the spacing of padding options are taken into account +* smart - lays the images out using a bin packing algorithm which allows for much smaller surface areas in your sprite files Example: From e49581c18f1fa19c55954000377b497e47dcb9d3 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 23:37:59 -0400 Subject: [PATCH 18/23] smart pack docs - forgot something --- Gemfile.lock | 2 +- doc-src/content/help/tutorials/spriting.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a3433dd2..24843a91 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - compass (0.12.0.alpha.0.ec7c4b2) + compass (0.12.0.alpha.0.5f2cf88) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/doc-src/content/help/tutorials/spriting.markdown b/doc-src/content/help/tutorials/spriting.markdown index d6f8587b..b5c3d6ba 100644 --- a/doc-src/content/help/tutorials/spriting.markdown +++ b/doc-src/content/help/tutorials/spriting.markdown @@ -60,7 +60,7 @@ Set the `$-layout` variable to the preferred layout method. * vertical - default * horizontal - lays images out side by side * diagonal - lays images out corner to corner none of the spacing of padding options are taken into account -* smart - lays the images out using a bin packing algorithm which allows for much smaller surface areas in your sprite files +* smart - lays the images out using a bin packing algorithm which allows for much smaller surface areas in your sprite files - does not support spacing or padding Example: From 6a166d0145472d8f9b00d514b77723a1fba07542 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 2 Aug 2011 23:46:03 -0400 Subject: [PATCH 19/23] derp double require --- Gemfile.lock | 2 +- lib/compass/sass_extensions/sprites/layout_methods.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 24843a91..d9559e14 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - compass (0.12.0.alpha.0.5f2cf88) + compass (0.12.0.alpha.0.e49581c) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/lib/compass/sass_extensions/sprites/layout_methods.rb b/lib/compass/sass_extensions/sprites/layout_methods.rb index 5a030231..2b6a6142 100644 --- a/lib/compass/sass_extensions/sprites/layout_methods.rb +++ b/lib/compass/sass_extensions/sprites/layout_methods.rb @@ -23,8 +23,6 @@ module Compass def compute_image_positions! case @kwargs.get_var('layout').value when SMART - require 'compass/sass_extensions/sprites/image_row' - require 'compass/sass_extensions/sprites/row_fitter' calculate_smart_positions when DIAGONAL calculate_diagonal_dimensions From d8e43bfdd7f43796d52f82cacbe92dc379beb44a Mon Sep 17 00:00:00 2001 From: Tyrinslys Valinlore Date: Wed, 3 Aug 2011 11:13:12 -0400 Subject: [PATCH 20/23] Changed the descriptions of the sin, cos, and tan to be more descriptive. --- .../content/reference/compass/helpers/trig.haml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc-src/content/reference/compass/helpers/trig.haml b/doc-src/content/reference/compass/helpers/trig.haml index 2147d2b2..2e574ccc 100644 --- a/doc-src/content/reference/compass/helpers/trig.haml +++ b/doc-src/content/reference/compass/helpers/trig.haml @@ -35,8 +35,9 @@ documented_functions: sin($number) .details %p - Takes the sine of a number. If the number is unitless or has a unit of deg - then it will return a unitless result. Degrees will first be converted to radians. + Returns the sine of a number. If the number is unitless or has a unit of deg + then it will return a unitless result. Unless the number has a unit of deg it + will be evaluated as radians. Degrees will first be converted to radians. If the number is any other unit, the units will be passed thru to the result, and the number will be treated as radians. @@ -46,8 +47,9 @@ documented_functions: cos($number) .details %p - Takes the cosine of a number. If the number is unitless or has a unit of deg - then it will return a unitless result. Degrees will first be converted to radians. + Returns the cosine of a number. If the number is unitless or has a unit of deg + then it will return a unitless result. Unless the number has a unit of deg it + will be evaluated as radians. Degrees will first be converted to radians. If the number is any other unit, the units will be passed thru to the result, and the number will be treated as radians. #tan.helper @@ -56,7 +58,8 @@ documented_functions: tan($number) .details %p - Takes the tangent of a number. If the number is unitless or has a unit of deg - then it will return a unitless result. Degrees will first be converted to radians. + Returns the tangent of a number. If the number is unitless or has a unit of deg + then it will return a unitless result. Unless the number has a unit of deg it + will be evaluated as radians. Degrees will first be converted to radians. If the number is any other unit, the units will be passed thru to the result, and the number will be treated as radians. From 4aa052d9e43c1fac142b0c8ce4be1ae388274ca3 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Fri, 12 Aug 2011 15:12:31 -0400 Subject: [PATCH 21/23] horizontal layout now respects positions and spacing correctly --- Gemfile.lock | 2 +- lib/compass/sass_extensions/sprites/image.rb | 23 +++--- .../sass_extensions/sprites/layout_methods.rb | 2 +- test/units/sprites/image_test.rb | 75 ++++++++----------- test/units/sprites/sprite_map_test.rb | 24 +++++- 5 files changed, 69 insertions(+), 57 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d9559e14..a4e40f94 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - compass (0.12.0.alpha.0.e49581c) + compass (0.12.0.alpha.0.d8e43bf) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) diff --git a/lib/compass/sass_extensions/sprites/image.rb b/lib/compass/sass_extensions/sprites/image.rb index fc842b3d..1b41b18f 100644 --- a/lib/compass/sass_extensions/sprites/image.rb +++ b/lib/compass/sass_extensions/sprites/image.rb @@ -48,29 +48,28 @@ module Compass File.basename(relative_file, '.png') end - # Value of $#{name}-repeat or $repeat - def repeat - [ "#{name}-repeat", "repeat" ].each { |which| - if var = options.get_var(which) - return var.value - end - } - "no-repeat" + def get_var_file(var) + options.get_var "#{name}_#{var}" end - # Value of $#{name}-position or $position defaults o 0px + # Value of $#{name}-repeat or $repeat + def repeat + (get_var_file("repeat") || options.get_var("repeat") || Sass::Script::String.new("no-repeat")).value + end + + # Value of $#{name}-position or $position defaults to 0px def position - options.get_var("#{name}-position") || options.get_var("position") || Sass::Script::Number.new(0, ["px"]) + get_var_file("position") || options.get_var("position") || Sass::Script::Number.new(0, ["px"]) end # Offset within the sprite def offset (position.unitless? || position.unit_str == "px") ? position.value : 0 end - + # Spacing between this image and the next def spacing - (options.get_var("#{name}-spacing") || options.get_var("spacing") || Sass::Script::Number.new(0)).value + (get_var_file("spacing") || options.get_var("spacing") || Sass::Script::Number.new(0, ['px'])).value end # MD5 hash of this file diff --git a/lib/compass/sass_extensions/sprites/layout_methods.rb b/lib/compass/sass_extensions/sprites/layout_methods.rb index 2b6a6142..60da675c 100644 --- a/lib/compass/sass_extensions/sprites/layout_methods.rb +++ b/lib/compass/sass_extensions/sprites/layout_methods.rb @@ -81,7 +81,7 @@ module Compass image.top = image.position.unit_str == '%' ? (@height - image.height) * (image.position.value / 100.0) : image.position.value next if index == 0 last_image = @images[index-1] - image.left = last_image.left + last_image.width + [image.offset, last_image.offset].max + image.left = last_image.left + last_image.width + [image.spacing, last_image.spacing].max end end diff --git a/test/units/sprites/image_test.rb b/test/units/sprites/image_test.rb index a3342138..ffac255d 100644 --- a/test/units/sprites/image_test.rb +++ b/test/units/sprites/image_test.rb @@ -6,41 +6,36 @@ class SpritesImageTest < Test::Unit::TestCase include SpriteHelper def setup create_sprite_temp - file = StringIO.new("images_path = #{@images_src_path.inspect}\n") - Compass.add_configuration(file, "sprite_config") - @repeat = 'no-repeat' - @spacing = 0 - @position = 100 - @offset = 100 end - let(:sprite_filename) { 'squares/ten-by-ten.png' } - let(:sprite_path) { File.join(@images_tmp_path, sprite_filename) } - let(:sprite_name) { File.basename(sprite_filename, '.png') } + SPRITE_FILENAME = 'selectors/ten-by-ten.png' - - def options - options = {:offset => @offset} - options.stubs(:get_var).with(anything).returns(nil) - ::OpenStruct.any_instance.stubs(:unitless?).returns(true) - options.stubs(:get_var).with("#{sprite_name}-repeat").returns(::OpenStruct.new(:value => @repeat)) - options.stubs(:get_var).with("#{sprite_name}-spacing").returns(::OpenStruct.new(:value => @spacing)) - options.stubs(:get_var).with("#{sprite_name}-position").returns(::OpenStruct.new(:value => @position)) - options.stubs(:get_var).with("layout").returns(::OpenStruct.new(:value => 'vertical')) - options + def sprite_path + File.join(@images_tmp_path, SPRITE_FILENAME) end - + def sprite_name + File.basename(SPRITE_FILENAME, '.png') + end - let(:digest) { Digest::MD5.file(sprite_path).hexdigest } - - - let(:image) { Compass::SassExtensions::Sprites::Image.new(sprite_map_test(options), File.join(sprite_filename), options)} + def digest + Digest::MD5.file(sprite_path).hexdigest + end + + def test_map(options ={}) + options = {'cleanup' => Sass::Script::Bool.new(true), 'layout' => Sass::Script::String.new('vertical')}.merge(options) + map = sprite_map_test(options) + end + + def test_image(options ={}) + test_map(options).images.first + end test 'initialize' do + image = test_image assert_equal sprite_name, image.name assert_equal sprite_path, image.file - assert_equal sprite_filename, image.relative_file + assert_equal SPRITE_FILENAME, image.relative_file assert_equal 10, image.width assert_equal 10, image.height assert_equal digest, image.digest @@ -49,44 +44,40 @@ class SpritesImageTest < Test::Unit::TestCase end test 'hover' do - assert_equal 'ten-by-ten_hover', image.hover.name + assert_equal 'ten-by-ten_hover', test_image.hover.name end test 'no parent' do - assert_nil image.parent + assert_nil test_image.parent end - - test 'image type is nil' do - @repeat = nil - assert_nil image.repeat - end - test 'image type is "global"' do - @repeat = 'global' - assert_equal @repeat, image.repeat + image = test_image "ten_by_ten_repeat" => Sass::Script::String.new('global') + assert_equal 'global', image.repeat end test 'image type is "no-repeat"' do - assert_equal 'no-repeat', image.repeat + assert_equal 'no-repeat', test_image.repeat end test 'image position' do - assert_equal Sass::Script::Number.new(100, ["px"]).value, image.position.value + image = test_image "ten_by_ten_position" => Sass::Script::Number.new(100, ["px"]) + assert_equal 100, image.position.value end test 'image spacing' do @spacing = 10 - assert_equal @spacing, image.spacing + image = test_image "spacing" => Sass::Script::Number.new(100, ["px"]) + assert_equal 100, image.spacing end test 'offset' do - assert_equal @offset, image.offset + image = test_image "ten_by_ten_position" => Sass::Script::Number.new(100, ["px"]) + assert_equal 100, image.offset end test 'neither, uses 0' do - @offset = 0 - img = image + img = test_image img.position.stubs(:unitless?).returns(false) assert_equal 0, img.offset end @@ -105,7 +96,7 @@ class SpritesImageTest < Test::Unit::TestCase config.images_path = @images_tmp_path config.sprite_load_path = [@images_tmp_path, other_folder] Compass.add_configuration(config, "sprite_config") - image = Compass::SassExtensions::Sprites::Image.new(sprite_map_test(options), "foo/my.png", options) + image = Compass::SassExtensions::Sprites::Image.new(test_map, "foo/my.png", {}) assert_equal File.join(other_folder, 'foo/my.png'), image.file assert_equal 0, image.size FileUtils.rm_rf other_folder diff --git a/test/units/sprites/sprite_map_test.rb b/test/units/sprites/sprite_map_test.rb index 30b601b9..b9f4a0ef 100644 --- a/test/units/sprites/sprite_map_test.rb +++ b/test/units/sprites/sprite_map_test.rb @@ -86,6 +86,16 @@ class SpriteMapTest < Test::Unit::TestCase assert_equal [0, 0, 0, 0], @base.images.map(&:left) end + it "should have a vertical layout with spacing" do + base = sprite_map_test(@options.merge({"spacing" => Sass::Script::Number.new(10, ['px'])})) + assert_equal [0, 20, 40, 60], base.images.map(&:top) + end + + it "should layout vertical with position" do + base = sprite_map_test("ten_by_ten_active_position" => Sass::Script::Number.new(10, ['px'])) + assert_equal [0, 10, 0, 0], base.images.map(&:left) + end + def smart options = @options.merge("layout" => Sass::Script::String.new('smart')) importer = Compass::SpriteImporter.new @@ -122,8 +132,9 @@ class SpriteMapTest < Test::Unit::TestCase end # Horizontal tests - def horizontal + def horizontal(options= {}) opts = @options.merge("layout" => Sass::Script::String.new('horizontal')) + opts.merge!(options) sprite_map_test(opts) end @@ -139,6 +150,17 @@ class SpriteMapTest < Test::Unit::TestCase assert_equal [0, 0, 0, 0], base.images.map(&:top) end + it "should layout horizontaly with spacing" do + base = horizontal("spacing" => Sass::Script::Number.new(10, ['px'])) + assert_equal [0, 20, 40, 60], base.images.map(&:left) + assert_equal [0, 0, 0, 0], base.images.map(&:top) + end + + it "should layout horizontaly with position" do + base = horizontal("ten_by_ten_active_position" => Sass::Script::Number.new(10, ['px'])) + assert_equal [0, 10, 0, 0], base.images.map(&:top) + end + it "should generate a horrizontal sprite" do base = horizontal base.generate From 1cdfab7c0308f83352163ef5891c03e3a6753eab Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Fri, 12 Aug 2011 15:34:04 -0400 Subject: [PATCH 22/23] fixed horizontal height and width calculation --- lib/compass/sass_extensions/sprites/layout_methods.rb | 4 ++-- test/units/sprites/sprite_map_test.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/compass/sass_extensions/sprites/layout_methods.rb b/lib/compass/sass_extensions/sprites/layout_methods.rb index 60da675c..258328ac 100644 --- a/lib/compass/sass_extensions/sprites/layout_methods.rb +++ b/lib/compass/sass_extensions/sprites/layout_methods.rb @@ -100,11 +100,11 @@ module Compass end def height_for_horizontal_layout - @height = @images.map {|image| image.height + image.spacing}.max + @height = @images.map {|image| image.height + image.offset}.max end def width_for_horizontal_layout - @images.inject(0) { |sum, image| sum += (image.width + image.offset) } + @images.inject(0) { |sum, image| sum += (image.width + image.spacing) } end def width_for_vertical_layout diff --git a/test/units/sprites/sprite_map_test.rb b/test/units/sprites/sprite_map_test.rb index b9f4a0ef..8360b086 100644 --- a/test/units/sprites/sprite_map_test.rb +++ b/test/units/sprites/sprite_map_test.rb @@ -154,6 +154,7 @@ class SpriteMapTest < Test::Unit::TestCase base = horizontal("spacing" => Sass::Script::Number.new(10, ['px'])) assert_equal [0, 20, 40, 60], base.images.map(&:left) assert_equal [0, 0, 0, 0], base.images.map(&:top) + assert_equal 80, base.width end it "should layout horizontaly with position" do From a82a3dd5d4a26d3716cedf7ead4690ae9ace4fef Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Fri, 19 Aug 2011 17:04:32 -0400 Subject: [PATCH 23/23] updated change log --- doc-src/content/CHANGELOG.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc-src/content/CHANGELOG.markdown b/doc-src/content/CHANGELOG.markdown index c6573794..038f5096 100644 --- a/doc-src/content/CHANGELOG.markdown +++ b/doc-src/content/CHANGELOG.markdown @@ -14,6 +14,14 @@ The Documentation for the [latest stable release](http://compass-style.org/docs/ The Documentation for the [latest preview release](http://beta.compass-style.org/) +0.12.0 pending +------------------- +* Added support for diagonal, horizontal, and smart sprite layout +* Fixed a bug with spacing in horizontal layout +* Changed the descriptions of the sin, cos, and tan to be more descriptive +* Fixed trig functions via issue #498 +* Fixed the default `http_path` in rails +* Sprites can now have a `sprite_seach_path` that is an array of directories that contain source images for sprites handy for using sprites in extensions of gems 0.11.5 (07/10/2011) -------------------