Module: JsonML
- Defined in:
- lib/jsonml.rb,
lib/jsonml/version.rb
Defined Under Namespace
Modules: Version
Constant Summary collapse
Class Method Summary collapse
Class Method Details
.attr2html(key, value) ⇒ Object
25 26 27 |
# File 'lib/jsonml.rb', line 25 def self.attr2html(key, value) %Q{#{key}="#{value}"} end |
.attrs2html(attrs) ⇒ Object
21 22 23 |
# File 'lib/jsonml.rb', line 21 def self.attrs2html(attrs) attrs.each_pair.map{|pair| attr2html(*pair) }.join(" ") end |
.to_html_text(src, out = "") ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jsonml.rb', line 3 def self.to_html_text(src, out = "") has_attrs = src[1].is_a?(Hash) first_child = has_attrs ? 2 : 1 case src when Array out << "<#{src.first}" out << " " << attrs2html(src[1]) if has_attrs out << ">" src[first_child..-1].each{|child| to_html_text(child, out) } out << "</#{src.first}>" when String out << src else raise "Unexpected node `#{src}`" end end |