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.



110
111
112
113
114
115
116
117
118
# File 'lib/forme/sinatra.rb', line 110

def form(obj=nil, attr={}, opts={}, &block)
  if block
    h = {:output=>@_out_buf, :hidden_tags=>Forme::Sinatra::HIDDEN_TAGS, :env=>env}
    (obj.is_a?(Hash) ? attr = attr.merge(h) : opts = opts.merge(h))
    Form.form(obj, attr, opts, &block)
  else
    Form.form(obj, attr, opts)
  end
end