Class: Forme::Formatter
- Inherits:
-
Object
- Object
- Forme::Formatter
- Defined in:
- lib/forme.rb
Overview
The default formatter used by the library. Any custom formatters should probably inherit from this formatter unless they have very special needs.
Unlike most other transformers which are registered as instances and use a functional style, this class is registered as a class due to the large amount of state it uses.
Registered as :default.
Defined Under Namespace
Constant Summary collapse
- ATTRIBUTE_OPTIONS =
These options are copied directly from the options hash to the the attributes hash, so they don’t need to be specified in the :attr option. However, they can be specified in both places, and if so, the :attr option version takes precedence.
[:name, :id, :placeholder, :value]
- CHECKBOX_MAP =
Used to specify the value of the hidden input created for checkboxes. Since the default for an unspecified checkbox value is 1, the default is
-
If the checkbox value is ‘t’, the hidden value is ‘f’, since that is
common usage for boolean values.
-
Hash.new(0)
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
The attributes to to set on the lower level
Tag
form returned. -
#form ⇒ Object
readonly
The
Form
instance for the receiver, taken from theinput
. -
#input ⇒ Object
readonly
The
Input
instance for the receiver. -
#opts ⇒ Object
readonly
The
opts
hash of theinput
.
Class Method Summary collapse
-
.call(input) ⇒ Object
Create a new instance and call it.
Instance Method Summary collapse
-
#call(input) ⇒ Object
Transform the
input
into aTag
instance (or an array of them), wrapping it with theform
‘s wrapper, and the form’serror_handler
andlabeler
if theinput
has an:error
or:label
options.
Instance Attribute Details
#attr ⇒ Object (readonly)
The attributes to to set on the lower level Tag
form returned. This are derived from the input
‘s opts
, but some processing is done on them.
605 606 607 |
# File 'lib/forme.rb', line 605 def attr @attr end |
#form ⇒ Object (readonly)
The Form
instance for the receiver, taken from the input
.
596 597 598 |
# File 'lib/forme.rb', line 596 def form @form end |
#input ⇒ Object (readonly)
The Input
instance for the receiver. This is what the receiver converts to the lower level Tag
form (or an array of them).
600 601 602 |
# File 'lib/forme.rb', line 600 def input @input end |
#opts ⇒ Object (readonly)
The opts
hash of the input
.
608 609 610 |
# File 'lib/forme.rb', line 608 def opts @opts end |
Class Method Details
.call(input) ⇒ Object
Create a new instance and call it
591 592 593 |
# File 'lib/forme.rb', line 591 def self.call(input) new.call(input) end |
Instance Method Details
#call(input) ⇒ Object
Transform the input
into a Tag
instance (or an array of them), wrapping it with the form
‘s wrapper, and the form’s error_handler
and labeler
if the input
has an :error
or :label
options.
621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'lib/forme.rb', line 621 def call(input) @input = input @form = input.form attr = input.opts[:attr] @attr = attr ? attr.dup : {} @opts = input.opts tag = convert_to_tag(input.type) tag = wrap_tag_with_label(tag) if input.opts[:label] tag = wrap_tag_with_error(tag) if input.opts[:error] wrap_tag(tag) end |