class Haml::Engine

def render(scope = Object.new, locals = {}, &block)

Returns:
  • (String) - The rendered template

Parameters:
  • block (#to_proc) -- A block that can be yielded to within the template
  • locals ({Symbol => Object}) -- Local variables that will be made available
  • scope (Binding, Proc, Object) -- The context in which the template is evaluated
def render(scope = Object.new, locals = {}, &block)
  parent = scope.instance_variable_defined?('@haml_buffer') ? scope.instance_variable_get('@haml_buffer') : nil
  buffer = Haml::Buffer.new(parent, @options.for_buffer)
  if scope.is_a?(Binding) || scope.is_a?(Proc)
    scope_object = eval("self", scope)
    scope = scope_object.instance_eval{binding} if block_given?
  else
    scope_object = scope
    scope = scope_object.instance_eval{binding}
  end
  set_locals(locals.merge(:_hamlout => buffer, :_erbout => buffer.buffer), scope, scope_object)
  scope_object.instance_eval do
    extend Haml::Helpers
    @haml_buffer = buffer
  end
  begin
    eval(@compiler.precompiled_with_return_value, scope, @options[:filename], @options[:line])
  rescue ::SyntaxError => e
    raise SyntaxError, e.message
  end
ensure
  # Get rid of the current buffer
  scope_object.instance_eval do
    @haml_buffer = buffer.upper if buffer
  end
end