Module: Sass::Callbacks
- Included in:
- Plugin::Compiler
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/callbacks.rb
Overview
A lightweight infrastructure for defining and running callbacks. Callbacks are defined using #define_callback at the class level, and called using run_#{name}
at the instance level.
Clients can add callbacks by calling the generated on_#{name}
method, and passing in a block that’s run when the callback is activated.
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary (collapse)
- + extended(base)
Automatically includes InstanceMethods when something extends this module.
Instance Method Summary (collapse)
- - define_callback(name) protected
Define a callback with the given name.
Class Method Details
+ extended(base)
Automatically includes InstanceMethods when something extends this module.
30 31 32 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/callbacks.rb', line 30
def self.extended(base)
base.send(:include, InstanceMethods)
end |
Instance Method Details
- define_callback(name) (protected)
This method returns an undefined value.
Define a callback with the given name. This will define an on_#{name}
method that registers a block, and a run_#{name}
method that runs that block (optionall with some arguments).
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/callbacks.rb', line 51
def define_callback(name)
class_eval <<RUBY, __FILE__, __LINE__ + 1
def on_#{name}(&block)
@_sass_callbacks = {} unless defined? @_sass_callbacks
(@_sass_callbacks[#{name.inspect}] ||= []) << block
end
def run_#{name}(*args)
return unless defined? @_sass_callbacks
return unless @_sass_callbacks[#{name.inspect}]
@_sass_callbacks[#{name.inspect}].each {|c| c[*args]}
end
private :run_#{name}
RUBY
end |