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.

Methods

Public Class

  1. call

Public Instance

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

Public Class methods

call (input)

Create a new instance and call it

[show source]
# File lib/forme/transformers/formatter.rb, line 27
def self.call(input)
  new.call(input)
end

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 57
def call(input)
  @input = input
  @form = input.form
  attr = input.opts[:attr]
  @attr = attr ? attr.dup : {}
  @opts = input.opts
  normalize_options

  tag = if html = input.opts[:html]
    html = html.call(input) if html.respond_to?(:call)
    form.raw(html)
  else
    convert_to_tag(input.type)
  end
  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]
  wrap_tag(tag)
end