Module: Haml::Filters
- Extended by:
- Filters
- Included in:
- Filters
- Defined in:
- lib/haml/filters.rb,
lib/haml/sass_rails_filter.rb
Overview
The module containing the default Haml filters, as well as the base module, Base.
Defined Under Namespace
Modules: Base, Cdata, Coffee, Css, Erb, Escaped, Javascript, Less, Markdown, Plain, Preserve, Ruby, Sass, Scss Classes: SassRailsTemplate, ScssRailsTemplate
Instance Attribute Summary collapse
-
#defined ⇒ {String => Haml::Filters::Base}
readonly
A hash mapping filter names to classes.
Instance Method Summary collapse
-
#register_tilt_filter(name, options = {}) ⇒ Module
Loads an external template engine from Tilt as a filter.
-
#remove_filter(name)
Removes a filter from Haml.
Instance Attribute Details
#defined ⇒ {String => Haml::Filters::Base} (readonly)
Returns a hash mapping filter names to classes.
16 17 18 |
# File 'lib/haml/filters.rb', line 16
def defined
@defined
end
|
Instance Method Details
#register_tilt_filter(name, options = {}) ⇒ Module
Loads an external template engine from 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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/haml/filters.rb', line 40
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)
Removes a filter from Haml. If the filter was removed, it returns the Module that was removed 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.
69 70 71 72 73 74 |
# File 'lib/haml/filters.rb', line 69
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
|