Module: Forme::Sinatra::ERB

Defined in:
lib/forme/sinatra.rb

Overview

This is the module used to add the Forme integration to Sinatra. It should be enabled in Sinatra with the following code in your Sinatra::Base subclass:

helpers Forme::Sinatra::ERB

Instance Method Summary collapse

Instance Method Details

#form(obj = nil, attr = {}, opts = {}, &block) ⇒ Object

Create a Form object and yield it to the block, injecting the opening form tag before yielding and the closing form tag after yielding.

Argument Handling:

No args

Creates a Form object with no options and not associated to an obj, and with no attributes in the opening tag.

1 hash arg

Treated as opening form tag attributes, creating a Form object with no options.

1 non-hash arg

Treated as the Form‘s obj, with empty options and no attributes in the opening tag.

2 hash args

First hash is opening attributes, second hash is Form options.

1 non-hash arg, 1-2 hash args

First argument is Form‘s obj, second is opening attributes, third if provided is Form’s options.



79
80
81
82
83
# File 'lib/forme/sinatra.rb', line 79

def form(obj=nil, attr={}, opts={}, &block)
  h = {:output=>@_out_buf}
  (obj.is_a?(Hash) ? attr = attr.merge(h) : opts = opts.merge(h))
  Form.form(obj, attr, opts, &block)
end