class Trestle::Form::Renderer

Constants

RAW_BLOCK_HELPERS

Raw block helpers will pass their block argument directly to the method without wrapping it in a new output buffer.

WHITELISTED_HELPERS

Whitelisted helpers will concatenate their result to the output buffer when called.

Public Class Methods

new(template, form=nil) click to toggle source
# File lib/trestle/form/renderer.rb, line 25
def initialize(template, form=nil)
  @template = template
  @form = form || @template.form
end

Public Instance Methods

fields_for(*args, &block) click to toggle source
# File lib/trestle/form/renderer.rb, line 34
def fields_for(*args, &block)
  result = @form.fields_for(*args) do |f|
    renderer = self.class.new(@template, f)
    renderer.render_form(f, &block)
  end

  concat(result)
end
method_missing(name, *args, &block) click to toggle source
# File lib/trestle/form/renderer.rb, line 43
def method_missing(name, *args, &block)
  target = @form.respond_to?(name) ? @form : @template

  if block_given? && !RAW_BLOCK_HELPERS.include?(name)
    result = target.send(name, *args) do |*blockargs|
      render_form(*blockargs, &block)
    end
  else
    result = target.send(name, *args, &block)
  end

  if target == @form || WHITELISTED_HELPERS.include?(name)
    concat(result)
  else
    result
  end
end
render_form(*args, &block) click to toggle source
# File lib/trestle/form/renderer.rb, line 30
def render_form(*args, &block)
  capture { instance_exec(*args, &block).to_s }
end
respond_to_missing?(name, include_all=false) click to toggle source
Calls superclass method
# File lib/trestle/form/renderer.rb, line 61
def respond_to_missing?(name, include_all=false)
  @form.respond_to?(name, include_all) ||
    @template.respond_to?(name, include_all) ||
    super
end