weblet 0.3.2 → 0.4.0
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 +81 -40
- data.tar.gz.sig +0 -0
- metadata +10 -11
- 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: 44c3165f75000e5c2ad59d99ab37d672a631389fb1241b9e739ccf58aaf64b5d
|
4
|
+
data.tar.gz: 371470bb1005b3291e69cbba8d8d04a17c1afc4ae876cded7f30c0277362700c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e76ced239f76106bd12abe6733dabed1f197c381dc868a785d59e16f66f34be08bb5defa704b031403f5e680a15511afa59361cc7fe309e83b5a4919a6d7c08e
|
7
|
+
data.tar.gz: 0c4fe8b26f780ca467f6e53ddfcd9852ff7c10a88a2925cd1909ba3179199a358adcf5ec282f29c3f003b93327c431473fd4df6483c51495fb3490d6043c93a7
|
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
|
@@ -70,32 +82,36 @@ end
|
|
70
82
|
|
71
83
|
class Weblet
|
72
84
|
|
73
|
-
def initialize(raws,
|
74
|
-
|
85
|
+
def initialize(raws, marker: nil, debug: false)
|
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
|
83
|
-
@b = b
|
84
96
|
|
85
97
|
end
|
86
98
|
|
87
99
|
def to_h()
|
88
100
|
@h
|
89
101
|
end
|
90
|
-
|
102
|
+
|
103
|
+
def to_outline()
|
104
|
+
treeize(scan_h(@h))
|
105
|
+
end
|
106
|
+
|
91
107
|
def to_xml()
|
92
108
|
@doc.root.xml pretty: true
|
93
109
|
end
|
94
110
|
|
95
111
|
def render(*args)
|
96
|
-
|
97
|
-
|
98
|
-
|
112
|
+
|
113
|
+
b = args.pop if args.last.is_a? Binding
|
114
|
+
|
99
115
|
if args.first.is_a? String then
|
100
116
|
path = args.first.split('/').map(&:to_sym)
|
101
117
|
else
|
@@ -104,23 +120,23 @@ class Weblet
|
|
104
120
|
|
105
121
|
#r = @h.dig *path
|
106
122
|
r = digx(@h, path)
|
107
|
-
|
123
|
+
|
108
124
|
# check for interpolated substitution tags e.g/ <:card/svg/link>
|
109
125
|
r.gsub!(/<:([^>]+)>/) {|x| self.render($1) } if r
|
110
|
-
|
126
|
+
|
111
127
|
puts 'r: ' + r.inspect if @debug
|
112
|
-
|
128
|
+
|
113
129
|
if r.nil? then
|
114
130
|
found = @doc.root.element("//node[@id='#{path.join}']")
|
115
131
|
r = found.cdatas.join if found
|
116
132
|
end
|
117
|
-
|
118
|
-
eval('%Q(' + r + ')',
|
133
|
+
|
134
|
+
eval('%Q(' + r + ')', b) if r
|
119
135
|
|
120
136
|
end
|
121
137
|
|
122
138
|
private
|
123
|
-
|
139
|
+
|
124
140
|
def digx(obj, a)
|
125
141
|
|
126
142
|
h = obj.is_a?(Array) ? obj.last : obj
|
@@ -133,30 +149,55 @@ class Weblet
|
|
133
149
|
r.is_a?(Array) ? r.first : r
|
134
150
|
end
|
135
151
|
|
136
|
-
end
|
152
|
+
end
|
137
153
|
|
138
154
|
def scan(node)
|
139
155
|
|
140
156
|
a = node.elements.map do |e|
|
141
|
-
|
157
|
+
|
142
158
|
puts 'e: ' + e.inspect if @debug
|
143
159
|
|
144
160
|
nodes = e.xpath('node')
|
145
|
-
|
161
|
+
|
146
162
|
puts 'nodes: ' + nodes.inspect if @debug
|
147
|
-
|
163
|
+
|
148
164
|
r = if nodes.any? then
|
149
|
-
|
165
|
+
|
150
166
|
r2 = scan(e)
|
151
167
|
e.cdatas.any? ? [e.cdatas.join(), r2] : r2
|
152
|
-
|
168
|
+
|
153
169
|
else
|
154
170
|
e.cdatas.join()
|
155
171
|
end
|
156
172
|
|
157
173
|
[e.attributes[:id].to_sym, r]
|
158
|
-
|
174
|
+
|
159
175
|
end.to_h
|
160
|
-
|
176
|
+
|
161
177
|
end
|
178
|
+
|
179
|
+
def scan_h(h)
|
180
|
+
|
181
|
+
a = h.map do |key, value|
|
182
|
+
value.is_a?(Array) ? [key, scan_h(value.last)] : [key]
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
def treeize(a, indent=-2)
|
188
|
+
|
189
|
+
indent += 1
|
190
|
+
a.map do |x|
|
191
|
+
|
192
|
+
if x.is_a? Symbol then
|
193
|
+
(' ' * indent) + x.to_s
|
194
|
+
else
|
195
|
+
treeize(x, indent)
|
196
|
+
end
|
197
|
+
|
198
|
+
end.join("\n")
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
|
162
203
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
mKbvoKGru7nPXh4E/ArWQ70Yz24o3lwGZW3XLzwdLPKB8MiOOGuTARkCWFEYT5tE
|
36
36
|
We42rjyhFeidBuSZp6/7Wwlo
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-02-21 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
|