old sprites will now be removed by default

This commit is contained in:
Scott Davis 2011-05-10 18:02:32 -04:00
parent 8f675f936b
commit 6cb9bc2662
7 changed files with 21 additions and 10 deletions

View File

@ -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 {

View File

@ -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?

View File

@ -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 }

View File

@ -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")

View File

@ -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

View File

@ -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"

View File

@ -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'