Class: Tablerize::StructuredHtmlElement

Inherits:
HtmlElement show all
Defined in:
lib/tablerize/html_element.rb

Overview

A StructuredHtmlElement represents HTML tags enclosing an array of HtmlElements.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, opts = {}) ⇒ StructuredHtmlElement

Returns a new instance of StructuredHtmlElement.



24
25
26
27
28
29
30
31
# File 'lib/tablerize/html_element.rb', line 24

def initialize(tag, opts = {})
  @tag = tag
  @attrs = {}
  @classes = []
  @children = []
  add_class opts[:class] unless opts[:class].nil?
  @attrs.update opts[:attrs] unless opts[:attrs].nil?
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



22
23
24
# File 'lib/tablerize/html_element.rb', line 22

def attrs
  @attrs
end

#childrenObject (readonly)

Returns the value of attribute children.



22
23
24
# File 'lib/tablerize/html_element.rb', line 22

def children
  @children
end

#classesObject (readonly)

Returns the value of attribute classes.



22
23
24
# File 'lib/tablerize/html_element.rb', line 22

def classes
  @classes
end

#tagObject

Returns the value of attribute tag.



21
22
23
# File 'lib/tablerize/html_element.rb', line 21

def tag
  @tag
end

Instance Method Details

#add_class(classes) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/tablerize/html_element.rb', line 33

def add_class(classes)
  if classes.respond_to? :each
    classes.each do |klass|
      add_single_class klass
    end
  else
    add_single_class classes
  end
end

#to_htmlObject



43
44
45
# File 'lib/tablerize/html_element.rb', line 43

def to_html
  "<#{tag}#{attrs_html(@attrs)}>#{inner_html}</#{tag}>"
end