Class: HOM::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/hom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, attributes = nil, content = Undefined) ⇒ Element

Returns a new instance of Element.



37
38
39
# File 'lib/hom.rb', line 37

def initialize(tag_name, attributes = nil, content = Undefined)
  @tag_name, @attributes, @content = tag_name, AttributeList.new.update(attributes), content
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



35
36
37
# File 'lib/hom.rb', line 35

def attributes
  @attributes
end

#contentObject (readonly)

Returns the value of attribute content.



35
36
37
# File 'lib/hom.rb', line 35

def content
  @content
end

#tag_nameObject (readonly)

Returns the value of attribute tag_name.



35
36
37
# File 'lib/hom.rb', line 35

def tag_name
  @tag_name
end

Instance Method Details

#+(object) ⇒ Object



53
54
55
# File 'lib/hom.rb', line 53

def +(object)
  NodeList.new([self, object])
end

#content?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/hom.rb', line 41

def content?
  @content != Undefined
end

#html_safe?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/hom.rb', line 45

def html_safe?
  true
end

#to_sObject



49
50
51
# File 'lib/hom.rb', line 49

def to_s
  Encoding.safe_encode(self)
end