class Forme::Formatter

  1. lib/forme/bs3.rb
  2. lib/forme/transformers/formatter.rb
  3. show all
Superclass: Object

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.


Public Class

  1. call

Public Instance

  1. attr
  2. call
  3. form
  4. input
  5. opts


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.


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

  1. If the checkbox value is 't', the hidden value is 'f', since that 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  


attr [R]

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.

form [R]

The Form instance for the receiver, taken from the input.

input [R]

The Input instance for the receiver. This is what the receiver converts to the lower level Tag form (or an array of them).

opts [R]

The opts hash of the input.

Public Class methods

call (input)

Create a new instance and call it

[show source]
# File lib/forme/transformers/formatter.rb, line 26

Public Instance methods

call (input)

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.

[show source]
# File lib/forme/transformers/formatter.rb, line 56
def call(input)
  @input = input
  @form = input.form
  attr = input.opts[:attr]
  @attr = attr ? attr.dup : {}
  @opts = input.opts

  tag = if html = input.opts[:html]
    html = if html.respond_to?(:call)
  tag = wrap_tag_with_label(tag) if @opts[:label]
  tag = wrap_tag_with_error(tag) if @opts[:error]
  tag = wrap(:helper, tag) if input.opts[:help]