class Forme::Input

  1. lib/forme/input.rb
Superclass: Object

High level abstract tag form, transformed by formatters into the lower level Tag form (or an array of them).

Methods

Public Class

  1. new

Public Instance

  1. form
  2. form_opts
  3. format
  4. merge_opts
  5. opts
  6. tag
  7. to_s
  8. type

Attributes

form [R]

The Form object related to the receiver.

form_opts [R]

The options hash in use by the form at the time of the Input's instantiation.

opts [R]

The options hash for the Input.

type [R]

The type of input, should be a symbol (e.g. :submit, :text, :select).

Public Class methods

new (form, type, opts={})

Set the form, type, and opts.

[show source]
# File lib/forme/input.rb, line 20
def initialize(form, type, opts={})
  @form, @type = form, type
  defaults = form.input_defaults
  @opts = (defaults.fetch(type){defaults[type.to_s]} || {}).merge(opts)
  @form_opts = form.opts
end

Public Instance methods

format ()

Transform the receiver into a lower level Tag form (or an array of them).

[show source]
# File lib/forme/input.rb, line 46
def format
  Forme.transform(:formatter, @opts, @form_opts, self)
end
merge_opts (hash)

Replace the opts by merging the given hash into opts, without modifying opts.

[show source]
# File lib/forme/input.rb, line 29
def merge_opts(hash)
  @opts = @opts.merge(hash)
end
tag (*a, &block)

Create a new Tag instance with the given arguments and block related to the receiver's form.

[show source]
# File lib/forme/input.rb, line 35
def tag(*a, &block)
  form._tag(*a, &block)
end
to_s ()

Return a string containing the serialized content of the receiver.

[show source]
# File lib/forme/input.rb, line 40
def to_s
  form.raw_output(Forme.transform(:serializer, @opts, @form_opts, self))
end