Class: Forme::Tag

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

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

Set the form, type, attr, and children.



580
581
582
583
# File 'lib/forme.rb', line 580

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.



573
574
575
# File 'lib/forme.rb', line 573

def attr
  @attr
end

#childrenObject (readonly)

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



577
578
579
# File 'lib/forme.rb', line 577

def children
  @children
end

#formObject (readonly)

The Form object related to the receiver.



567
568
569
# File 'lib/forme.rb', line 567

def form
  @form
end

#typeObject (readonly)

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



570
571
572
# File 'lib/forme.rb', line 570

def type
  @type
end

Instance Method Details

#<<(child) ⇒ Object

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



586
587
588
589
590
591
592
# File 'lib/forme.rb', line 586

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.



596
597
598
# File 'lib/forme.rb', line 596

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

#to_sObject

Return a string containing the serialized content of the receiver.



601
602
603
# File 'lib/forme.rb', line 601

def to_s
  form.serialize(self)
end