Class: Forme::Tag
- Inherits:
-
Object
- Object
- Forme::Tag
- 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
-
#attr ⇒ Object
readonly
The attributes hash of this receiver.
-
#children ⇒ Object
readonly
An array instance representing the children of the receiver, or possibly
nil
if the receiver has no children. -
#form ⇒ Object
readonly
The
Form
object related to the receiver. -
#type ⇒ Object
readonly
The type of tag, should be a symbol (e.g. :input, :select).
Instance Method Summary collapse
-
#<<(child) ⇒ Object
Adds a child to the array of receiver’s children.
-
#initialize(form, type, attr = {}, children = nil) ⇒ Tag
constructor
Set the
form
,type
,attr
, andchildren
. -
#tag(*a, &block) ⇒ Object
Create a new
Tag
instance with the given arguments and block related to the receiver’sform
. -
#to_s ⇒ Object
Return a string containing the serialized content of the receiver.
Constructor Details
#initialize(form, type, attr = {}, children = nil) ⇒ Tag
Set the form
, type
, attr
, and children
.
21 22 23 24 |
# File 'lib/forme/tag.rb', line 21 def initialize(form, type, attr={}, children=nil) @form, @type, @attr = form, type, (attr||{}) @children = parse_children(children) end |
Instance Attribute Details
#attr ⇒ Object (readonly)
The attributes hash of this receiver.
14 15 16 |
# File 'lib/forme/tag.rb', line 14 def attr @attr end |
#children ⇒ Object (readonly)
An array instance representing the children of the receiver, or possibly nil
if the receiver has no children.
18 19 20 |
# File 'lib/forme/tag.rb', line 18 def children @children end |
#form ⇒ Object (readonly)
The Form
object related to the receiver.
8 9 10 |
# File 'lib/forme/tag.rb', line 8 def form @form end |
#type ⇒ Object (readonly)
The type of tag, should be a symbol (e.g. :input, :select).
11 12 13 |
# File 'lib/forme/tag.rb', line 11 def type @type end |
Instance Method Details
#<<(child) ⇒ Object
Adds a child to the array of receiver’s children.
27 28 29 30 31 32 33 |
# File 'lib/forme/tag.rb', line 27 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
.
37 38 39 |
# File 'lib/forme/tag.rb', line 37 def tag(*a, &block) form._tag(*a, &block) end |
#to_s ⇒ Object
Return a string containing the serialized content of the receiver.
42 43 44 |
# File 'lib/forme/tag.rb', line 42 def to_s form.raw_output(Forme.transform(:serializer, @opts, @form.opts, self)) end |