module Haml::Filters::Base

The base module for Haml filters. User-defined filters should be modules including this module. The name of the filter is taken by downcasing the module name. For instance, if the module is named ‘FooBar`, the filter will be `:foobar`.

A user-defined filter should override either {#render} or {#compile}. {#render} is the most common. It takes a string, the filter source, and returns another string, the result of the filter. For example, the following will define a filter named ‘:sass`:

module Haml::Filters::Sass
  include Haml::Filters::Base

  def render(text)
    ::Sass::Engine.new(text).render
  end
end

For details on overriding {#compile}, see its documentation.

Note that filters overriding {#render} automatically support ‘#{}` for interpolating Ruby code. Those overriding {#compile} will need to add such support manually if it’s desired.