Class: Forme::Tag
- Inherits:
-
Object
- Object
- Forme::Tag
- Defined in:
- lib/forme.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
nilif the receiver has no children. -
#form ⇒ Object
readonly
The
Formobject 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
Taginstance 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.
584 585 586 587 |
# File 'lib/forme.rb', line 584 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.
577 578 579 |
# File 'lib/forme.rb', line 577 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.
581 582 583 |
# File 'lib/forme.rb', line 581 def children @children end |
#form ⇒ Object (readonly)
The Form object related to the receiver.
571 572 573 |
# File 'lib/forme.rb', line 571 def form @form end |
#type ⇒ Object (readonly)
The type of tag, should be a symbol (e.g. :input, :select).
574 575 576 |
# File 'lib/forme.rb', line 574 def type @type end |
Instance Method Details
#<<(child) ⇒ Object
Adds a child to the array of receiver’s children.
590 591 592 593 594 595 596 |
# File 'lib/forme.rb', line 590 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.
600 601 602 |
# File 'lib/forme.rb', line 600 def tag(*a, &block) form._tag(*a, &block) end |
#to_s ⇒ Object
Return a string containing the serialized content of the receiver.
605 606 607 |
# File 'lib/forme.rb', line 605 def to_s form.raw_output(Forme.transform(:serializer, @opts, @form.opts, self)) end |