Move callbacks to the configuration base class and make them work correctly with inherited data.
This commit is contained in:
parent
5896711c8a
commit
e2960d81b0
@ -138,7 +138,7 @@ module Compass
|
|||||||
end
|
end
|
||||||
duration = options[:time] ? "(#{(css_content.__duration * 1000).round / 1000.0}s)" : ""
|
duration = options[:time] ? "(#{(css_content.__duration * 1000).round / 1000.0}s)" : ""
|
||||||
write_file(css_filename, css_content, options.merge(:force => true, :extra => duration))
|
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
|
end
|
||||||
|
|
||||||
def should_compile?(sass_filename, css_filename)
|
def should_compile?(sass_filename, css_filename)
|
||||||
@ -159,7 +159,7 @@ module Compass
|
|||||||
formatted_error = "(Line #{e.sass_line}: #{e.message})"
|
formatted_error = "(Line #{e.sass_line}: #{e.message})"
|
||||||
file = basename(sass_filename)
|
file = basename(sass_filename)
|
||||||
logger.record :error, file, formatted_error
|
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)
|
write_file css_filename, error_contents(e, sass_filename), options.merge(:force => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,12 +18,38 @@ module Compass
|
|||||||
class Data
|
class Data
|
||||||
|
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
extend Sass::Callbacks
|
||||||
|
|
||||||
|
|
||||||
include Compass::Configuration::Inheritance
|
include Compass::Configuration::Inheritance
|
||||||
include Compass::Configuration::Serialization
|
include Compass::Configuration::Serialization
|
||||||
include Compass::Configuration::Adapters
|
include Compass::Configuration::Adapters
|
||||||
extend Compass::Configuration::Paths
|
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 *ATTRIBUTES
|
||||||
inherited_accessor :required_libraries, :loaded_frameworks, :framework_path #XXX we should make these arrays add up cumulatively.
|
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
|
relative_assets || http_images_path == :relative
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_callback(event, *args)
|
|
||||||
begin
|
|
||||||
send(:"run_#{event}", *args)
|
|
||||||
rescue NoMethodError => e
|
|
||||||
unless e.message =~ /run_#{event}/
|
|
||||||
raise
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assert_valid_keys!(attr_hash)
|
def assert_valid_keys!(attr_hash)
|
||||||
|
@ -1,28 +1,6 @@
|
|||||||
module Compass
|
module Compass
|
||||||
module Configuration
|
module Configuration
|
||||||
class FileData < Data
|
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)
|
def self.new_from_file(config_file, defaults = nil)
|
||||||
data = new(config_file)
|
data = new(config_file)
|
||||||
data.with_defaults(defaults) do
|
data.with_defaults(defaults) do
|
||||||
|
@ -68,10 +68,10 @@ module Compass
|
|||||||
end
|
end
|
||||||
unless @callbacks_loaded
|
unless @callbacks_loaded
|
||||||
Sass::Plugin.on_updating_stylesheet do |sass_file, css_file|
|
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
|
end
|
||||||
Sass::Plugin.on_compilation_error do |e, filename, css|
|
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
|
end
|
||||||
@callbacks_loaded = true
|
@callbacks_loaded = true
|
||||||
end
|
end
|
||||||
|
@ -61,6 +61,19 @@ module Compass
|
|||||||
inherited_writer(*attributes)
|
inherited_writer(*attributes)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ module Compass
|
|||||||
cleanup_old_sprites
|
cleanup_old_sprites
|
||||||
end
|
end
|
||||||
engine.construct_sprite
|
engine.construct_sprite
|
||||||
Compass.configuration.run_callback(:sprite_generated, engine.canvas)
|
Compass.configuration.run_sprite_generated(engine.canvas)
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -89,7 +89,7 @@ module Compass
|
|||||||
def save!
|
def save!
|
||||||
FileUtils.mkdir_p(File.dirname(filename))
|
FileUtils.mkdir_p(File.dirname(filename))
|
||||||
saved = engine.save(filename)
|
saved = engine.save(filename)
|
||||||
Compass.configuration.run_callback(:sprite_saved, filename)
|
Compass.configuration.run_sprite_saved(filename)
|
||||||
saved
|
saved
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user