module Dom
Constants
- Coder
- Indent
Public Class Methods
compact()
click to toggle source
# File lib/dom.rb, line 61 def self.compact; singleton_class.class_eval{alias join join_compact} end
format(tag, attr)
click to toggle source
# File lib/dom.rb, line 77 def self.format tag, attr tag = hyphenize(tag) [ [ tag, *attr.map do |k, v| v = case v when nil then next when false then "none" when true then "" else v end "%s=\"%s\"" % [hyphenize(k), v] end ].compact.join(" "), tag ] end
hyphenize(sym;)
click to toggle source
# File lib/dom.rb, line 102 def self.hyphenize sym; sym.to_s.tr("_", "-") end
join_compact(a, tag)
click to toggle source
# File lib/dom.rb, line 64 def self.join_compact a, tag a.map{|e| e.to_s.dom_escape(tag)}.join end
join_nested(a, tag)
click to toggle source
# File lib/dom.rb, line 67 def self.join_nested a, tag a.map{|e| e.to_s.dom_escape(tag).concat($/)} .join.gsub(/^/o, Indent) .prepend($/) end
join_pre(a, tag)
click to toggle source
# File lib/dom.rb, line 72 def self.join_pre a, tag a.map{|e| e.to_s.dom_escape(tag).prepend("-->").concat("<!--#$/")} .join.gsub(/^/o, Indent) .prepend("<!--#$/").concat("-->") end
json_format(tag, attr)
click to toggle source
# File lib/dom.rb, line 96 def self.json_format tag, attr [ hyphenize(tag), *([attr.map{|k, v| [hyphenize(k), v]}.to_h] if attr) ] end
nested()
click to toggle source
# File lib/dom.rb, line 62 def self.nested; singleton_class.class_eval{alias join join_nested} end
pre()
click to toggle source
# File lib/dom.rb, line 63 def self.pre; singleton_class.class_eval{alias join join_pre} end