class MaRuKu::Out::HTML::HTMLElement
A simple class to represent an HTML
element for output.
Constants
- SELF_CLOSING
-
These elements have no children and should be rendered with a self-closing tag. It’s not an exhaustive list, but they cover everything we use.
Attributes
Public Class Methods
Source
# File lib/maruku/output/to_html.rb, line 21 def initialize(name, attr={}, children=[]) self.name = name self.attributes = attr || {} self.children = Array(children) children << yield if block_given? end
Public Instance Methods
Source
# File lib/maruku/output/to_html.rb, line 28 def <<(child) children << child if children self end
Source
# File lib/maruku/output/to_html.rb, line 37 def []=(key, value) attributes[key.to_s] = value end
Source
# File lib/maruku/output/to_html.rb, line 41 def add_class(class_name) attributes['class'] = ((attributes['class']||'').split(' ') + [class_name]).join(' ') end
Source
# File lib/maruku/output/to_html.rb, line 49 def to_html m = "<#{name}" attributes.each do |k, v| m << " #{k.to_s}=\"#{v.to_s}\"" end if SELF_CLOSING.include? name m << " />" else content = children.map(&:to_s) m << ">" << content.join('') << "</#{name}>" end end