Module: Dom

Defined in:
lib/dom.rb

Constant Summary collapse

Coder =
HTMLEntities.new
Indent =
"  "

Class Method Summary collapse

Class Method Details

.attr(h) ⇒ Object



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

def self.attr h; h.map{|k, v| " %s=\"%s\"".freeze % [hyphenize(k), v]}.join end

.compactObject



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

def self.compact; singleton_class.class_eval{alias join join_compact} end

.hyphenize(sym) ⇒ Object



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

def self.hyphenize sym; sym.to_s.tr("_".freeze, "-".freeze) end

.join_compact(a, tag) ⇒ Object



15
16
17
# File 'lib/dom.rb', line 15

def self.join_compact a, tag
	a.map{|e| e.to_s.escape_html(tag)}.join
end

.join_nested(a, tag) ⇒ Object



18
19
20
21
22
# File 'lib/dom.rb', line 18

def self.join_nested a, tag
	a.map{|e| e.to_s.escape_html(tag).concat($/)}
	.join.gsub(/^/o, Indent)
	.prepend($/)
end

.join_pre(a, tag) ⇒ Object



23
24
25
26
27
# File 'lib/dom.rb', line 23

def self.join_pre a, tag
	a.map{|e| e.to_s.escape_html(tag).prepend("-->".freeze).concat("<!--#$/".freeze)}
	.join.gsub(/^/o, Indent)
	.prepend("<!--#$/".freeze).concat("-->".freeze)
end

.json_attr(h) ⇒ Object



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

def self.json_attr h; h.map{|k, v| [hyphenize(k), v]}.to_h end

.nestedObject



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

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

.preObject



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

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