Module: Dom
- Defined in:
- lib/dom.rb
Class Method Summary collapse
- .attr(h) ⇒ Object
- .compact ⇒ Object
- .hyphenize(sym) ⇒ Object
- .join_compact(a, tag, s = "".freeze) ⇒ Object
- .join_nested(a, tag) ⇒ Object
- .join_pre(a, tag) ⇒ Object
- .json_attr(h) ⇒ Object
- .nested ⇒ Object
- .pre ⇒ Object
Class Method Details
.attr(h) ⇒ Object
23 |
# File 'lib/dom.rb', line 23 def self.attr h; h.map{|k, v| " #{hyphenize(k)}=\"#{v}\""}.join end |
.compact ⇒ Object
11 |
# File 'lib/dom.rb', line 11 def self.compact; singleton_class.class_eval{alias :join :join_compact} end |
.hyphenize(sym) ⇒ Object
25 |
# File 'lib/dom.rb', line 25 def self.hyphenize sym; sym.to_s.tr("_".freeze, "-".freeze) end |
.join_compact(a, tag, s = "".freeze) ⇒ Object
14 15 16 |
# File 'lib/dom.rb', line 14 def self.join_compact a, tag, s = "".freeze a.map{|e| e.to_s.escape_html(tag)}.join(s) end |
.join_nested(a, tag) ⇒ Object
17 18 19 |
# File 'lib/dom.rb', line 17 def self.join_nested a, tag "#$/#{join_compact(a, tag, $/).gsub(/^/, " ".freeze)}#$/" end |
.join_pre(a, tag) ⇒ Object
20 21 22 |
# File 'lib/dom.rb', line 20 def self.join_pre a, tag "<!--#$/#{"-->#{join_compact(a, tag, "<!--#$/-->".freeze)}<!--".gsub(/^/, " ".freeze)}#$/-->" end |
.json_attr(h) ⇒ Object
24 |
# File 'lib/dom.rb', line 24 def self.json_attr h; Hash[h.map{|k, v| [hyphenize(k), v]}] end |
.nested ⇒ Object
12 |
# File 'lib/dom.rb', line 12 def self.nested; singleton_class.class_eval{alias :join :join_nested} end |
.pre ⇒ Object
13 |
# File 'lib/dom.rb', line 13 def self.pre; singleton_class.class_eval{alias :join :join_pre} end |