Class: Forme::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/forme.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

Instance Method Summary collapse

Constructor Details

#initialize(form, type, opts = {}) ⇒ Input

Set the form, type, and opts.



536
537
538
539
540
541
# File 'lib/forme.rb', line 536

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

#formObject (readonly)

The Form object related to the receiver.



524
525
526
# File 'lib/forme.rb', line 524

def form
  @form
end

#form_optsObject (readonly)

The options hash in use by the form at the time of the Input’s instantiation.



533
534
535
# File 'lib/forme.rb', line 533

def form_opts
  @form_opts
end

#optsObject (readonly)

The options hash for the Input.



530
531
532
# File 'lib/forme.rb', line 530

def opts
  @opts
end

#typeObject (readonly)

The type of input, should be a symbol (e.g. :submit, :text, :select).



527
528
529
# File 'lib/forme.rb', line 527

def type
  @type
end

Instance Method Details

#formatObject

Transform the receiver into a lower level Tag form (or an array of them).



562
563
564
# File 'lib/forme.rb', line 562

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.



545
546
547
# File 'lib/forme.rb', line 545

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.



551
552
553
# File 'lib/forme.rb', line 551

def tag(*a, &block)
  form._tag(*a, &block)
end

#to_sObject

Return a string containing the serialized content of the receiver.



556
557
558
# File 'lib/forme.rb', line 556

def to_s
  form.raw_output(Forme.transform(:serializer, @opts, @form_opts, self))
end