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.



492
493
494
495
496
497
# File 'lib/forme.rb', line 492

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.



480
481
482
# File 'lib/forme.rb', line 480

def form
  @form
end

#form_optsObject (readonly)

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



489
490
491
# File 'lib/forme.rb', line 489

def form_opts
  @form_opts
end

#optsObject (readonly)

The options hash for the Input.



486
487
488
# File 'lib/forme.rb', line 486

def opts
  @opts
end

#typeObject (readonly)

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



483
484
485
# File 'lib/forme.rb', line 483

def type
  @type
end

Instance Method Details

#formatObject

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



518
519
520
# File 'lib/forme.rb', line 518

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.



501
502
503
# File 'lib/forme.rb', line 501

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.



507
508
509
# File 'lib/forme.rb', line 507

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

#to_sObject

Return a string containing the serialized content of the receiver.



512
513
514
# File 'lib/forme.rb', line 512

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