Class: Campo::Form

Inherits:
Base
  • Object
show all
Defined in:
lib/campo.rb

Constant Summary collapse

DEFAULT =
{ method: "POST" }

Instance Attribute Summary

Attributes inherited from Base

#attributes, #fields

Attributes included from Childish

#parent

Instance Method Summary collapse

Methods inherited from Base

#labelled, #on_output, #output, output, quotable, unhash

Methods included from Convenience

#bit_of_ruby, #checkbox, #fieldset, #input, #literal, #radio, #select, #submit, #text, #textarea

Methods included from Iding

#id_tag

Methods included from Childish

#push=

Constructor Details

#initialize(name, attributes = {}) ⇒ Form

Returns a new instance of Form.

Examples:

form = Campo::Form.new "example", "/path/to/post/to/" do |form|
  form.text "first_field"
  #... more fields follow
end

Parameters:

  • name (String)

    The form’s name (html) attribute.

  • attributes (optional, Hash) (defaults to: {})

    Html attributes. They can be anything you like. Defaults follow:

Options Hash (attributes):

  • :method (String) — default: "POST"


280
281
282
283
284
285
286
287
288
# File 'lib/campo.rb', line 280

def initialize(name,  attributes={} )
  attributes[:id] = name.gsub(/\W/, "_") if attributes[:id].nil?
  super( name, DEFAULT.merge( attributes ) )
  self.on_output do |n=0, tab=2|
    %Q!#{" " * n * tab}%form{ atts[:#{name.gsub(/\W/, "_").downcase}], #{Base.unhash( @attributes )} }!
  end
  
  self
end