module Haml::Filters::Base
def self.included(base)
-
base
(Module, Class
) -- The module that this is included in
def self.included(base) Filters.defined[base.name.split("::").last.downcase] = base base.extend(base) end
def compile(precompiler, text)
-
(Haml::Error)
- if none of \{#compile}, \{#render}, and \{#render_with_options} are overridden
Parameters:
-
text
(String
) -- The text of the filter -
precompiler
(Haml::Precompiler
) -- The precompiler instance
def compile(precompiler, text) resolve_lazy_requires filter = self precompiler.instance_eval do if contains_interpolation?(text) return if options[:suppress_eval] text = unescape_interpolation(text).gsub(/(\\+)n/) do |s| escapes = $1.size next s if escapes % 2 == 0 ("\\" * (escapes - 1)) + "\n" end newline if text.gsub!(/\n"\Z/, "\\n\"") push_script <<RUBY.strip, :escape_html => false nd_preserve(#{filter.inspect}.render_with_options(#{text}, _hamlout.options)) return end rendered = Haml::Helpers::find_and_preserve(filter.render_with_options(text, precompiler.options), precompiler.options[:preserve]) if !options[:ugly] push_text(rendered.rstrip.gsub("\n", "\n#{' ' * @output_tabs}")) else push_text(rendered.rstrip) end (text.count("\n") - 1).times {newline} resolve_newlines newline end end
def internal_compile(*args)
- See: #compile -
def internal_compile(*args) resolve_lazy_requires compile(*args) end
def lazy_require(*reqs)
-
reqs
(Array
) -- The requires to run
def lazy_require(*reqs) @lazy_requires = reqs end
def render(text)
-
(Haml::Error)
- if it's not overridden
Returns:
-
(String)
- The filtered result
Parameters:
-
text
(String
) -- The source text for the filter to process
def render(text) raise Error.new("#{self.inspect}#render not defined!") end
def render_with_options(text, options)
-
(Haml::Error)
- if it or \{#render} isn't overridden
Returns:
-
(String)
- The filtered result
Parameters:
-
text
(String
) -- The source text for the filter to process
Other tags:
- See: #render -
def render_with_options(text, options) render(text) end
def resolve_lazy_requires
def resolve_lazy_requires return unless @lazy_requires @lazy_requires[0...-1].each do |req| begin @required = req require @required return rescue LoadError; end # RCov doesn't see this, but it is run end begin @required = @lazy_requires[-1] require @required rescue LoadError => e classname = self.name.match(/\w+$/)[0] if @lazy_requires.size == 1 raise Error.new("Can't run #{classname} filter; required file '#{@lazy_requires.first}' not found") else raise Error.new("Can't run #{classname} filter; required #{@lazy_requires.map { |r| "'#{r}'" }.join(' or ')}, but none were found") end end end