Class: Forme::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/forme/input.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, type, opts = {}) ⇒ Input

Set the form, type, and opts.


20
21
22
23
24
25
# 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

Instance Attribute Details

#formObject (readonly)

The Form object related to the receiver.


8
9
10
# File 'lib/forme/input.rb', line 8

def form
  @form
end

#form_optsObject (readonly)

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


17
18
19
# File 'lib/forme/input.rb', line 17

def form_opts
  @form_opts
end

#optsObject (readonly)

The options hash for the Input.


14
15
16
# File 'lib/forme/input.rb', line 14

def opts
  @opts
end

#typeObject (readonly)

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


11
12
13
# File 'lib/forme/input.rb', line 11

def type
  @type
end

Instance Method Details

#formatObject

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


40
41
42
# File 'lib/forme/input.rb', line 40

def format
  Forme.transform(:formatter, @opts, @form_opts, self)
end

#tag(*a, &block) ⇒ Object

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


29
30
31
# File 'lib/forme/input.rb', line 29

def tag(*a, &block)
  form._tag(*a, &block)
end

#to_sObject

Return a string containing the serialized content of the receiver.


34
35
36
# File 'lib/forme/input.rb', line 34

def to_s
  form.raw_output(Forme.transform(:serializer, @opts, @form_opts, self))
end