Refactor loggin within sprites

Handle missing logger instance more elegantly and centralize
relativizing and quiet mode checking.

Closes GH-84.
This commit is contained in:
Chris Eppstein 2011-09-26 09:00:51 -07:00
parent 9b56dc6169
commit fecc98219d

View File

@ -60,13 +60,13 @@ module Compass
Compass.configuration.run_sprite_generated(engine.canvas)
save!
else
options[:compass][:logger].record(:unchanged, relativize(filename)) unless options[:quiet]
log :unchanged, 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)) unless options[:quiet]
log :remove, file
FileUtils.rm file
Compass.configuration.run_sprite_removed(file)
end
@ -98,7 +98,7 @@ module Compass
def save!
FileUtils.mkdir_p(File.dirname(filename))
saved = engine.save(filename)
options[:compass][:logger].record(:create, relativize(filename)) unless options[:quiet]
log :create, filename
Compass.configuration.run_sprite_saved(filename)
saved
end
@ -126,6 +126,11 @@ module Compass
[width, height]
end
def log(action, filename, *extra)
if options[:compass] && options[:compass][:logger] && !options[:quiet]
options[:compass][:logger].record(action, relativize(filename), *extra)
end
end
end
end
end