dom 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dom.rb +21 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88b038b2977ed6d5ebca9f8d1069576c54af8173
|
4
|
+
data.tar.gz: fa7ba3f5e0791bff501b4027828a790346ef4627
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 421b0495c1e9fc83ea6512cd23a8db67a8a06352d8f7759e742fdc2f467c91d6204b3635fc95049741b525fc8a8282df44d9c9b417b5c74ace943e4da0111bd0
|
7
|
+
data.tar.gz: 424a460427f206fbb60330bbd1edf8fabde0bba3bb3f58e66d9acb04d1e38c4dc4aa6b9d7b83836ddbc8ac5244ce68516cda99df9c8cc15d45173ebe6eba6a64
|
data/lib/dom.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "stringio"
|
2
3
|
require "strscan"
|
3
4
|
require "htmlentities"
|
4
5
|
|
5
6
|
class File
|
6
|
-
def self.relativize f; f.sub(%r{\A/}o, ""
|
7
|
+
def self.relativize f; f.sub(%r{\A/}o, "") end
|
7
8
|
end
|
8
9
|
|
9
10
|
module Dom
|
@@ -21,29 +22,29 @@ module Dom
|
|
21
22
|
.prepend($/)
|
22
23
|
end
|
23
24
|
def self.join_pre a, tag
|
24
|
-
a.map{|e| e.to_s.escape_html(tag).prepend("-->"
|
25
|
+
a.map{|e| e.to_s.escape_html(tag).prepend("-->").concat("<!--#$/")}
|
25
26
|
.join.gsub(/^/o, Indent)
|
26
|
-
.prepend("<!--#$/"
|
27
|
+
.prepend("<!--#$/").concat("-->")
|
27
28
|
end
|
28
29
|
def self.attr h
|
29
|
-
" ".concat(h.map do
|
30
|
+
(+" ").concat(h.map do
|
30
31
|
|k, v|
|
31
32
|
v = case v
|
32
33
|
when nil then next
|
33
|
-
when false then "none"
|
34
|
-
when true then ""
|
34
|
+
when false then "none"
|
35
|
+
when true then ""
|
35
36
|
else v
|
36
37
|
end
|
37
|
-
"%s=\"%s\""
|
38
|
-
end.compact.join" "
|
38
|
+
"%s=\"%s\"" % [hyphenize(k), v]
|
39
|
+
end.compact.join" ")
|
39
40
|
end
|
40
41
|
def self.json_attr h; h.map{|k, v| [hyphenize(k), v]}.to_h end
|
41
|
-
def self.hyphenize sym; sym.to_s.tr("_"
|
42
|
+
def self.hyphenize sym; sym.to_s.tr("_", "-") end
|
42
43
|
end
|
43
44
|
|
44
45
|
module Kernel
|
45
46
|
private def dom tag, mounted: nil, **attr
|
46
|
-
("<%s%s />"
|
47
|
+
("<%s%s />" % [Dom.hyphenize(tag), Dom.attr(attr)])
|
47
48
|
.dom_escaped.mounted_set(mounted)
|
48
49
|
end
|
49
50
|
private def jsonml tag, attr = nil
|
@@ -54,7 +55,7 @@ end
|
|
54
55
|
class String
|
55
56
|
def dom tag, mounted: nil, **attr
|
56
57
|
_tag = Dom.hyphenize(tag)
|
57
|
-
("<%s%s>%s</%s>"
|
58
|
+
("<%s%s>%s</%s>" % [_tag, Dom.attr(attr), escape_html(tag)._ansi2html, _tag])
|
58
59
|
.dom_escaped.mounted_set(mounted)
|
59
60
|
end
|
60
61
|
def mounted; nil end
|
@@ -87,8 +88,8 @@ class String
|
|
87
88
|
sc = StringScanner.new(self)
|
88
89
|
io = StringIO.new
|
89
90
|
io.print(
|
90
|
-
if sc.scan(/\e\[0?m/o) then '</span>'
|
91
|
-
elsif sc.scan(/\e\[0?(\d+)m/o) then '<span class="%s">'
|
91
|
+
if sc.scan(/\e\[0?m/o) then '</span>'
|
92
|
+
elsif sc.scan(/\e\[0?(\d+)m/o) then '<span class="%s">' % AnsiColor[sc[1]]
|
92
93
|
end ||
|
93
94
|
sc.scan(/./mo)) until sc.eos?
|
94
95
|
io.string
|
@@ -114,13 +115,17 @@ class DomString < String
|
|
114
115
|
end
|
115
116
|
|
116
117
|
class Array
|
117
|
-
def dom tag, mounted: nil, **attr
|
118
|
+
def dom tag = nil, mounted: nil, **attr
|
118
119
|
error_objs = select{|e| e.kind_of?(String).!}
|
119
120
|
unless error_objs.empty?
|
120
121
|
raise "All array elements must be a string: #{error_objs.first.inspect}"
|
121
122
|
end
|
122
|
-
|
123
|
-
|
123
|
+
if tag
|
124
|
+
_tag = Dom.hyphenize(tag)
|
125
|
+
"<%s%s>%s</%s>" % [_tag, Dom.attr(attr), Dom.join(self, tag), _tag]
|
126
|
+
else
|
127
|
+
Dom.join(self, tag)
|
128
|
+
end
|
124
129
|
.dom_escaped.mounted_set(*map(&:mounted), mounted)
|
125
130
|
end
|
126
131
|
def jsonml tag, attr = nil; [Dom.hyphenize(tag), *([Dom.json_attr(attr)] if attr), *self] end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sawa
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.5.1
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: Creates HTML DOM strings
|