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'