module Haml::Helpers
def capture_haml(*args, &block)
- Yieldparam: args - `args`
Other tags:
- Yield: - A block of Haml code that will be converted to a string
Parameters:
-
args
(Array
) -- Arguments to pass into the block
def capture_haml(*args, &block) buffer = eval('if defined? _hamlout then _hamlout else nil end', block.binding) || haml_buffer with_haml_buffer(buffer) do position = haml_buffer.buffer.length haml_buffer.capture_position = position block.call(*args) captured = haml_buffer.buffer.slice!(position..-1) return captured if haml_buffer.options[:ugly] # Note that the "reject" is needed for rbx 1.2.4, which includes empty # strings in the returned array when splitting by /^/. captured = captured.split(/^/).reject {|x| x == ""} min_tabs = nil captured.each do |line| tabs = line.index(/[^ ]/) || line.length min_tabs ||= tabs min_tabs = min_tabs > tabs ? tabs : min_tabs end captured.map do |line| line[min_tabs..-1] end.join end ensure haml_buffer.capture_position = nil end