Class: Tablerize::StructuredHtmlElement
- Inherits:
-
HtmlElement
- Object
- HtmlElement
- Tablerize::StructuredHtmlElement
- Defined in:
- lib/tablerize/html_element.rb
Overview
A StructuredHtmlElement represents HTML tags enclosing an array of HtmlElements.
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
- #add_class(classes) ⇒ Object
-
#initialize(tag, opts = {}) ⇒ StructuredHtmlElement
constructor
A new instance of StructuredHtmlElement.
- #to_html ⇒ Object
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
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
22 23 24 |
# File 'lib/tablerize/html_element.rb', line 22 def attrs @attrs end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
22 23 24 |
# File 'lib/tablerize/html_element.rb', line 22 def children @children end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
22 23 24 |
# File 'lib/tablerize/html_element.rb', line 22 def classes @classes end |
#tag ⇒ Object
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_html ⇒ Object
43 44 45 |
# File 'lib/tablerize/html_element.rb', line 43 def to_html "<#{tag}#{attrs_html(@attrs)}>#{inner_html}</#{tag}>" end |