class Haml::Engine
def render(scope = Object.new, locals = {}, &block)
but if you're relying on local variables defined in the context of scope,
This won't have an effect in most cases,
In particular, it's equivalent to passing eval("self", scope) as scope.
the evaluation context may not be quite what the user expects.
if scope is a Binding or Proc object and a block is given,
Due to some Ruby quirks,
within the template.
that block is run when +yield+ is called
If a block is passed to render,
Haml::Engine.new("%p= foo").render(Object.new, :foo => "Hello, world!") #=> "
Hello, world!
"For example:
+locals+ is a hash of local variables to make available to the template.
s.responds_to?(:html_attrs) #=> true
# s now extends Haml::Helpers
Haml::Engine.new("%p= upcase").render(s) #=> "
FOOBAR
"s = "foobar"
For example:
(all prefixed with "haml").
It extends Haml::Helpers, and various instance variables are set
(either the scope object or the "self" object of the scope binding).
Note that Haml modifies the evaluation context
otherwise, Haml just uses its #instance_eval context.
Haml uses it as the second argument to Kernel#eval;
If it's a Binding or Proc object,
+scope+ is the context in which the template is evaluated.
Processes the template and returns the result as a string.
def render(scope = Object.new, locals = {}, &block) buffer = Haml::Buffer.new(scope.instance_variable_get('@haml_buffer'), 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 eval(@precompiled, scope, @options[:filename], @options[:line]) # Get rid of the current buffer scope_object.instance_eval do @haml_buffer = buffer.upper end buffer.buffer end