class Forme::Tag
Low level abstract tag form, where each instance represents an HTML tag with attributes and children.
Attributes
attr[R]
The attributes hash of this receiver.
children[R]
An array instance representing the children of the receiver, or possibly nil
if the receiver has no children.
form[R]
The Form
object related to the receiver.
type[R]
The type of tag, should be a symbol (e.g. :input, :select).
Public Class Methods
new(form, type, attr={}, children=nil)
click to toggle source
Set the form
, type
, attr
, and children
.
# File lib/forme/tag.rb 21 def initialize(form, type, attr={}, children=nil) 22 @form, @type, @attr = form, type, (attr||{}) 23 @children = parse_children(children) 24 end
Public Instance Methods
tag(*a, &block)
click to toggle source
Create a new Tag
instance with the given arguments and block related to the receiver’s form
.
# File lib/forme/tag.rb 28 def tag(*a, &block) 29 form._tag(*a, &block) 30 end
to_s()
click to toggle source
Return a string containing the serialized content of the receiver.
# File lib/forme/tag.rb 33 def to_s 34 Forme.transform(:serializer, @opts, @form.opts, self) 35 end
Private Instance Methods
parse_children(children)
click to toggle source
Convert children constructor argument into the children to use for the tag.
# File lib/forme/tag.rb 40 def parse_children(children) 41 case children 42 when Array 43 children 44 when Proc, Method 45 parse_children(children.call(self)) 46 when nil 47 nil 48 else 49 [children] 50 end 51 end