class Forme::ERB::Form

  1. lib/forme/erb.rb
Superclass: Form

Subclass used when using Forme ERB integration. Handles integrating into the view template so that methods with blocks can inject strings into the output.

Methods

Public Class

  1. new

Public Instance

  1. emit
  2. form
  3. inputs
  4. output
  5. tag

Attributes

output [R]

Template output object, where serialized output gets injected.

Public Class methods

new (*)

Set the template output object when initializing.

[show source]
# File lib/forme/erb.rb, line 32
def initialize(*)
  super
  @output = @opts[:output] ? @opts[:output] : String.new
end

Public Instance methods

emit (tag)

Serialize the tag and inject it into the output.

[show source]
# File lib/forme/erb.rb, line 38
def emit(tag)
  output << tag.to_s
end
form (*a, &block)

Capture the inside of the form, injecting it into the template if a block is given, or returning it as a string if not.

[show source]
# File lib/forme/erb.rb, line 54
def form(*a, &block)
  if block
    capture(block){super}
  else
    super
  end
end
inputs (*a, &block)

Capture the inside of the inputs, injecting it into the template if a block is given, or returning it as a string if not.

[show source]
# File lib/forme/erb.rb, line 44
def inputs(*a, &block)
  if block
    capture(block){super}
  else
    capture{super}
  end
end
tag (type, attr={}, children=[], &block)

If a block is given, inject an opening tag into the output, inject any given children into the output, yield to the block, inject a closing tag into the output. If a block is not given, just return the tag created.

[show source]
# File lib/forme/erb.rb, line 66
def tag(type, attr={}, children=[], &block)
  tag = _tag(type, attr, children)
  if block
    capture(block) do
      emit(serialize_open(tag))
      Array(tag.children).each{|c| emit(c)}
      yield self
      emit(serialize_close(tag))
    end
  else
    tag
  end
end