From 8f675f936bf41aed7722e0a4b46ecafe0e8756e9 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 10 May 2011 18:01:12 -0400 Subject: [PATCH 01/12] moved test files to a more sain structure --- test/{ => integrations}/compass_test.rb | 0 .../rails_integration_test.rb | 0 test/{ => integrations}/sprites_test.rb | 0 test/{ => integrations}/test_rails_helper.rb | 0 test/{ => units}/command_line_test.rb | 0 test/{ => units}/compass_png_test.rb | 0 test/{ => units}/configuration_test.rb | 0 test/{ => units}/sass_extensions_test.rb | 0 test/{ => units}/sprites/base_test.rb | 21 +++++++++++++++++-- test/{ => units}/sprites/image_test.rb | 0 10 files changed, 19 insertions(+), 2 deletions(-) rename test/{ => integrations}/compass_test.rb (100%) rename test/{ => integrations}/rails_integration_test.rb (100%) rename test/{ => integrations}/sprites_test.rb (100%) rename test/{ => integrations}/test_rails_helper.rb (100%) rename test/{ => units}/command_line_test.rb (100%) rename test/{ => units}/compass_png_test.rb (100%) rename test/{ => units}/configuration_test.rb (100%) rename test/{ => units}/sass_extensions_test.rb (100%) rename test/{ => units}/sprites/base_test.rb (75%) rename test/{ => units}/sprites/image_test.rb (100%) diff --git a/test/compass_test.rb b/test/integrations/compass_test.rb similarity index 100% rename from test/compass_test.rb rename to test/integrations/compass_test.rb diff --git a/test/rails_integration_test.rb b/test/integrations/rails_integration_test.rb similarity index 100% rename from test/rails_integration_test.rb rename to test/integrations/rails_integration_test.rb diff --git a/test/sprites_test.rb b/test/integrations/sprites_test.rb similarity index 100% rename from test/sprites_test.rb rename to test/integrations/sprites_test.rb diff --git a/test/test_rails_helper.rb b/test/integrations/test_rails_helper.rb similarity index 100% rename from test/test_rails_helper.rb rename to test/integrations/test_rails_helper.rb diff --git a/test/command_line_test.rb b/test/units/command_line_test.rb similarity index 100% rename from test/command_line_test.rb rename to test/units/command_line_test.rb diff --git a/test/compass_png_test.rb b/test/units/compass_png_test.rb similarity index 100% rename from test/compass_png_test.rb rename to test/units/compass_png_test.rb diff --git a/test/configuration_test.rb b/test/units/configuration_test.rb similarity index 100% rename from test/configuration_test.rb rename to test/units/configuration_test.rb diff --git a/test/sass_extensions_test.rb b/test/units/sass_extensions_test.rb similarity index 100% rename from test/sass_extensions_test.rb rename to test/units/sass_extensions_test.rb diff --git a/test/sprites/base_test.rb b/test/units/sprites/base_test.rb similarity index 75% rename from test/sprites/base_test.rb rename to test/units/sprites/base_test.rb index a5c0adef..1798d56c 100644 --- a/test/sprites/base_test.rb +++ b/test/units/sprites/base_test.rb @@ -10,8 +10,12 @@ class SpritesBaseTest < Test::Unit::TestCase config.images_path = @images_tmp_path Compass.add_configuration(config) Compass.configure_sass_plugin! - options = Compass.sass_engine_options.extend Compass::SassExtensions::Functions::Sprites::VariableReader - @map = Compass::SpriteMap.new("selectors/*.png", options) + @options = Compass.sass_engine_options.extend Compass::SassExtensions::Functions::Sprites::VariableReader + setup_map + end + + def setup_map + @map = Compass::SpriteMap.new("selectors/*.png", @options) @base = Compass::SassExtensions::Sprites::Base.new(@map.sprite_names.map{|n| "selectors/#{n}.png"}, @map, @map.sass_engine, @map.options) end @@ -70,4 +74,17 @@ class SpritesBaseTest < Test::Unit::TestCase assert !@base.outdated? end + it "should remove old sprite when generating new" do + @base.generate + file = @base.filename + assert File.exists?(file), "Original file does not exist" + file_to_remove = File.join(@images_tmp_path, 'selectors', 'ten-by-ten.png') + FileUtils.rm file_to_remove + assert !File.exists?(file_to_remove), "Failed to remove sprite file" + @options["remove_old_sprites"] = true + setup_map + @base.generate + assert !File.exists?(file), "Sprite file did not get removed" + end + end \ No newline at end of file diff --git a/test/sprites/image_test.rb b/test/units/sprites/image_test.rb similarity index 100% rename from test/sprites/image_test.rb rename to test/units/sprites/image_test.rb From 6cb9bc266278c2859f571cb5ad016a60d4e8e02b Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 10 May 2011 18:02:32 -0400 Subject: [PATCH 02/12] old sprites will now be removed by default --- .../stylesheets/compass/utilities/sprites/_base.scss | 7 ++++--- lib/compass/sass_extensions/sprites/base.rb | 9 +++++++++ lib/compass/sass_extensions/sprites/sprite_map.rb | 1 + test/integrations/sprites_test.rb | 4 ++-- test/units/compass_png_test.rb | 2 +- test/units/sprites/base_test.rb | 6 +++--- test/units/sprites/image_test.rb | 2 +- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss b/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss index bc63081b..c346e181 100644 --- a/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss +++ b/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss @@ -15,14 +15,15 @@ $sprite-selectors: hover, target, active !default; background-position: sprite-position($map, $sprite, $offset-x, $offset-y); } + +// Determines if you want to include magic selectors in your sprites +$disable-magic-sprite-selectors:false !default; + // Include the position and (optionally) dimensions of this `$sprite` // in the given sprite `$map`. The sprite url should come from either a base // class or you can specify the `sprite-url` explicitly like this: // // background: $map no-repeat; - -$disable-magic-sprite-selectors:false !default; - @mixin sprite($map, $sprite, $dimensions: false, $offset-x: 0, $offset-y: 0) { @include sprite-background-position($map, $sprite, $offset-x, $offset-y); @if $dimensions { diff --git a/lib/compass/sass_extensions/sprites/base.rb b/lib/compass/sass_extensions/sprites/base.rb index 194a5601..85fd668d 100644 --- a/lib/compass/sass_extensions/sprites/base.rb +++ b/lib/compass/sass_extensions/sprites/base.rb @@ -118,12 +118,21 @@ module Compass # Generate a sprite image if necessary def generate if generation_required? + if options["#{@map.name}_clean_up_sprites"] + cleanup_old_sprites + end sprite_data = construct_sprite save!(sprite_data) Compass.configuration.run_callback(:sprite_generated, sprite_data) end end + def cleanup_old_sprites + Dir[File.join(Compass.configuration.images_path, "#{path}-*.png")].each do |file| + FileUtils.rm file + end + end + # Does this sprite need to be generated def generation_required? !File.exists?(filename) || outdated? diff --git a/lib/compass/sass_extensions/sprites/sprite_map.rb b/lib/compass/sass_extensions/sprites/sprite_map.rb index f2106739..c17423f1 100644 --- a/lib/compass/sass_extensions/sprites/sprite_map.rb +++ b/lib/compass/sass_extensions/sprites/sprite_map.rb @@ -74,6 +74,7 @@ $#{name}-position: 0% !default; $#{name}-spacing: 0 !default; $#{name}-repeat: no-repeat !default; $#{name}-prefix: '' !default; +$#{name}-clean-up-sprites: true !default; #{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\");" : generate_overrides } diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index 8e6f4173..fdc43d5b 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -9,8 +9,8 @@ class SpritesTest < Test::Unit::TestCase def setup Compass.reset_configuration! - @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') + @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 file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n") Compass.add_configuration(file, "sprite_config") diff --git a/test/units/compass_png_test.rb b/test/units/compass_png_test.rb index b8fd70c8..2a71e198 100644 --- a/test/units/compass_png_test.rb +++ b/test/units/compass_png_test.rb @@ -1,7 +1,7 @@ require 'test_helper' require 'fileutils' -class CommandLineTest < Test::Unit::TestCase +class CompassPngTest < Test::Unit::TestCase def test_class_crc_table assert_equal 256, Compass::PNG::CRC_TABLE.length diff --git a/test/units/sprites/base_test.rb b/test/units/sprites/base_test.rb index 1798d56c..3d0f1487 100644 --- a/test/units/sprites/base_test.rb +++ b/test/units/sprites/base_test.rb @@ -3,8 +3,8 @@ require 'test_helper' class SpritesBaseTest < Test::Unit::TestCase def setup - @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') + @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 @@ -81,7 +81,7 @@ class SpritesBaseTest < Test::Unit::TestCase file_to_remove = File.join(@images_tmp_path, 'selectors', 'ten-by-ten.png') FileUtils.rm file_to_remove assert !File.exists?(file_to_remove), "Failed to remove sprite file" - @options["remove_old_sprites"] = true + @options["selectors_clean_up_sprites"] = true setup_map @base.generate assert !File.exists?(file), "Sprite file did not get removed" diff --git a/test/units/sprites/image_test.rb b/test/units/sprites/image_test.rb index 93435ad8..01609932 100644 --- a/test/units/sprites/image_test.rb +++ b/test/units/sprites/image_test.rb @@ -5,7 +5,7 @@ class SpritesImageTest < Test::Unit::TestCase def setup - @images_src_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'sprites', 'public', 'images') + @images_src_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images') file = StringIO.new("images_path = #{@images_src_path.inspect}\n") Compass.add_configuration(file, "sprite_config") @repeat = 'no-repeat' From 4321fc0cf57e648ad097fc6fe6f1b03ba37b79ee Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 10 May 2011 19:20:38 -0400 Subject: [PATCH 03/12] refactored to allow a per sprite cleanup --- .../sass_extensions/functions/sprites.rb | 8 ++-- lib/compass/sass_extensions/sprites/base.rb | 12 +++--- .../sass_extensions/sprites/sprite_map.rb | 6 +-- test/integrations/sprites_test.rb | 37 +++++++++++++++++-- test/units/sprites/base_test.rb | 7 ++-- test/units/sprites/image_test.rb | 2 +- 6 files changed, 52 insertions(+), 20 deletions(-) diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index 18ca2009..4c426cf4 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -19,11 +19,11 @@ module Compass::SassExtensions::Functions::Sprites # # The sprite map object will generate the sprite map image, if necessary, # the first time it is converted to a url. Simply constructing it has no side-effects. - def sprite_map(glob, kwargs = {}) + def sprite_map(glob, cleanup, kwargs = {}) kwargs.extend VariableReader - Compass::SassExtensions::Sprites::Base.from_uri(glob, self, kwargs) - end - Sass::Script::Functions.declare :sprite_map, [:glob], :var_kwargs => true + Compass::SassExtensions::Sprites::Base.from_uri(glob, self, kwargs, cleanup) + end + Sass::Script::Functions.declare :sprite_map, [:glob, :cleanup], :var_kwargs => true # Returns the image and background position for use in a single shorthand property: # diff --git a/lib/compass/sass_extensions/sprites/base.rb b/lib/compass/sass_extensions/sprites/base.rb index 85fd668d..0a8506f3 100644 --- a/lib/compass/sass_extensions/sprites/base.rb +++ b/lib/compass/sass_extensions/sprites/base.rb @@ -6,13 +6,13 @@ module Compass # Initialize a new aprite object from a relative file path # the path is relative to the images_path confguration option - def self.from_uri(uri, context, kwargs) + def self.from_uri(uri, context, kwargs, cleanup = Sass::Script::Bool.new(true)) sprite_map = ::Compass::SpriteMap.new(uri.value, {}) sprites = sprite_map.files.map do |sprite| sprite.gsub(Compass.configuration.images_path+"/", "") end - new(sprites, sprite_map, context, kwargs) + new(sprites, sprite_map, context, cleanup, kwargs) end # Loads the sprite engine @@ -24,13 +24,13 @@ module Compass # We should do so only when the packing algorithm changes SPRITE_VERSION = "1" - attr_accessor :image_names, :path, :name, :options, :map + attr_accessor :image_names, :path, :name, :options, :map, :cleanup attr_accessor :images, :width, :height - def initialize(image_names, map, context, options) + def initialize(image_names, map, context, cleanup, options) require_engine! - @image_names, @path, @name, @options = image_names, map.path, map.name, options + @image_names, @path, @name, @options, @cleanup = image_names, map.path, map.name, options, cleanup @images = nil @width = nil @height = nil @@ -118,7 +118,7 @@ module Compass # Generate a sprite image if necessary def generate if generation_required? - if options["#{@map.name}_clean_up_sprites"] + if @cleanup.value cleanup_old_sprites end sprite_data = construct_sprite diff --git a/lib/compass/sass_extensions/sprites/sprite_map.rb b/lib/compass/sass_extensions/sprites/sprite_map.rb index c17423f1..fd971f96 100644 --- a/lib/compass/sass_extensions/sprites/sprite_map.rb +++ b/lib/compass/sass_extensions/sprites/sprite_map.rb @@ -74,9 +74,9 @@ $#{name}-position: 0% !default; $#{name}-spacing: 0 !default; $#{name}-repeat: no-repeat !default; $#{name}-prefix: '' !default; -$#{name}-clean-up-sprites: true !default; +$#{name}-clean-up: true !default; -#{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\");" : generate_overrides } +#{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\", $#{name}-clean-up);" : generate_overrides } // All sprites should extend this class // The #{name}-sprite mixin will do so for you. @@ -130,7 +130,7 @@ $#{name}-#{sprite_name}-repeat: $#{name}-repeat !default; SCSS end.join - content += "\n$#{name}-sprites: sprite-map(\"#{uri}\",\n" + content += "\n$#{name}-sprites: sprite-map(\"#{uri}\", $#{name}-clean-up,\n" content += sprite_names.map do |sprite_name| %Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position, $#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing, diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index fdc43d5b..74f122f5 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -24,7 +24,11 @@ class SpritesTest < Test::Unit::TestCase def map_location(file) - Dir.glob(File.join(@images_tmp_path, file)).first + map_files(file).first + end + + def map_files(glob) + Dir.glob(File.join(@images_tmp_path, glob)) end def image_size(file) @@ -255,7 +259,7 @@ class SpritesTest < Test::Unit::TestCase it "should use position adjustments in functions" do css = render <<-SCSS - $squares: sprite-map("squares/*.png", $position: 100%); + $squares: sprite-map("squares/*.png", true, $position: 100%); .squares-sprite { background: $squares no-repeat; } @@ -407,7 +411,7 @@ class SpritesTest < Test::Unit::TestCase it "should work even if @import is missing" do css = render <<-SCSS .squares { - background: sprite(sprite-map("squares/*.png"), twenty-by-twenty) no-repeat; + background: sprite(sprite-map("squares/*.png", true), twenty-by-twenty) no-repeat; } SCSS assert_correct css, <<-CSS @@ -546,5 +550,32 @@ class SpritesTest < Test::Unit::TestCase } CSS end + + it "should generate a sprite and remove the old file" do + FileUtils.touch File.join(@images_tmp_path, "selectors-cc8834Fdd.png") + assert_equal 1, map_files('selectors-*.png').size + css = render <<-SCSS + @import "selectors/*.png"; + a { + $disable-magic-sprite-selectors:true; + @include selectors-sprite(ten-by-ten) + } + SCSS + assert_equal 1, map_files('selectors-*.png').size, "File was not removed" + end + + it "should generate a sprite and NOT remove the old file" do + FileUtils.touch File.join(@images_tmp_path, "selectors-cc8834Ftest.png") + assert_equal 1, map_files('selectors-*.png').size + css = render <<-SCSS + $selectors-clean-up: false; + @import "selectors/*.png"; + a { + $disable-magic-sprite-selectors:true; + @include selectors-sprite(ten-by-ten) + } + SCSS + assert_equal 2, map_files('selectors-*.png').size, "File was removed" + end end \ No newline at end of file diff --git a/test/units/sprites/base_test.rb b/test/units/sprites/base_test.rb index 3d0f1487..d6c2d322 100644 --- a/test/units/sprites/base_test.rb +++ b/test/units/sprites/base_test.rb @@ -3,6 +3,7 @@ require 'test_helper' class SpritesBaseTest < 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 @@ -10,13 +11,13 @@ class SpritesBaseTest < Test::Unit::TestCase config.images_path = @images_tmp_path Compass.add_configuration(config) Compass.configure_sass_plugin! - @options = Compass.sass_engine_options.extend Compass::SassExtensions::Functions::Sprites::VariableReader + @options = {} setup_map end def setup_map @map = Compass::SpriteMap.new("selectors/*.png", @options) - @base = Compass::SassExtensions::Sprites::Base.new(@map.sprite_names.map{|n| "selectors/#{n}.png"}, @map, @map.sass_engine, @map.options) + @base = Compass::SassExtensions::Sprites::Base.new(@map.sprite_names.map{|n| "selectors/#{n}.png"}, @map, @map.sass_engine, Sass::Script::Bool.new(true), @map.options) end def teardown @@ -81,7 +82,7 @@ class SpritesBaseTest < Test::Unit::TestCase file_to_remove = File.join(@images_tmp_path, 'selectors', 'ten-by-ten.png') FileUtils.rm file_to_remove assert !File.exists?(file_to_remove), "Failed to remove sprite file" - @options["selectors_clean_up_sprites"] = true + @options["cleanup"] = true setup_map @base.generate assert !File.exists?(file), "Sprite file did not get removed" diff --git a/test/units/sprites/image_test.rb b/test/units/sprites/image_test.rb index 01609932..6a7d5a2e 100644 --- a/test/units/sprites/image_test.rb +++ b/test/units/sprites/image_test.rb @@ -20,7 +20,7 @@ class SpritesImageTest < Test::Unit::TestCase def parent map = Compass::SpriteMap.new("selectors/*.png", options) - @parent ||= Compass::SassExtensions::Sprites::Base.new(map.sprite_names.map{|n| "selectors/#{n}.png"}, map, map.sass_engine, map.options) + @parent ||= Compass::SassExtensions::Sprites::Base.new(map.sprite_names.map{|n| "selectors/#{n}.png"}, map, map.sass_engine, Sass::Script::Bool.new(true), map.options) end let(:options) do From 325306dcec16b8c8ff1c00b97f08e5c847740826 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 10 May 2011 21:04:57 -0400 Subject: [PATCH 04/12] Fixed and issue with the options keyword in the Sprite::Base class. it was casing the passed options to be reset to an empty hash. I renamed it to kwargs for consistancy. I also refactored my previous changes to be unobtrusive to people currently using the sprite-map function without an @import. --- .../sass_extensions/functions/sprites.rb | 6 ++--- lib/compass/sass_extensions/sprites/base.rb | 23 +++++++++++-------- .../sass_extensions/sprites/sprite_map.rb | 4 ++-- test/integrations/sprites_test.rb | 4 ++-- test/units/sprites/base_test.rb | 5 ++-- test/units/sprites/image_test.rb | 2 +- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index 4c426cf4..1ab53e26 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -19,11 +19,11 @@ module Compass::SassExtensions::Functions::Sprites # # The sprite map object will generate the sprite map image, if necessary, # the first time it is converted to a url. Simply constructing it has no side-effects. - def sprite_map(glob, cleanup, kwargs = {}) + def sprite_map(glob, kwargs = {}) kwargs.extend VariableReader - Compass::SassExtensions::Sprites::Base.from_uri(glob, self, kwargs, cleanup) + Compass::SassExtensions::Sprites::Base.from_uri(glob, self, kwargs) end - Sass::Script::Functions.declare :sprite_map, [:glob, :cleanup], :var_kwargs => true + Sass::Script::Functions.declare :sprite_map, [:glob], :var_kwargs => true # Returns the image and background position for use in a single shorthand property: # diff --git a/lib/compass/sass_extensions/sprites/base.rb b/lib/compass/sass_extensions/sprites/base.rb index 0a8506f3..4bdea36b 100644 --- a/lib/compass/sass_extensions/sprites/base.rb +++ b/lib/compass/sass_extensions/sprites/base.rb @@ -6,13 +6,12 @@ module Compass # Initialize a new aprite object from a relative file path # the path is relative to the images_path confguration option - def self.from_uri(uri, context, kwargs, cleanup = Sass::Script::Bool.new(true)) + def self.from_uri(uri, context, kwargs) sprite_map = ::Compass::SpriteMap.new(uri.value, {}) - sprites = sprite_map.files.map do |sprite| sprite.gsub(Compass.configuration.images_path+"/", "") end - new(sprites, sprite_map, context, cleanup, kwargs) + new(sprites, sprite_map, context, kwargs) end # Loads the sprite engine @@ -24,18 +23,22 @@ module Compass # We should do so only when the packing algorithm changes SPRITE_VERSION = "1" - attr_accessor :image_names, :path, :name, :options, :map, :cleanup + attr_accessor :image_names, :path, :name, :map, :kwargs attr_accessor :images, :width, :height - def initialize(image_names, map, context, cleanup, options) + def initialize(sprites, sprite_map, context, kwargs) require_engine! - @image_names, @path, @name, @options, @cleanup = image_names, map.path, map.name, options, cleanup + @image_names = sprites + @path = sprite_map.path + @name = sprite_map.name + @kwargs = kwargs + @kwargs['cleanup'] ||= Sass::Script::Bool.new(true) @images = nil @width = nil @height = nil @evaluation_context = context - @map = map + @map = sprite_map validate! compute_image_metadata! end @@ -58,7 +61,7 @@ module Compass # Creates the Sprite::Image objects for each image and calculates the width def init_images @images = image_names.collect do |relative_file| - image = Compass::SassExtensions::Sprites::Image.new(self, relative_file, options) + image = Compass::SassExtensions::Sprites::Image.new(self, relative_file, kwargs) @width = [ @width, image.width + image.offset ].max image end @@ -118,7 +121,7 @@ module Compass # Generate a sprite image if necessary def generate if generation_required? - if @cleanup.value + if kwargs.get_var('cleanup').value cleanup_old_sprites end sprite_data = construct_sprite @@ -183,7 +186,7 @@ module Compass to_s end - def to_s(options = self.options) + def to_s(kwargs = self.kwargs) sprite_url(self).value end diff --git a/lib/compass/sass_extensions/sprites/sprite_map.rb b/lib/compass/sass_extensions/sprites/sprite_map.rb index fd971f96..7e19fdf5 100644 --- a/lib/compass/sass_extensions/sprites/sprite_map.rb +++ b/lib/compass/sass_extensions/sprites/sprite_map.rb @@ -76,7 +76,7 @@ $#{name}-repeat: no-repeat !default; $#{name}-prefix: '' !default; $#{name}-clean-up: true !default; -#{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\", $#{name}-clean-up);" : generate_overrides } +#{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\", $cleanup: $#{name}-clean-up);" : generate_overrides } // All sprites should extend this class // The #{name}-sprite mixin will do so for you. @@ -130,7 +130,7 @@ $#{name}-#{sprite_name}-repeat: $#{name}-repeat !default; SCSS end.join - content += "\n$#{name}-sprites: sprite-map(\"#{uri}\", $#{name}-clean-up,\n" + content += "\n$#{name}-sprites: sprite-map(\"#{uri}\",\n$cleanup: $#{name}-clean-up,\n" content += sprite_names.map do |sprite_name| %Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position, $#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing, diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index 74f122f5..549427d4 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -259,7 +259,7 @@ class SpritesTest < Test::Unit::TestCase it "should use position adjustments in functions" do css = render <<-SCSS - $squares: sprite-map("squares/*.png", true, $position: 100%); + $squares: sprite-map("squares/*.png", $position: 100%); .squares-sprite { background: $squares no-repeat; } @@ -411,7 +411,7 @@ class SpritesTest < Test::Unit::TestCase it "should work even if @import is missing" do css = render <<-SCSS .squares { - background: sprite(sprite-map("squares/*.png", true), twenty-by-twenty) no-repeat; + background: sprite(sprite-map("squares/*.png"), twenty-by-twenty) no-repeat; } SCSS assert_correct css, <<-CSS diff --git a/test/units/sprites/base_test.rb b/test/units/sprites/base_test.rb index d6c2d322..e79a11c3 100644 --- a/test/units/sprites/base_test.rb +++ b/test/units/sprites/base_test.rb @@ -11,13 +11,13 @@ class SpritesBaseTest < Test::Unit::TestCase config.images_path = @images_tmp_path Compass.add_configuration(config) Compass.configure_sass_plugin! - @options = {} + @options = {'cleanup' => Sass::Script::Bool.new(true)} setup_map end def setup_map @map = Compass::SpriteMap.new("selectors/*.png", @options) - @base = Compass::SassExtensions::Sprites::Base.new(@map.sprite_names.map{|n| "selectors/#{n}.png"}, @map, @map.sass_engine, Sass::Script::Bool.new(true), @map.options) + @base = Compass::SassExtensions::Sprites::Base.new(@map.sprite_names.map{|n| "selectors/#{n}.png"}, @map, @map.sass_engine, @map.options) end def teardown @@ -82,7 +82,6 @@ class SpritesBaseTest < Test::Unit::TestCase file_to_remove = File.join(@images_tmp_path, 'selectors', 'ten-by-ten.png') FileUtils.rm file_to_remove assert !File.exists?(file_to_remove), "Failed to remove sprite file" - @options["cleanup"] = true setup_map @base.generate assert !File.exists?(file), "Sprite file did not get removed" diff --git a/test/units/sprites/image_test.rb b/test/units/sprites/image_test.rb index 6a7d5a2e..01609932 100644 --- a/test/units/sprites/image_test.rb +++ b/test/units/sprites/image_test.rb @@ -20,7 +20,7 @@ class SpritesImageTest < Test::Unit::TestCase def parent map = Compass::SpriteMap.new("selectors/*.png", options) - @parent ||= Compass::SassExtensions::Sprites::Base.new(map.sprite_names.map{|n| "selectors/#{n}.png"}, map, map.sass_engine, Sass::Script::Bool.new(true), map.options) + @parent ||= Compass::SassExtensions::Sprites::Base.new(map.sprite_names.map{|n| "selectors/#{n}.png"}, map, map.sass_engine, map.options) end let(:options) do From 84d207f8277a0456adf21e18468dea7408cff53a Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 10 May 2011 21:51:35 -0400 Subject: [PATCH 05/12] Sass Colors will no longer cause an error if you use them as sprite names. closes #381 --- lib/compass/sass_extensions/functions/sprites.rb | 12 ++++++++++++ test/integrations/sprites_test.rb | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index 1ab53e26..ab6bf017 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -34,6 +34,7 @@ module Compass::SassExtensions::Functions::Sprites # # background: url('/images/icons.png?12345678') 0 -24px no-repeat; def sprite(map, sprite, offset_x = ZERO, offset_y = ZERO) + sprite = convert_sprite(sprite) verify_map(map) unless sprite.is_a?(Sass::Script::String) raise Sass::SyntaxError, %Q(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.) @@ -56,6 +57,7 @@ module Compass::SassExtensions::Functions::Sprites # Returns the path to the original image file for the sprite with the given name def sprite_file(map, sprite) + sprite = convert_sprite(sprite) verify_map(map, "sprite") verify_sprite(sprite) if image = map.image_for(sprite.value) @@ -68,6 +70,7 @@ module Compass::SassExtensions::Functions::Sprites # Returns voolean if sprite has a parent def sprite_does_not_have_parent(map, sprite) + sprite = convert_sprite(sprite) verify_map map verify_sprite sprite Sass::Script::Bool.new map.image_for(sprite.value).parent.nil? @@ -77,6 +80,7 @@ module Compass::SassExtensions::Functions::Sprites # Returns boolean if sprite has the selector def sprite_has_selector(map, sprite, selector) + sprite = convert_sprite(sprite) verify_map map verify_sprite sprite unless VALID_SELECTORS.include?(selector.value) @@ -118,6 +122,7 @@ module Compass::SassExtensions::Functions::Sprites # # background-position: 3px -36px; def sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO) + sprite = convert_sprite(sprite) verify_map(map, "sprite-position") unless sprite && sprite.is_a?(Sass::Script::String) raise Sass::SyntaxError, %Q(The second argument to sprite-position must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.) @@ -147,6 +152,13 @@ module Compass::SassExtensions::Functions::Sprites protected + def convert_sprite(sprite) + if sprite.is_a?(Sass::Script::Color) + return Sass::Script::String.new(sprite.to_s) + end + sprite + end + def verify_map(map, error = "sprite") unless map.is_a?(Compass::SassExtensions::Sprites::Base) missing_sprite!(error) diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index 549427d4..3f482e62 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -577,5 +577,15 @@ class SpritesTest < Test::Unit::TestCase SCSS assert_equal 2, map_files('selectors-*.png').size, "File was removed" end + + it "should generate a sprite if the sprite is a colorname" do + css = render <<-SCSS + @import "colors/*.png"; + a { + @include colors-sprite(blue); + } + SCSS + assert !css.empty? + end end \ No newline at end of file From 369c8d636ebe3f98a69380aea7ddfb7a49fa863e Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 10 May 2011 21:57:43 -0400 Subject: [PATCH 06/12] forgot test files --- .../sprites/public/images/colors/blue.png | Bin 0 -> 2804 bytes .../sprites/public/images/colors/yellow.png | Bin 0 -> 2804 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/fixtures/sprites/public/images/colors/blue.png create mode 100644 test/fixtures/sprites/public/images/colors/yellow.png diff --git a/test/fixtures/sprites/public/images/colors/blue.png b/test/fixtures/sprites/public/images/colors/blue.png new file mode 100644 index 0000000000000000000000000000000000000000..c0ae53ccadde24b58be417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ryqZLBKpMrlfEarPuZSoKCN}SvX$Ce&<3?-w@tOjw-0qh zbo8I`In&+g(AoN%@o#l!)y`I&lRZ~_o_Id*{OpCC3)5Y~uE~qMizD4@x*uO!ap~UW z<(GS}_+Gho)${759+#dA*Bq~%y>5T~%njQc?KiD&w%xM2)%v^D@2$Poy=}K`Zg=$A z^>y|y?LU9V`Od|=?su==W8J$s;6KoRKlJ{C!KlHZ2iyna50f6gd6e;J=JDnym?s5K zrJj~PQ+ihWhu$A8L)Js*hTVs6Jr92Vc!V?Z>d(|azmDd;pu8v@QypsSHf2_lllLW{#WH|-Pfo8V*Yh&YQ@y(8_}EDw?*&d-_^aheBV7CIQ{HH@`ss^ z1)t Date: Tue, 10 May 2011 22:44:10 -0400 Subject: [PATCH 07/12] Fixed problem with globs only going one directoy deep from now on imports like foo/*.png will get mapped to foo/**/*.png Please enter the commit message for your changes. Lines starting --- .../sass_extensions/sprites/sprite_map.rb | 17 ++++++++++++++--- lib/compass/sass_extensions/sprites/sprites.rb | 2 +- test/integrations/sprites_test.rb | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/compass/sass_extensions/sprites/sprite_map.rb b/lib/compass/sass_extensions/sprites/sprite_map.rb index 7e19fdf5..10f860e1 100644 --- a/lib/compass/sass_extensions/sprites/sprite_map.rb +++ b/lib/compass/sass_extensions/sprites/sprite_map.rb @@ -25,7 +25,7 @@ module Compass # Returns the Glob of image files for this sprite def files - @files ||= Dir[File.join(Compass.configuration.images_path, uri)].sort + @files ||= Dir[File.join(Compass.configuration.images_path, uri).gsub('/*', '/**/*')].sort end # Returns an Array of image names without the file extension @@ -50,7 +50,18 @@ module Compass end def ensure_path_and_name! - @path, @name = Compass::Sprites.path_and_name(uri) + @path ||= get_path + @name ||= get_name + end + + def get_name + _, name = Compass::Sprites.path_and_name(uri) + name + end + + def get_path + path, _ = Compass::Sprites.path_and_name(uri) + path end def key(uri, options) @@ -130,7 +141,7 @@ $#{name}-#{sprite_name}-repeat: $#{name}-repeat !default; SCSS end.join - content += "\n$#{name}-sprites: sprite-map(\"#{uri}\",\n$cleanup: $#{name}-clean-up,\n" + content += "\n$#{name}-sprites: sprite-map(\"#{uri}\", \n$cleanup: $#{name}-clean-up,\n" content += sprite_names.map do |sprite_name| %Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position, $#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing, diff --git a/lib/compass/sass_extensions/sprites/sprites.rb b/lib/compass/sass_extensions/sprites/sprites.rb index c0c5dc21..7696d3bd 100644 --- a/lib/compass/sass_extensions/sprites/sprites.rb +++ b/lib/compass/sass_extensions/sprites/sprites.rb @@ -7,7 +7,7 @@ module Compass [$1, $3, $4] end end - + def self.discover_sprites(uri) self.load_map(uri, {}).files end diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index 3f482e62..ea077625 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -587,5 +587,21 @@ class SpritesTest < Test::Unit::TestCase SCSS assert !css.empty? end + + it "should generate a sprite from nested folders" do + css = render <<-SCSS + @import "nested/*.png"; + @include all-nested-sprites; + SCSS + assert_correct css, <<-CSS + .nested-sprite, .nested-ten-by-ten { + background: url('/nested-55a8935544.png') no-repeat; + } + + .nested-ten-by-ten { + background-position: 0 0; + } + CSS + end end \ No newline at end of file From fdd639efafcdaf055c22f6ed169805a93c16cf94 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Wed, 11 May 2011 02:41:51 -0400 Subject: [PATCH 08/12] updated the regex to support nested files and refactored some unclear functions --- lib/compass/sass_extensions/sprites/sprite_map.rb | 2 +- lib/compass/sass_extensions/sprites/sprites.rb | 4 ++-- test/integrations/sprites_test.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/compass/sass_extensions/sprites/sprite_map.rb b/lib/compass/sass_extensions/sprites/sprite_map.rb index 10f860e1..121c4e12 100644 --- a/lib/compass/sass_extensions/sprites/sprite_map.rb +++ b/lib/compass/sass_extensions/sprites/sprite_map.rb @@ -25,7 +25,7 @@ module Compass # Returns the Glob of image files for this sprite def files - @files ||= Dir[File.join(Compass.configuration.images_path, uri).gsub('/*', '/**/*')].sort + @files ||= Dir[File.join(Compass.configuration.images_path, uri)].sort end # Returns an Array of image names without the file extension diff --git a/lib/compass/sass_extensions/sprites/sprites.rb b/lib/compass/sass_extensions/sprites/sprites.rb index 7696d3bd..7431983f 100644 --- a/lib/compass/sass_extensions/sprites/sprites.rb +++ b/lib/compass/sass_extensions/sprites/sprites.rb @@ -3,8 +3,8 @@ module Compass attr_accessor :name, :path def self.path_and_name(uri) - if uri =~ %r{((.+/)?(.+))/(.+?)\.png} - [$1, $3, $4] + if uri =~ %r{((.+/)?([^\*.]+))/(.+?)\.png} + [$1, $3] end end diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index ea077625..23a45996 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -590,7 +590,7 @@ class SpritesTest < Test::Unit::TestCase it "should generate a sprite from nested folders" do css = render <<-SCSS - @import "nested/*.png"; + @import "nested/**/*.png"; @include all-nested-sprites; SCSS assert_correct css, <<-CSS From 2f105f3696b20e4a486e20f556ff4eac5e4100b7 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Wed, 11 May 2011 02:45:26 -0400 Subject: [PATCH 09/12] made things less ambiguous --- lib/compass/sass_extensions/functions/sprites.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index ab6bf017..69b7599e 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -34,7 +34,7 @@ module Compass::SassExtensions::Functions::Sprites # # background: url('/images/icons.png?12345678') 0 -24px no-repeat; def sprite(map, sprite, offset_x = ZERO, offset_y = ZERO) - sprite = convert_sprite(sprite) + sprite = convert_sprite_name(sprite) verify_map(map) unless sprite.is_a?(Sass::Script::String) raise Sass::SyntaxError, %Q(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.) @@ -57,7 +57,7 @@ module Compass::SassExtensions::Functions::Sprites # Returns the path to the original image file for the sprite with the given name def sprite_file(map, sprite) - sprite = convert_sprite(sprite) + sprite = convert_sprite_name(sprite) verify_map(map, "sprite") verify_sprite(sprite) if image = map.image_for(sprite.value) @@ -70,7 +70,7 @@ module Compass::SassExtensions::Functions::Sprites # Returns voolean if sprite has a parent def sprite_does_not_have_parent(map, sprite) - sprite = convert_sprite(sprite) + sprite = convert_sprite_name(sprite) verify_map map verify_sprite sprite Sass::Script::Bool.new map.image_for(sprite.value).parent.nil? @@ -80,7 +80,7 @@ module Compass::SassExtensions::Functions::Sprites # Returns boolean if sprite has the selector def sprite_has_selector(map, sprite, selector) - sprite = convert_sprite(sprite) + sprite = convert_sprite_name(sprite) verify_map map verify_sprite sprite unless VALID_SELECTORS.include?(selector.value) @@ -122,7 +122,7 @@ module Compass::SassExtensions::Functions::Sprites # # background-position: 3px -36px; def sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO) - sprite = convert_sprite(sprite) + sprite = convert_sprite_name(sprite) verify_map(map, "sprite-position") unless sprite && sprite.is_a?(Sass::Script::String) raise Sass::SyntaxError, %Q(The second argument to sprite-position must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.) @@ -152,9 +152,9 @@ module Compass::SassExtensions::Functions::Sprites protected - def convert_sprite(sprite) + def convert_sprite_name(sprite) if sprite.is_a?(Sass::Script::Color) - return Sass::Script::String.new(sprite.to_s) + return Sass::Script::String.new(Sass::Script::Color::HTML4_COLORS_REVERSE[sprite.rgb]) end sprite end From c83432d1c0c5b0ce0090cacbaf64e296bb272fd4 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Wed, 11 May 2011 03:10:11 -0400 Subject: [PATCH 10/12] updated change log --- doc-src/content/CHANGELOG.markdown | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc-src/content/CHANGELOG.markdown b/doc-src/content/CHANGELOG.markdown index 3b966e4b..218c8b5e 100644 --- a/doc-src/content/CHANGELOG.markdown +++ b/doc-src/content/CHANGELOG.markdown @@ -14,6 +14,13 @@ 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.11.3 (PENDING) +------------------- +* Sprites will now by default remove any old versions of the sprite a new variable has been created to override this. +* Nested sprites are now supported using globs `@import 'nested/**/*.png';`. +* Fixed a bug that was causing sprite variable options to not get passed to the image classes. +* Sass Colors will no longer cause an error if you use them as sprite names. + 0.11.2 (05/01/2011) ------------------- From d254f41696a2b83ce457b347213b04fbec8222ab Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Wed, 11 May 2011 23:21:51 -0400 Subject: [PATCH 11/12] updated sprite 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 77169578..92f80553 100644 --- a/doc-src/content/help/tutorials/spriting.markdown +++ b/doc-src/content/help/tutorials/spriting.markdown @@ -182,6 +182,7 @@ the sprites were contained within a folder called `icon`. included in each sprite's CSS output. Can be `true` or `false`. Defaults to `false`. * `$-sprite-base-class` -- The base class for these sprites. Defaults to `.-sprite`. E.g. `$icon-sprite-base-class: ".action-icon"` +* `$-clean-up` -- Wheter or not to removed the old sprite file when a new one is created. Defaults to true ### Options per Sprite From ef18040a0bfca4c7851d35c8e88f7555986e43a2 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Wed, 11 May 2011 23:22:17 -0400 Subject: [PATCH 12/12] typo --- doc-src/content/help/tutorials/spriting.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-src/content/help/tutorials/spriting.markdown b/doc-src/content/help/tutorials/spriting.markdown index 92f80553..bf3d1b08 100644 --- a/doc-src/content/help/tutorials/spriting.markdown +++ b/doc-src/content/help/tutorials/spriting.markdown @@ -182,7 +182,7 @@ the sprites were contained within a folder called `icon`. included in each sprite's CSS output. Can be `true` or `false`. Defaults to `false`. * `$-sprite-base-class` -- The base class for these sprites. Defaults to `.-sprite`. E.g. `$icon-sprite-base-class: ".action-icon"` -* `$-clean-up` -- Wheter or not to removed the old sprite file when a new one is created. Defaults to true +* `$-clean-up` -- Whether or not to removed the old sprite file when a new one is created. Defaults to true ### Options per Sprite