From cd907d17a701887256561f8526b8b50c0dfb43fd Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Mon, 19 Sep 2011 07:28:29 -0700 Subject: [PATCH] Log the creation or unchanged status of sprites during compilation. --- lib/compass/compiler.rb | 2 ++ lib/compass/sass_extensions/functions/sprites.rb | 2 +- lib/compass/sass_extensions/sprites/sprite_methods.rb | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/compass/compiler.rb b/lib/compass/compiler.rb index 11759e26..a1006c21 100644 --- a/lib/compass/compiler.rb +++ b/lib/compass/compiler.rb @@ -15,6 +15,8 @@ module Compass self.sass_options.update(sass_opts) self.sass_options[:cache_location] ||= determine_cache_location self.sass_options[:importer] = self.importer = Sass::Importers::Filesystem.new(from) + self.sass_options[:compass] ||= {} + self.sass_options[:compass][:logger] = self.logger self.staleness_checker = Sass::Plugin::StalenessChecker.new(sass_options) end diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index e4df7c49..da193f8e 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -68,7 +68,7 @@ module Compass::SassExtensions::Functions::Sprites end Sass::Script::Functions.declare :sprite_file, [:map, :sprite] - # Returns voolean if sprite has a parent + # Returns boolean if sprite has a parent def sprite_does_not_have_parent(map, sprite) sprite = convert_sprite_name(sprite) verify_map map diff --git a/lib/compass/sass_extensions/sprites/sprite_methods.rb b/lib/compass/sass_extensions/sprites/sprite_methods.rb index d07b3d05..3dddbe51 100644 --- a/lib/compass/sass_extensions/sprites/sprite_methods.rb +++ b/lib/compass/sass_extensions/sprites/sprite_methods.rb @@ -46,6 +46,10 @@ module Compass File.join(Compass.configuration.generated_images_path, "#{path}-s#{uniqueness_hash}.png") end + def relativize(path) + Pathname.new(path).relative_path_from(Pathname.new(Dir.pwd)).to_s + end + # Generate a sprite image if necessary def generate if generation_required? @@ -55,11 +59,14 @@ module Compass engine.construct_sprite Compass.configuration.run_sprite_generated(engine.canvas) save! + else + options[:compass][:logger].record(:unchanged, relativize(filename)) end end def cleanup_old_sprites Dir[File.join(Compass.configuration.images_path, "#{path}-*.png")].each do |file| + options[:compass][:logger].record(:remove, relativize(file)) FileUtils.rm file end end @@ -89,6 +96,7 @@ module Compass def save! FileUtils.mkdir_p(File.dirname(filename)) saved = engine.save(filename) + options[:compass][:logger].record(:create, relativize(filename)) Compass.configuration.run_sprite_saved(filename) saved end