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.
Classes and Modules
Constants
ATTRIBUTE_BOOLEAN_OPTIONS | = | [:autofocus, :required, :disabled] |
Options copied from the options hash into the attributes hash, where a true value in the options hash sets the attribute value to the same name as the key. |
|
ATTRIBUTE_OPTIONS | = | [:name, :id, :placeholder, :value, :style] |
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. |
|
CHECKBOX_MAP | = | Hash.new(0) |
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
common usage for boolean values. |
|
DATE_SELECT_FORMAT | = | '%02i'.freeze | ||
DEFAULT_DATETIME_ORDER | = | [:year, '-'.freeze, :month, '-'.freeze, :day, ' '.freeze, :hour, ':'.freeze, :minute, ':'.freeze, :second].freeze | ||
DEFAULT_DATE_ORDER | = | [:year, '-'.freeze, :month, '-'.freeze, :day].freeze | ||
DEFAULT_DATE_SELECT_OPS | = | {:year=>1900..2050, :month=>1..12, :day=>1..31, :hour=>0..23, :minute=>0..59, :second=>0..59}.freeze |
Attributes
attr | [R] |
The attributes to to set on the lower level |
form | [R] |
The |
input | [R] |
The |
opts | [R] |
The |
Public Class methods
Create a new instance and call it
# File lib/forme/transformers/formatter.rb 27 def self.call(input) 28 new.call(input) 29 end
Public Instance methods
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.
# File lib/forme/transformers/formatter.rb 57 def call(input) 58 @input = input 59 @form = input.form 60 attr = input.opts[:attr] 61 @attr = attr ? attr.dup : {} 62 @opts = input.opts 63 normalize_options 64 tag = if html = input.opts[:html] 65 html = html.call(input) if html.respond_to?(:call) 66 form.raw(html) 67 else 68 convert_to_tag(input.type) 69 end 70 tag = wrap_tag_with_label(tag) if @opts[:label] 71 tag = wrap_tag_with_error(tag) if @opts[:error] 72 tag = wrap(:helper, tag) if input.opts[:help] 73 wrap_tag(tag) 74 end