module Haml::Helpers
def self.action_view?
def self.action_view? @@action_view_defined end
def capture_haml(*args, &block)
the local variable foo would be assigned to "
13
\n".%p= a
- foo = capture_haml(13) do |a|
.foo
For example, after the following,
and returns it as a string.
gets rid of the excess indentation,
Captures the result of the given block of Haml code,
def capture_haml(*args, &block) capture_haml_with_buffer(haml_buffer.buffer, *args, &block) end
def capture_haml_with_buffer(local_buffer, *args, &block)
Performs the function of capture_haml, assuming local_buffer
def capture_haml_with_buffer(local_buffer, *args, &block) position = local_buffer.length block.call *args captured = local_buffer.slice!(position..-1) min_tabs = nil captured.each do |line| tabs = line.index(/[^ ]/) min_tabs ||= tabs min_tabs = min_tabs > tabs ? tabs : min_tabs end result = captured.map do |line| line[min_tabs..-1] end result.to_s end
def escape_once(text)
Escapes HTML entities in text, but without escaping an ampersand
def escape_once(text) text.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |s| HTML_ESCAPE[s] } end
def find_and_preserve(input = '', tags = haml_buffer.options[:preserve], &block)
@tags@ is an array of tags to preserve.
into the HTML entities for endlines.
Uses preserve to convert any newlines inside whitespace-sensitive tags
find_and_preserve {...}
find_and_preserve(input, tags = haml_buffer.options[:preserve])
call-seq:
def find_and_preserve(input = '', tags = haml_buffer.options[:preserve], &block) return find_and_preserve(capture_haml(&block)) if block input = input.to_s input.gsub(/<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im) do "<#{$1}#{$2}>#{preserve($3)}</#{$1}>" end end
def haml_bind_proc(&proc)
Gives a proc the same local "_hamlout" and "_erbout" variables
def haml_bind_proc(&proc) _hamlout = haml_buffer _erbout = _hamlout.buffer proc { |*args| proc.call(*args) } end
def haml_buffer
def haml_buffer @haml_buffer end
def haml_tag(name, *rest, &block)
more_data
data
strong!