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.
540 541 542 543 |
# File 'lib/forme.rb', line 540 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.
533 534 535 |
# File 'lib/forme.rb', line 533 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.
537 538 539 |
# File 'lib/forme.rb', line 537 def children @children end |
#form ⇒ Object (readonly)
The Form object related to the receiver.
527 528 529 |
# File 'lib/forme.rb', line 527 def form @form end |
#type ⇒ Object (readonly)
The type of tag, should be a symbol (e.g. :input, :select).
530 531 532 |
# File 'lib/forme.rb', line 530 def type @type end |
Instance Method Details
#<<(child) ⇒ Object
Adds a child to the array of receiver’s children.
546 547 548 549 550 551 552 |
# File 'lib/forme.rb', line 546 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.
556 557 558 |
# File 'lib/forme.rb', line 556 def tag(*a, &block) form._tag(*a, &block) end |
#to_s ⇒ Object
Return a string containing the serialized content of the receiver.
561 562 563 |
# File 'lib/forme.rb', line 561 def to_s Forme.transform(:serializer, @opts, @form.opts, self) end |