dom 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dom.rb +13 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8584195bab3ab80020115f6f91c2707f9d8d452
|
4
|
+
data.tar.gz: f3cf38faf00c31a4b11823fc920147a6a312355c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 719fce10bc791310d7f138db495fc8670443a845e0bfbc153a352835ea873202fd785875f4565ff4d0cac86bfc8ca19d4c8e345bfdfd88afb16dc1ecc3b16b8a
|
7
|
+
data.tar.gz: 860b198dab65fdaf52b040090b3db0f95ac51e130b68b771efef308796ebefaa767b1de367a6becf0d1655ef8614c17c7d3f8d57127a7fd3ba73f3df1ddb76a4
|
data/lib/dom.rb
CHANGED
@@ -27,7 +27,14 @@ module Dom
|
|
27
27
|
end
|
28
28
|
def self.attr h
|
29
29
|
" ".concat(h.map do
|
30
|
-
|k, v|
|
30
|
+
|k, v|
|
31
|
+
v = case v
|
32
|
+
when nil then next
|
33
|
+
when false then "none".freeze
|
34
|
+
when true then "".freeze
|
35
|
+
else v
|
36
|
+
end
|
37
|
+
"%s=\"%s\"".freeze % [hyphenize(k), v]
|
31
38
|
end.compact.join" ".freeze)
|
32
39
|
end
|
33
40
|
def self.json_attr h; h.map{|k, v| [hyphenize(k), v]}.to_h end
|
@@ -47,14 +54,13 @@ end
|
|
47
54
|
class String
|
48
55
|
def dom tag, mounted: nil, **attr
|
49
56
|
_tag = Dom.hyphenize(tag)
|
50
|
-
("<%s%s>%s</%s>".freeze % [_tag, Dom.attr(attr), escape_html(tag).
|
57
|
+
("<%s%s>%s</%s>".freeze % [_tag, Dom.attr(attr), escape_html(tag)._ansi2html, _tag])
|
51
58
|
.dom_escaped.mounted_set(mounted)
|
52
59
|
end
|
53
60
|
def mounted; nil end
|
54
61
|
def escape_html tag = nil
|
55
62
|
case tag; when :style, :script then self else Dom::Coder.encode(self) end
|
56
63
|
end
|
57
|
-
def unescape_html; Dom::Coder.decode(self) end
|
58
64
|
def dom_escaped; DomString.new(self) end
|
59
65
|
def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr), self] end
|
60
66
|
AnsiColor = {
|
@@ -77,7 +83,7 @@ class String
|
|
77
83
|
"46" => "bg-cyan",
|
78
84
|
"47" => "bg-white",
|
79
85
|
}
|
80
|
-
def
|
86
|
+
def _ansi2html
|
81
87
|
sc = StringScanner.new(self)
|
82
88
|
io = StringIO.new
|
83
89
|
io.print(
|
@@ -87,15 +93,15 @@ class String
|
|
87
93
|
sc.scan(/./mo)) until sc.eos?
|
88
94
|
io.string
|
89
95
|
end
|
96
|
+
def ansi2html; _ansi2html.dom_escaped end
|
90
97
|
end
|
91
98
|
|
92
99
|
class DomString < String
|
93
100
|
def to_s; self end
|
94
101
|
def escape_html tag = nil; self end
|
95
102
|
def dom_escaped; self end
|
96
|
-
def % v; super(v).dom_escaped end
|
97
|
-
def
|
98
|
-
def + v; super(v).dom_escaped end
|
103
|
+
# def % v; super(v).dom_escaped end
|
104
|
+
# def + v; super(v).dom_escaped end
|
99
105
|
def mounted_set *mounted
|
100
106
|
mounted.compact!
|
101
107
|
if mounted.empty?
|