module Sass::Callbacks

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.

@example Define a callback

class Munger
  extend Sass::Callbacks
  define_callback :string_munged

  def munge(str)
    res = str.gsub(/[a-z]/, '\1\1')
    run_string_munged str, res
    res
  end
end

@example Use a callback

m = Munger.new
m.on_string_munged {|str, res| puts "#{str} was munged into #{res}!"}
m.munge "bar" #=> bar was munged into bbaarr!