Method: Docks::Renderers::ERB#render

Defined in:
lib/docks/renderers/erb_renderer.rb

#render(template, locals = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/docks/renderers/erb_renderer.rb', line 19

def render(template, locals = {})
  first_pass = @output.length < 1
  final_output, @output = @output, ""

  content, layout, locals = normalize_content_and_locals(template, locals)
  return if content.nil?

  @locals << locals
  content = ::ERB.new(content, nil, nil, "@output").result(get_binding)
  return content if layout.nil?

  ::ERB.new(layout, nil, nil, "@output").result(get_binding { |name| name.nil? ? content : @content_blocks[name] })

ensure
  @locals.pop
  @output = first_pass ? "" : final_output
end