module Haml::Filters::Base
def compile(compiler, text)
-
(Haml::Error)
- if none of \{#compile}, \{#render}, and
Parameters:
-
text
(String
) -- The text of the filter -
compiler
(Haml::Compiler
) -- The compiler instance
def compile(compiler, text) filter = self compiler.instance_eval do if contains_interpolation?(text) return if options[:suppress_eval] escape = options[:escape_filter_interpolations] # `escape_filter_interpolations` defaults to `escape_html` if unset. escape = options[:escape_html] if escape.nil? text = unescape_interpolation(text, escape).gsub(/(\\+)n/) do |s| escapes = $1.size next s if escapes % 2 == 0 "#{'\\' * (escapes - 1)}\n" end # We need to add a newline at the beginning to get the # filter lines to line up (since the Haml filter contains # a line that doesn't show up in the source, namely the # filter name). Then we need to escape the trailing # newline so that the whole filter block doesn't take up # too many. text = %[\n#{text.sub(/\n"\Z/, "\\n\"")}] push_script <<RUBY.rstrip, :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.to_s, compiler.options), compiler.options[:preserve]) push_text("#{rendered.rstrip}\n") end end