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.



522
523
524
525
526
527
528
529
530
531
532
# File 'lib/forme.rb', line 522

def initialize(form, type, attr={}, children=nil)
  case children
  when Array
    @children = children
  when nil
    @children = nil
  else
    @children = [children]
  end
  @form, @type, @attr = form, type, (attr||{})
end

Instance Attribute Details

#attrObject (readonly)

The attributes hash of this receiver.



515
516
517
# File 'lib/forme.rb', line 515

def attr
  @attr
end

#childrenObject (readonly)

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



519
520
521
# File 'lib/forme.rb', line 519

def children
  @children
end

#formObject (readonly)

The Form object related to the receiver.



509
510
511
# File 'lib/forme.rb', line 509

def form
  @form
end

#typeObject (readonly)

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



512
513
514
# File 'lib/forme.rb', line 512

def type
  @type
end

Instance Method Details

#<<(child) ⇒ Object

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



535
536
537
538
539
540
541
# File 'lib/forme.rb', line 535

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.



545
546
547
# File 'lib/forme.rb', line 545

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

#to_sObject

Return a string containing the serialized content of the receiver.



550
551
552
# File 'lib/forme.rb', line 550

def to_s
  form.serialize(self)
end