old sprites will now be removed by default
This commit is contained in:
parent
8f675f936b
commit
6cb9bc2662
@ -15,14 +15,15 @@ $sprite-selectors: hover, target, active !default;
|
|||||||
background-position: sprite-position($map, $sprite, $offset-x, $offset-y);
|
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`
|
// Include the position and (optionally) dimensions of this `$sprite`
|
||||||
// in the given sprite `$map`. The sprite url should come from either a base
|
// 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:
|
// class or you can specify the `sprite-url` explicitly like this:
|
||||||
//
|
//
|
||||||
// background: $map no-repeat;
|
// background: $map no-repeat;
|
||||||
|
|
||||||
$disable-magic-sprite-selectors:false !default;
|
|
||||||
|
|
||||||
@mixin sprite($map, $sprite, $dimensions: false, $offset-x: 0, $offset-y: 0) {
|
@mixin sprite($map, $sprite, $dimensions: false, $offset-x: 0, $offset-y: 0) {
|
||||||
@include sprite-background-position($map, $sprite, $offset-x, $offset-y);
|
@include sprite-background-position($map, $sprite, $offset-x, $offset-y);
|
||||||
@if $dimensions {
|
@if $dimensions {
|
||||||
|
@ -118,12 +118,21 @@ module Compass
|
|||||||
# Generate a sprite image if necessary
|
# Generate a sprite image if necessary
|
||||||
def generate
|
def generate
|
||||||
if generation_required?
|
if generation_required?
|
||||||
|
if options["#{@map.name}_clean_up_sprites"]
|
||||||
|
cleanup_old_sprites
|
||||||
|
end
|
||||||
sprite_data = construct_sprite
|
sprite_data = construct_sprite
|
||||||
save!(sprite_data)
|
save!(sprite_data)
|
||||||
Compass.configuration.run_callback(:sprite_generated, sprite_data)
|
Compass.configuration.run_callback(:sprite_generated, sprite_data)
|
||||||
end
|
end
|
||||||
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
|
# Does this sprite need to be generated
|
||||||
def generation_required?
|
def generation_required?
|
||||||
!File.exists?(filename) || outdated?
|
!File.exists?(filename) || outdated?
|
||||||
|
@ -74,6 +74,7 @@ $#{name}-position: 0% !default;
|
|||||||
$#{name}-spacing: 0 !default;
|
$#{name}-spacing: 0 !default;
|
||||||
$#{name}-repeat: no-repeat !default;
|
$#{name}-repeat: no-repeat !default;
|
||||||
$#{name}-prefix: '' !default;
|
$#{name}-prefix: '' !default;
|
||||||
|
$#{name}-clean-up-sprites: true !default;
|
||||||
|
|
||||||
#{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\");" : generate_overrides }
|
#{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\");" : generate_overrides }
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ class SpritesTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Compass.reset_configuration!
|
Compass.reset_configuration!
|
||||||
@images_src_path = File.join(File.dirname(__FILE__), 'fixtures', 'sprites', 'public', 'images')
|
@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_tmp_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'sprites', 'public', 'images-tmp')
|
||||||
::FileUtils.cp_r @images_src_path, @images_tmp_path
|
::FileUtils.cp_r @images_src_path, @images_tmp_path
|
||||||
file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n")
|
file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n")
|
||||||
Compass.add_configuration(file, "sprite_config")
|
Compass.add_configuration(file, "sprite_config")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
|
||||||
class CommandLineTest < Test::Unit::TestCase
|
class CompassPngTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_class_crc_table
|
def test_class_crc_table
|
||||||
assert_equal 256, Compass::PNG::CRC_TABLE.length
|
assert_equal 256, Compass::PNG::CRC_TABLE.length
|
||||||
|
@ -3,8 +3,8 @@ require 'test_helper'
|
|||||||
class SpritesBaseTest < Test::Unit::TestCase
|
class SpritesBaseTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def setup
|
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')
|
||||||
@images_tmp_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'sprites', 'public', 'images-tmp')
|
@images_tmp_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images-tmp')
|
||||||
FileUtils.cp_r @images_src_path, @images_tmp_path
|
FileUtils.cp_r @images_src_path, @images_tmp_path
|
||||||
config = Compass::Configuration::Data.new('config')
|
config = Compass::Configuration::Data.new('config')
|
||||||
config.images_path = @images_tmp_path
|
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')
|
file_to_remove = File.join(@images_tmp_path, 'selectors', 'ten-by-ten.png')
|
||||||
FileUtils.rm file_to_remove
|
FileUtils.rm file_to_remove
|
||||||
assert !File.exists?(file_to_remove), "Failed to remove sprite file"
|
assert !File.exists?(file_to_remove), "Failed to remove sprite file"
|
||||||
@options["remove_old_sprites"] = true
|
@options["selectors_clean_up_sprites"] = true
|
||||||
setup_map
|
setup_map
|
||||||
@base.generate
|
@base.generate
|
||||||
assert !File.exists?(file), "Sprite file did not get removed"
|
assert !File.exists?(file), "Sprite file did not get removed"
|
||||||
|
@ -5,7 +5,7 @@ class SpritesImageTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
|
|
||||||
def setup
|
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")
|
file = StringIO.new("images_path = #{@images_src_path.inspect}\n")
|
||||||
Compass.add_configuration(file, "sprite_config")
|
Compass.add_configuration(file, "sprite_config")
|
||||||
@repeat = 'no-repeat'
|
@repeat = 'no-repeat'
|
||||||
|
Loading…
Reference in New Issue
Block a user