diff --git a/lib/compass/compiler.rb b/lib/compass/compiler.rb index f5dcbe12..11759e26 100644 --- a/lib/compass/compiler.rb +++ b/lib/compass/compiler.rb @@ -138,7 +138,7 @@ module Compass end duration = options[:time] ? "(#{(css_content.__duration * 1000).round / 1000.0}s)" : "" write_file(css_filename, css_content, options.merge(:force => true, :extra => duration)) - Compass.configuration.run_callback(:stylesheet_saved, css_filename) + Compass.configuration.run_stylesheet_saved(css_filename) end def should_compile?(sass_filename, css_filename) @@ -159,7 +159,7 @@ module Compass formatted_error = "(Line #{e.sass_line}: #{e.message})" file = basename(sass_filename) logger.record :error, file, formatted_error - Compass.configuration.run_callback(:stylesheet_error, sass_filename, formatted_error) + Compass.configuration.run_stylesheet_error(sass_filename, formatted_error) write_file css_filename, error_contents(e, sass_filename), options.merge(:force => true) end diff --git a/lib/compass/configuration/data.rb b/lib/compass/configuration/data.rb index ddc2de3a..2bd3b997 100644 --- a/lib/compass/configuration/data.rb +++ b/lib/compass/configuration/data.rb @@ -18,12 +18,38 @@ module Compass class Data attr_reader :name + extend Sass::Callbacks + include Compass::Configuration::Inheritance include Compass::Configuration::Serialization include Compass::Configuration::Adapters extend Compass::Configuration::Paths + # on_sprite_saved + # yields the filename + # usage: on_sprite_saved {|filename| do_something(filename) } + define_callback :sprite_saved + chained_method :run_sprite_saved + + # on_sprite_generated + # yields 'ChunkyPNG::Image' + # usage: on_sprite_generated {|sprite_data| do_something(sprite_data) } + define_callback :sprite_generated + chained_method :run_sprite_generated + + # on_stylesheet_saved + # yields the filename + # usage: on_stylesheet_saved {|filename| do_something(filename) } + define_callback :stylesheet_saved + chained_method :run_stylesheet_saved + + # on_stylesheet_error + # yields the filename & message + # usage: on_stylesheet_error {|filename, message| do_something(filename, message) } + define_callback :stylesheet_error + chained_method :run_stylesheet_error + inherited_accessor *ATTRIBUTES inherited_accessor :required_libraries, :loaded_frameworks, :framework_path #XXX we should make these arrays add up cumulatively. @@ -138,16 +164,6 @@ module Compass relative_assets || http_images_path == :relative end - def run_callback(event, *args) - begin - send(:"run_#{event}", *args) - rescue NoMethodError => e - unless e.message =~ /run_#{event}/ - raise - end - end - end - private def assert_valid_keys!(attr_hash) diff --git a/lib/compass/configuration/file_data.rb b/lib/compass/configuration/file_data.rb index af628752..49c432d6 100644 --- a/lib/compass/configuration/file_data.rb +++ b/lib/compass/configuration/file_data.rb @@ -1,28 +1,6 @@ module Compass module Configuration class FileData < Data - extend Sass::Callbacks - - # on_sprite_generated - # yields the filename - # usage: on_sprite_save {|filename| do_somethign(filename) } - define_callback :sprite_saved - - # on_sprite_generated - # yields 'ChunkyPNG::Image' - # usage: on_sprite_generated {|sprite_data| do_something(sprite_data) } - define_callback :sprite_generated - - # on_stylesheet_saved - # yields the filename - # usage: on_stylesheet_saved {|filename| do_something(filename) } - define_callback :stylesheet_saved - - # on_stylesheet_error - # yields the filename & message - # usage: on_stylesheet_error {|filename, message| do_something(filename, message) } - define_callback :stylesheet_error - def self.new_from_file(config_file, defaults = nil) data = new(config_file) data.with_defaults(defaults) do diff --git a/lib/compass/configuration/helpers.rb b/lib/compass/configuration/helpers.rb index 9017f735..8164ff2b 100644 --- a/lib/compass/configuration/helpers.rb +++ b/lib/compass/configuration/helpers.rb @@ -68,10 +68,10 @@ module Compass end unless @callbacks_loaded Sass::Plugin.on_updating_stylesheet do |sass_file, css_file| - Compass.configuration.run_callback(:stylesheet_saved, css_file) + Compass.configuration.run_stylesheet_saved(css_file) end Sass::Plugin.on_compilation_error do |e, filename, css| - Compass.configuration.run_callback(:stylesheet_error, filename, e.message) + Compass.configuration.run_stylesheet_error(filename, e.message) end @callbacks_loaded = true end diff --git a/lib/compass/configuration/inheritance.rb b/lib/compass/configuration/inheritance.rb index da12b5bc..d7224ac5 100644 --- a/lib/compass/configuration/inheritance.rb +++ b/lib/compass/configuration/inheritance.rb @@ -61,6 +61,19 @@ module Compass inherited_writer(*attributes) end + def chained_method(method) + line = __LINE__ + 1 + class_eval %Q{ + alias_method :_chained_#{method}, method + def #{method}(*args, &block) + _chained_#{method}(*args, &block) + if inherited_data + inherited_data.#{method}(*args, &block) + end + end + }, __FILE__, line + end + end diff --git a/lib/compass/sass_extensions/sprites/sprite_methods.rb b/lib/compass/sass_extensions/sprites/sprite_methods.rb index 36cf76ed..d07b3d05 100644 --- a/lib/compass/sass_extensions/sprites/sprite_methods.rb +++ b/lib/compass/sass_extensions/sprites/sprite_methods.rb @@ -53,7 +53,7 @@ module Compass cleanup_old_sprites end engine.construct_sprite - Compass.configuration.run_callback(:sprite_generated, engine.canvas) + Compass.configuration.run_sprite_generated(engine.canvas) save! end end @@ -89,7 +89,7 @@ module Compass def save! FileUtils.mkdir_p(File.dirname(filename)) saved = engine.save(filename) - Compass.configuration.run_callback(:sprite_saved, filename) + Compass.configuration.run_sprite_saved(filename) saved end