Method: Forme::Form.form
- Defined in:
- lib/forme/form.rb
.form(obj = nil, attr = {}, opts = {}, &block) ⇒ Object
Create a Form instance 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
Formobject with no options and not associated to anobj, and with no attributes in the opening tag. - 1 hash arg
-
Treated as opening form tag attributes, creating a
Formobject with no options. - 1 non-hash arg
-
Treated as the
Form‘sobj, with empty options and no attributes in the opening tag. - 2 hash args
-
First hash is opening attributes, second hash is
Formoptions. - 1 non-hash arg, 1-2 hash args
-
First argument is
Form‘s obj, second is opening attributes, third if provided isForm’s options.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/forme/form.rb', line 49 def self.form(obj=nil, attr={}, opts={}, &block) f = if obj.is_a?(Hash) raise Error, "Can't provide 3 hash arguments to form" unless opts.empty? opts = attr attr = obj new(opts) else new(obj, opts) end ins = opts[:inputs] = opts[:button] if ins || block = Proc.new do |form| form._inputs(ins, opts) if ins yield form if block_given? form.emit(form.()) if end end f.form(attr, &block) end |