Class: Forme::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/forme/tag.rb

Overview

Low level abstract tag form, where each instance represents a html tag with attributes and children.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, type, attr = {}, children = nil) ⇒ Tag

Set the form, type, attr, and children.



19
20
21
22
# File 'lib/forme/tag.rb', line 19

def initialize(form, type, attr={}, children=nil)
  @form, @type, @attr = form, type, (attr||{})
  @children = parse_children(children)
end

Instance Attribute Details

#attrObject (readonly)

The attributes hash of this receiver.



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

def attr
  @attr
end

#childrenObject (readonly)

An array instance representing the children of the receiver, or possibly nil if the receiver has no children.



16
17
18
# File 'lib/forme/tag.rb', line 16

def children
  @children
end

#formObject (readonly)

The Form object related to the receiver.



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

def form
  @form
end

#typeObject (readonly)

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



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

def type
  @type
end

Instance Method Details

#<<(child) ⇒ Object

Adds a child to the array of receiver’s children.



25
26
27
28
29
30
31
# File 'lib/forme/tag.rb', line 25

def <<(child)
  if children
    children << child
  else
    @children = [child]
  end
end

#tag(*a, &block) ⇒ Object

Create a new Tag instance with the given arguments and block related to the receiver’s form.



35
36
37
# File 'lib/forme/tag.rb', line 35

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

#to_sObject

Return a string containing the serialized content of the receiver.



40
41
42
# File 'lib/forme/tag.rb', line 40

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