weblet 0.3.4 → 0.4.1
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
- checksums.yaml.gz.sig +0 -0
- data/lib/weblet.rb +92 -71
- data.tar.gz.sig +0 -0
- metadata +32 -33
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cdf3dd81231ca9ee4385a6bb250af42f86677e30951cea62e74c5dac3a2ed19
|
4
|
+
data.tar.gz: 0f5aead405414359f202d14c97f4da26fb102d55a5b077822a4f2ebf1087c5d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2062764f51b7343e8800a9e32a823efed674af59c8e088705916e53da12b61d61c5f42ae7778940fb1f214507e672bdbb4d1dc460219ca585f23dc7a8624c7e
|
7
|
+
data.tar.gz: 6bca43e05423533b06f0ad10645c0ef8e0d9376a6335d6a26302946d18e6f8cbf0db1941da34b7c112896e1d73248111c76509e52ede277c17b0f0d70726454c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/weblet.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# file: weblet.rb
|
4
4
|
|
5
5
|
require 'rexle'
|
6
|
-
require '
|
6
|
+
require 'rxfreader'
|
7
7
|
|
8
8
|
|
9
9
|
class WebletBuilder
|
@@ -11,19 +11,19 @@ class WebletBuilder
|
|
11
11
|
def initialize(s, marker: nil, debug: false)
|
12
12
|
|
13
13
|
@marker, @debug = marker, debug
|
14
|
-
|
14
|
+
|
15
15
|
s.strip!
|
16
|
-
|
17
|
-
# the default marker is the hash symbol (#) but the client can set their
|
16
|
+
|
17
|
+
# the default marker is the hash symbol (#) but the client can set their
|
18
18
|
# own marker by simply using their custom symbol in the 1st line of input
|
19
19
|
@marker ||= s[0]
|
20
|
-
|
20
|
+
|
21
21
|
a = scan(s.strip)
|
22
22
|
puts 'a: ' + a.inspect if @debug
|
23
|
-
|
23
|
+
|
24
24
|
@a = build(a)
|
25
25
|
@a.unshift *['weblet', {}, '']
|
26
|
-
|
26
|
+
|
27
27
|
end
|
28
28
|
|
29
29
|
def to_a()
|
@@ -38,30 +38,42 @@ class WebletBuilder
|
|
38
38
|
return a unless a.length > 1
|
39
39
|
|
40
40
|
a.map {|x| scan(x, indent+1)}
|
41
|
-
|
41
|
+
|
42
42
|
end
|
43
43
|
|
44
44
|
def build(a)
|
45
45
|
|
46
46
|
puts 'a: ' + a.inspect if @debug
|
47
|
-
|
47
|
+
|
48
48
|
a.map do |x|
|
49
|
-
|
49
|
+
|
50
50
|
puts 'x: ' + x.inspect if @debug
|
51
|
-
|
52
|
-
if x
|
53
|
-
|
51
|
+
|
52
|
+
if x.is_a? String then
|
53
|
+
|
54
|
+
head, body = x.split("\n", 2)
|
55
|
+
puts 'head: ' + head.inspect if @debug
|
56
|
+
puts 'body: ' + body.inspect if @debug
|
57
|
+
puts 'marker: ' + @marker.inspect if @debug
|
58
|
+
|
59
|
+
[:node, {id: head[/#{@marker}(\w+)/,1]}, '',['![', {}, body.strip]]
|
60
|
+
|
61
|
+
elsif x[0].is_a? String
|
62
|
+
|
54
63
|
head, body = x[0].split("\n", 2)
|
64
|
+
puts 'body: ' + body.inspect if @debug
|
65
|
+
puts 'marker: ' + @marker.inspect if @debug
|
66
|
+
|
55
67
|
[:node, {id: head[/#{@marker}(\w+)/,1]}, '',['![', {}, body.strip]]
|
56
|
-
|
68
|
+
|
57
69
|
elsif x[0] and x[0].is_a? Array
|
58
|
-
|
70
|
+
|
59
71
|
head, body = x[0][0].split("\n", 2)
|
60
72
|
[:node, {id: head[/#{@marker}(\w+)/,1]}, '', \
|
61
73
|
['![', {}, body.to_s.strip], *build(x[1..-1])]
|
62
|
-
|
74
|
+
|
63
75
|
end
|
64
|
-
|
76
|
+
|
65
77
|
end
|
66
78
|
|
67
79
|
end
|
@@ -71,98 +83,80 @@ end
|
|
71
83
|
class Weblet
|
72
84
|
|
73
85
|
def initialize(raws, marker: nil, debug: false)
|
74
|
-
|
86
|
+
|
75
87
|
@debug = debug
|
76
|
-
|
77
|
-
s, _ =
|
88
|
+
|
89
|
+
s, _ = RXFReader.read(raws.strip)
|
78
90
|
|
79
91
|
obj = s[0] == '<' ? s : WebletBuilder.new(s, marker: marker, \
|
80
92
|
debug: debug).to_a
|
93
|
+
puts 'obj: ' + obj.inspect if @debug
|
81
94
|
@doc = Rexle.new(obj)
|
82
95
|
@h = scan @doc.root
|
96
|
+
@kvp = scan2keypair(@h).to_h
|
97
|
+
|
98
|
+
end
|
83
99
|
|
100
|
+
def [](key)
|
101
|
+
@kvp[key.to_s]
|
102
|
+
end
|
103
|
+
|
104
|
+
def []=(key, value)
|
105
|
+
@kvp[key.to_s] = value
|
84
106
|
end
|
85
107
|
|
86
108
|
def to_h()
|
87
109
|
@h
|
88
110
|
end
|
89
|
-
|
111
|
+
|
112
|
+
# key-value pair
|
113
|
+
def to_kvp()
|
114
|
+
@kvp
|
115
|
+
end
|
116
|
+
|
90
117
|
def to_outline()
|
91
118
|
treeize(scan_h(@h))
|
92
119
|
end
|
93
|
-
|
120
|
+
|
94
121
|
def to_xml()
|
95
122
|
@doc.root.xml pretty: true
|
96
123
|
end
|
97
124
|
|
98
|
-
def render(
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
if args.first.is_a? String then
|
103
|
-
path = args.first.split('/').map(&:to_sym)
|
104
|
-
else
|
105
|
-
path = *args.flatten(1)
|
106
|
-
end
|
125
|
+
def render(rawkey, bindingx=nil)
|
126
|
+
|
127
|
+
key = rawkey.to_s
|
128
|
+
return unless @kvp.has_key?(key)
|
107
129
|
|
108
|
-
#r = @h.dig *path
|
109
|
-
r = digx(@h, path)
|
110
|
-
|
111
130
|
# check for interpolated substitution tags e.g/ <:card/svg/link>
|
112
|
-
r.gsub
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
if r.nil? then
|
117
|
-
found = @doc.root.element("//node[@id='#{path.join}']")
|
118
|
-
r = found.cdatas.join if found
|
119
|
-
end
|
120
|
-
|
121
|
-
eval('%Q(' + r + ')', b) if r
|
131
|
+
r = @kvp[key].gsub(/<:([^>]+)>/) {|x| self.render($1) }
|
132
|
+
|
133
|
+
eval('%Q(' + r + ')', bindingx)
|
122
134
|
|
123
135
|
end
|
124
136
|
|
125
137
|
private
|
126
|
-
|
127
|
-
def digx(obj, a)
|
128
|
-
|
129
|
-
h = obj.is_a?(Array) ? obj.last : obj
|
130
|
-
|
131
|
-
r = h.dig(a.shift)
|
132
|
-
|
133
|
-
if a.any? then
|
134
|
-
digx(r, a)
|
135
|
-
else
|
136
|
-
r.is_a?(Array) ? r.first : r
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
138
|
|
141
139
|
def scan(node)
|
142
140
|
|
143
141
|
a = node.elements.map do |e|
|
144
|
-
|
145
|
-
puts 'e: ' + e.inspect if @debug
|
146
142
|
|
147
143
|
nodes = e.xpath('node')
|
148
|
-
|
149
|
-
puts 'nodes: ' + nodes.inspect if @debug
|
150
|
-
|
144
|
+
|
151
145
|
r = if nodes.any? then
|
152
|
-
|
146
|
+
|
153
147
|
r2 = scan(e)
|
154
148
|
e.cdatas.any? ? [e.cdatas.join(), r2] : r2
|
155
|
-
|
149
|
+
|
156
150
|
else
|
157
151
|
e.cdatas.join()
|
158
152
|
end
|
159
153
|
|
160
154
|
[e.attributes[:id].to_sym, r]
|
161
|
-
|
155
|
+
|
162
156
|
end.to_h
|
163
|
-
|
157
|
+
|
164
158
|
end
|
165
|
-
|
159
|
+
|
166
160
|
def scan_h(h)
|
167
161
|
|
168
162
|
a = h.map do |key, value|
|
@@ -170,7 +164,7 @@ class Weblet
|
|
170
164
|
end
|
171
165
|
|
172
166
|
end
|
173
|
-
|
167
|
+
|
174
168
|
def treeize(a, indent=-2)
|
175
169
|
|
176
170
|
indent += 1
|
@@ -185,6 +179,33 @@ class Weblet
|
|
185
179
|
end.join("\n")
|
186
180
|
|
187
181
|
end
|
188
|
-
|
189
|
-
|
182
|
+
|
183
|
+
def scan2keypair(h, trail=nil)
|
184
|
+
|
185
|
+
h.inject([]) do |r,x|
|
186
|
+
|
187
|
+
if x.last.is_a? String then
|
188
|
+
|
189
|
+
key, val = x
|
190
|
+
|
191
|
+
new_key = if r.last and r.last.first.length > 0 then
|
192
|
+
key.to_s
|
193
|
+
else
|
194
|
+
key.to_s
|
195
|
+
end
|
196
|
+
|
197
|
+
r << [[trail, new_key].compact.join('/'), val]
|
198
|
+
|
199
|
+
else
|
200
|
+
|
201
|
+
new_key = x.first.to_s
|
202
|
+
r << [new_key, x.last.first]
|
203
|
+
r.concat scan2keypair(x.last.last, [trail, new_key].compact.join('/'))
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
190
211
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weblet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -11,31 +11,31 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjIwNDE5MTg1NzA3WhcN
|
15
|
+
MjMwNDE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GRq5Ku1NeWXyfgMcGi/obkJBkV68Yl
|
29
|
+
R2p0wd7Ff7Cbg26B+cw5CdSuTigGtAwff9AUvYXYyPOfiQfRBvnXqc0Awya8Pcqh
|
30
|
+
WEy7EsCR7zYwVXhwKjVazss2N+EHTwCNBuOu6tK69bzTf1j0cm6KRcJ5jxzkpZr+
|
31
|
+
N7376dc4ukN7rhBqjKnjYZln/TKbP4eRwqhOEerBVDn1/W6BzZMCkJGB9BQpp4/B
|
32
|
+
XH6/f4U2XBLY5kGDq0YeVnKaoqjyyMtEh93qTIukESvIjlMWuh5pUktikPsrhqly
|
33
|
+
f07hewJIYm5TfvecZtS9aCRJiAIEQBCZ5zAeisxCJKJzoHkHltoYmPZ0z7LanOWy
|
34
|
+
JnNGpUAfgxmo+dQH+d6tbe9rVXNyk2FINurCKGx3N7OJsfJWueTiHXENks2men9q
|
35
|
+
35oUH2ouHjXtvit5hQCmL2+hQV/HFZj86eWeg422XrNjGwBbyQwueRmGDSR5jAbO
|
36
|
+
/gJR3jXcFcpOgDnvL6xGYhfn
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-04-19 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rexle
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
version: '1.5'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.5.
|
49
|
+
version: 1.5.14
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -56,27 +56,27 @@ dependencies:
|
|
56
56
|
version: '1.5'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.5.
|
59
|
+
version: 1.5.14
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
61
|
+
name: rxfreader
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '0.1'
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 0.1.2
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '0.1'
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
79
|
+
version: 0.1.2
|
80
80
|
description:
|
81
81
|
email: digital.robertson@gmail.com
|
82
82
|
executables: []
|
@@ -103,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.7.10
|
106
|
+
rubygems_version: 3.2.22
|
108
107
|
signing_key:
|
109
108
|
specification_version: 4
|
110
109
|
summary: Intended for retrieving HTML templates from a convenient to use Hash-like
|
metadata.gz.sig
CHANGED
Binary file
|