Module: Dom
- Defined in:
- lib/dom.rb
Constant Summary collapse
- Coder =
HTMLEntities.new
Class Method Summary collapse
- .compact ⇒ Object
- .format(tag, attr) ⇒ Object
- .hyphenize(sym) ⇒ Object
- .join_compact(a, tag) ⇒ Object
- .join_nested(a, tag) ⇒ Object
- .join_pre(a, tag) ⇒ Object
- .json_format(tag, attr) ⇒ Object
- .nested ⇒ Object
- .pre ⇒ Object
Class Method Details
.compact ⇒ Object
61 |
# File 'lib/dom.rb', line 61 def self.compact; singleton_class.class_eval{alias join join_compact} end |
.format(tag, attr) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# 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) ⇒ Object
102 |
# File 'lib/dom.rb', line 102 def self.hyphenize sym; sym.to_s.tr("_", "-") end |
.join_compact(a, tag) ⇒ Object
64 65 66 |
# 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) ⇒ Object
67 68 69 70 71 |
# 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) ⇒ Object
72 73 74 75 76 |
# 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) ⇒ Object
96 97 98 99 100 101 |
# 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 ⇒ Object
62 |
# File 'lib/dom.rb', line 62 def self.nested; singleton_class.class_eval{alias join join_nested} end |
.pre ⇒ Object
63 |
# File 'lib/dom.rb', line 63 def self.pre; singleton_class.class_eval{alias join join_pre} end |