Class: Forme::Input
- Inherits:
-
Object
- Object
- Forme::Input
- 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
-
#form ⇒ Object
readonly
The
Form
object related to the receiver. -
#form_opts ⇒ Object
readonly
The options hash in use by the form at the time of the Input’s instantiation.
-
#opts ⇒ Object
readonly
The options hash for the Input.
-
#type ⇒ Object
readonly
The type of input, should be a symbol (e.g. :submit, :text, :select).
Instance Method Summary collapse
-
#format ⇒ Object
Transform the receiver into a lower level
Tag
form (or an array of them). -
#initialize(form, type, opts = {}) ⇒ Input
constructor
Set the
form
,type
, andopts
. -
#merge_opts(hash) ⇒ Object
Replace the
opts
by merging the givenhash
intoopts
, without modifyingopts
. -
#tag(*a, &block) ⇒ Object
Create a new
Tag
instance with the given arguments and block related to the receiver’sform
. -
#to_s ⇒ Object
Return a string containing the serialized content of the receiver.
Constructor Details
#initialize(form, type, opts = {}) ⇒ Input
Set the form
, type
, and opts
.
18 19 20 21 22 23 |
# File 'lib/forme/input.rb', line 18 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
#form ⇒ Object (readonly)
The Form
object related to the receiver.
6 7 8 |
# File 'lib/forme/input.rb', line 6 def form @form end |
#form_opts ⇒ Object (readonly)
The options hash in use by the form at the time of the Input’s instantiation.
15 16 17 |
# File 'lib/forme/input.rb', line 15 def form_opts @form_opts end |
#opts ⇒ Object (readonly)
The options hash for the Input.
12 13 14 |
# File 'lib/forme/input.rb', line 12 def opts @opts end |
#type ⇒ Object (readonly)
The type of input, should be a symbol (e.g. :submit, :text, :select).
9 10 11 |
# File 'lib/forme/input.rb', line 9 def type @type end |
Instance Method Details
#format ⇒ Object
Transform the receiver into a lower level Tag
form (or an array of them).
44 45 46 |
# File 'lib/forme/input.rb', line 44 def format Forme.transform(:formatter, @opts, @form_opts, self) end |
#merge_opts(hash) ⇒ Object
Replace the opts
by merging the given hash
into opts
, without modifying opts
.
27 28 29 |
# File 'lib/forme/input.rb', line 27 def merge_opts(hash) @opts = @opts.merge(hash) end |
#tag(*a, &block) ⇒ Object
Create a new Tag
instance with the given arguments and block related to the receiver’s form
.
33 34 35 |
# File 'lib/forme/input.rb', line 33 def tag(*a, &block) form._tag(*a, &block) end |