class Docks::Renderers::ERB
Public Class Methods
new()
click to toggle source
Calls superclass method
Docks::Renderers::Base::new
# File lib/docks/renderers/erb_renderer.rb, line 11 def initialize require "erb" super @locals = [] @output = "" end
Public Instance Methods
capture(*args) { |*args| ... }
click to toggle source
# File lib/docks/renderers/erb_renderer.rb, line 41 def capture(*args, &block) old_output, @output = @output, "" yield *args content = @output @output = old_output content end
concat(content)
click to toggle source
# File lib/docks/renderers/erb_renderer.rb, line 49 def concat(content) @output << content end
get_binding()
click to toggle source
# File lib/docks/renderers/erb_renderer.rb, line 37 def get_binding binding end
method_missing(meth, *arguments, &block)
click to toggle source
Calls superclass method
# File lib/docks/renderers/erb_renderer.rb, line 53 def method_missing(meth, *arguments, &block) super if @locals.empty? @locals.last.fetch(meth) rescue KeyError super end
render(template, locals = {})
click to toggle source
# 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
Private Instance Methods
clean()
click to toggle source
Calls superclass method
Docks::Renderers::Base#clean
# File lib/docks/renderers/erb_renderer.rb, line 62 def clean super @locals = [] end