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.



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

#attrObject (readonly)

The attributes hash of this receiver.



533
534
535
# File 'lib/forme.rb', line 533

def attr
  @attr
end

#childrenObject (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

#formObject (readonly)

The Form object related to the receiver.



527
528
529
# File 'lib/forme.rb', line 527

def form
  @form
end

#typeObject (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_sObject

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