Class: Forme::Input

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



18
19
20
21
22
23
# File 'lib/forme/input.rb', line 18

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.



6
7
8
# File 'lib/forme/input.rb', line 6

def form
  @form
end

#form_optsObject (readonly)

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



15
16
17
# File 'lib/forme/input.rb', line 15

def form_opts
  @form_opts
end

#optsObject (readonly)

The options hash for the Input.



12
13
14
# File 'lib/forme/input.rb', line 12

def opts
  @opts
end

#typeObject (readonly)

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



9
10
11
# File 'lib/forme/input.rb', line 9

def type
  @type
end

Instance Method Details

#formatObject

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



44
45
46
# File 'lib/forme/input.rb', line 44

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.



27
28
29
# File 'lib/forme/input.rb', line 27

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.



33
34
35
# File 'lib/forme/input.rb', line 33

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

#to_sObject

Return a string containing the serialized content of the receiver.



38
39
40
# File 'lib/forme/input.rb', line 38

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