dom 0.2.10 → 0.2.12
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 +36 -23
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e3e8109c1a95328ff38ea23213be43fa8a06865
|
4
|
+
data.tar.gz: d61374e6c2985930d0d7ae0d572a1bf5c2d8856b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e880eadaae730af643e02a29ff85f569a2b4ebcddda509ec49eeffa5a7aafd59cdc8804b1c3e233852ffb5596340643919522645e65a50a55aa194da73329de8
|
7
|
+
data.tar.gz: 2307e935d2a2fd80321f4d3c71f3ac5d4a7e6424a9b44a4934e042d53368d789460a3765ead8149bf3f9e3f67c83d33255b6dc4cd7a5b39cb2e0eadafdb11d39
|
data/lib/dom.rb
CHANGED
@@ -8,6 +8,7 @@ end
|
|
8
8
|
|
9
9
|
module Dom
|
10
10
|
Coder = HTMLEntities.new
|
11
|
+
Indent = " "
|
11
12
|
def self.compact; singleton_class.class_eval{alias join join_compact} end
|
12
13
|
def self.nested; singleton_class.class_eval{alias join join_nested} end
|
13
14
|
def self.pre; singleton_class.class_eval{alias join join_pre} end
|
@@ -15,35 +16,39 @@ module Dom
|
|
15
16
|
a.map{|e| e.to_s.escape_html(tag)}.join(s)
|
16
17
|
end
|
17
18
|
def self.join_nested a, tag
|
18
|
-
"
|
19
|
+
"#$/%s#$/".freeze % join_compact(a, tag, $/).gsub(/^/o, " ".freeze)
|
19
20
|
end
|
20
21
|
def self.join_pre a, tag
|
21
|
-
"<!--#$/#{
|
22
|
+
"<!--#$/#{Indent}-->%s<!--#$/-->".freeze %
|
23
|
+
join_compact(a, tag, "<!--#$/-->".freeze).gsub(/^/o, Indent)
|
22
24
|
end
|
23
|
-
def self.attr h; h.map{|k, v| "
|
25
|
+
def self.attr h; h.map{|k, v| " %s=\"%s\"".freeze % [hyphenize(k), v]}.join end
|
24
26
|
def self.json_attr h; h.map{|k, v| [hyphenize(k), v]}.to_h end
|
25
27
|
def self.hyphenize sym; sym.to_s.tr("_".freeze, "-".freeze) end
|
26
28
|
end
|
27
29
|
|
28
30
|
module Kernel
|
29
|
-
private
|
30
|
-
|
31
|
-
|
31
|
+
private def dom tag, mounted: nil, **attr
|
32
|
+
("<%s%s />".freeze % [Dom.hyphenize(tag), Dom.attr(attr)])
|
33
|
+
.dom_escaped.mounted_set(mounted)
|
34
|
+
end
|
35
|
+
private def jsonml tag, attr = nil
|
36
|
+
[Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr)]
|
32
37
|
end
|
33
|
-
def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr)] end
|
34
38
|
end
|
35
39
|
|
36
40
|
class String
|
37
|
-
def dom tag,
|
38
|
-
|
39
|
-
"
|
40
|
-
|
41
|
+
def dom tag, mounted: nil, **attr
|
42
|
+
_tag = Dom.hyphenize(tag)
|
43
|
+
("<%s%s>%s</%s>".freeze % [_tag, Dom.attr(attr), escape_html(tag).ansi2html, _tag])
|
44
|
+
.dom_escaped.mounted_set(mounted)
|
41
45
|
end
|
46
|
+
def mounted; nil end
|
42
47
|
def escape_html tag = nil
|
43
48
|
case tag; when :style, :script then self else Dom::Coder.encode(self) end
|
44
49
|
end
|
45
50
|
def unescape_html; Dom::Coder.decode(self) end
|
46
|
-
def
|
51
|
+
def dom_escaped; DomString.new(self) end
|
47
52
|
def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr), self] end
|
48
53
|
AnsiColor = {
|
49
54
|
"1" => "bold",
|
@@ -71,9 +76,8 @@ class String
|
|
71
76
|
io.print(
|
72
77
|
if sc.scan(/\e\[0?m/o) then '</span>'.freeze
|
73
78
|
elsif sc.scan(/\e\[0?(\d+)m/o) then '<span class="%s">'.freeze % AnsiColor[sc[1]]
|
74
|
-
|
75
|
-
|
76
|
-
) until sc.eos?
|
79
|
+
end ||
|
80
|
+
sc.scan(/./mo)) until sc.eos?
|
77
81
|
io.string
|
78
82
|
end
|
79
83
|
end
|
@@ -81,17 +85,26 @@ end
|
|
81
85
|
class DomString < String
|
82
86
|
def to_s; self end
|
83
87
|
def escape_html tag = nil; self end
|
84
|
-
def
|
85
|
-
def % v; super(v).
|
86
|
-
def * v; super(v).
|
87
|
-
def + v; super(v).
|
88
|
+
def dom_escaped; self end
|
89
|
+
def % v; super(v).dom_escaped end
|
90
|
+
def * v; super(v).dom_escaped end
|
91
|
+
def + v; super(v).dom_escaped end
|
92
|
+
def mounted_set *mounted
|
93
|
+
mounted.compact!
|
94
|
+
if mounted.empty?
|
95
|
+
elsif @mounted then @mounted.concat(mounted.join)
|
96
|
+
else @mounted = mounted.join
|
97
|
+
end
|
98
|
+
self
|
99
|
+
end
|
100
|
+
attr_reader :mounted
|
88
101
|
end
|
89
102
|
|
90
103
|
class Array
|
91
|
-
def dom tag,
|
92
|
-
|
93
|
-
"
|
94
|
-
|
104
|
+
def dom tag, mounted: nil, **attr
|
105
|
+
_tag = Dom.hyphenize(tag)
|
106
|
+
("<%s%s>%s</%s>".freeze % [_tag, Dom.attr(attr), Dom.join(self, tag), _tag])
|
107
|
+
.dom_escaped.mounted_set(*map(&:mounted), mounted)
|
95
108
|
end
|
96
109
|
def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr), *self] end
|
97
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06
|
11
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email: []
|
@@ -36,7 +36,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
36
|
version: '0'
|
37
37
|
requirements: []
|
38
38
|
rubyforge_project:
|
39
|
-
rubygems_version: 2.
|
39
|
+
rubygems_version: 2.4.1
|
40
40
|
signing_key:
|
41
41
|
specification_version: 4
|
42
42
|
summary: Creates HTML DOM strings
|