Module: Haml::Filters

### Home Classes Methods

### In Files

- lib/haml/filters.rb
- lib/haml/sass_rails_filter.rb

### Namespace

- MODULE Haml::Filters::Base
- MODULE Haml::Filters::Cdata
- MODULE Haml::Filters::Css
- MODULE Haml::Filters::Erb
- MODULE Haml::Filters::Escaped
- MODULE Haml::Filters::Javascript
- MODULE Haml::Filters::Plain
- MODULE Haml::Filters::PrecompiledTiltFilter
- MODULE Haml::Filters::Preserve
- MODULE Haml::Filters::Ruby
- MODULE Haml::Filters::TiltFilter
- CLASS Haml::Filters::SassRailsTemplate
- CLASS Haml::Filters::ScssRailsTemplate

### Methods

- #register_tilt_filter
- #remove_filter

### Class/Module Index

Quicksearch

- Haml
- Haml::Buffer
- Haml::Compiler
- Haml::Engine
- Haml::Error
- Haml::ErubisTemplateHandler
- Haml::Exec
- Haml::Exec::Generic
- Haml::Exec::Haml
- Haml::Filters
- Haml::Filters::Base
- Haml::Filters::Cdata
- Haml::Filters::Css
- Haml::Filters::Erb
- Haml::Filters::Escaped
- Haml::Filters::Javascript
- Haml::Filters::Plain
- Haml::Filters::PrecompiledTiltFilter
- Haml::Filters::Preserve
- Haml::Filters::Ruby
- Haml::Filters::SassRailsTemplate
- Haml::Filters::ScssRailsTemplate
- Haml::Filters::TiltFilter
- Haml::Helpers
- Haml::Helpers::ActionViewExtensions
- Haml::Helpers::ErrorReturn
- Haml::Helpers::XssMods
- Haml::Options
- Haml::Parser
- Haml::Parser::Line
- Haml::Parser::ParseNode
- Haml::Plugin
- Haml::Railtie
- Haml::SafeErubisTemplate
- Haml::SyntaxError
- Haml::Template
- Haml::Util
- Haml::Util::StaticConditionalContext
- ActionView
- ActionView::Base
- ActionView::Helpers
- ActionView::Helpers::CaptureHelper
- ActionView::Helpers::FormHelper
- ActionView::Helpers::FormTagHelper
- ActionView::Helpers::HamlSupport
- ActionView::Helpers::InstanceTag
- ActionView::Helpers::TagHelper
- ActionView::Helpers::Tags
- ActionView::Helpers::Tags::TextArea
- ActionView::Helpers::TextHelper
- Object

No matching classes.

# Haml::Filters

The module containing the default Haml filters, as well as the base module, {Haml::Filters::Base}.

@see Haml::Filters::Base

### Attributes

defined[R]

@return [{String => Haml::Filters::Base}] a hash mapping filter names to

    classes.

### Public Instance Methods

register_tilt_filter(name, options = {}) click to toggle source

Loads an external template engine from [Tilt](github.com/rtomayko/tilt) as a filter. This method is used internally by Haml to set up filters for Sass, SCSS, Less, Coffeescript, and others. It's left public to make it easy for developers to add their own Tilt-based filters if they choose.

@return [Module] The generated filter. @param [Hash] options Options for generating the filter module. @option options [Boolean] :precompiled Whether the filter should be

    precompiled. Erb, Nokogiri and Builder use this, for example.

@option options [Class] :template_class The Tilt template class to use,

    in the event it can't be inferred from an extension.

@option options [String] :extension The extension associated with the

    content, for example "markdown". This lets Tilt choose the preferred
    engine when there are more than one.

@option options [String,Array<String>] :alias Any aliases for the filter.

    For example, :coffee is also available as :coffeescript.

@option options [String] :extend The name of a module to extend when

    defining the filter. Defaults to "Plain". This allows filters such as
    Coffee to "inherit" from Javascript, wrapping its output in script tags.

@since 4.0

    # File lib/haml/filters.rb, line 38
    def register_tilt_filter(name, options = {})
      if constants.map(&:to_s).include?(name.to_s)
        raise "#{name} filter already defined"
      end

      filter = const_set(name, Module.new)
      filter.extend const_get(options[:extend] || "Plain")
      filter.extend TiltFilter
      filter.extend PrecompiledTiltFilter if options.has_key? :precompiled

      if options.has_key? :template_class
        filter.template_class = options[:template_class]
      else
        filter.tilt_extension = options.fetch(:extension) { name.downcase }
      end

      # All ":coffeescript" as alias for ":coffee", etc.
      if options.has_key?(:alias)
        [options[:alias]].flatten.each {|x| Filters.defined[x.to_s] = filter}
      end
      filter
    end

remove_filter(name) click to toggle source

Removes a filter from Haml. If the filter was removed, it returns the that was remove Module upon success, or nil on failure. If you try to redefine a filter, Haml will raise an error. Use this method first to explicitly remove the filter before redefining it. @return Module The filter module that has been removed @since 4.0

    # File lib/haml/filters.rb, line 67
    def remove_filter(name)
      defined.delete name.to_s.downcase
      if constants.map(&:to_s).include?(name.to_s)
        remove_const name.to_sym
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.