Class: Campo::Form

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

Constant Summary collapse

DEFAULT =
{ method: "POST" }

Instance Attribute Summary

Attributes inherited from Base

#attributes, #attributes The element's html attributes., #fields, #fields The element's child elements.

Attributes included from Childish

#parent

Instance Method Summary collapse

Methods inherited from Base

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

Methods included from Convenience

#bit_of_ruby, #checkbox, #fieldset, #hidden, #input, #literal, #password, #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"


442
443
444
445
446
447
# File 'lib/campo/campo.rb', line 442

def initialize(name,  attributes={} )
  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
end