Module: Dom

Defined in:
lib/dom.rb

Class Method Summary collapse

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

.compactObject



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

.nestedObject



12
# File 'lib/dom.rb', line 12

def self.nested; singleton_class.class_eval{alias :join :join_nested} end

.preObject



13
# File 'lib/dom.rb', line 13

def self.pre; singleton_class.class_eval{alias :join :join_pre} end