weblet 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/weblet.rb +34 -11
- metadata +2 -2
- 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: db2437f118c3c20ae3793072517fb43614ab736e31ceddb2e94c25e9f5f7f2f6
|
4
|
+
data.tar.gz: 2624d3afc74ac2dc93867e4423614c483b6f26f091f27c081335210799d93222
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b464034193c7a1972c1554423198bb48a3b07cf97737b278c048d25ee59bbfa2b189514a6b35143e9d1352b0c1f1dae4b27afdc85c1c54bf77733a7392f92b3a
|
7
|
+
data.tar.gz: b715617193855dbbde52a3ac3dd78bc22ab6c1af7643c6a329f78f778f5d7018c09f3b92a07edd01c86890609a71777911a1d7de17be041d515e635418fb4bd2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/weblet.rb
CHANGED
@@ -7,8 +7,9 @@ require 'rexle'
|
|
7
7
|
|
8
8
|
class WebletBuilder
|
9
9
|
|
10
|
-
def initialize(s)
|
10
|
+
def initialize(s, debug: false)
|
11
11
|
|
12
|
+
@debug = debug
|
12
13
|
@a = build(scan(s.strip))
|
13
14
|
@a.unshift *['weblet', {}, '']
|
14
15
|
|
@@ -32,13 +33,19 @@ class WebletBuilder
|
|
32
33
|
def build(a)
|
33
34
|
|
34
35
|
a.map do |x|
|
35
|
-
|
36
|
+
|
37
|
+
puts 'x: ' + x.inspect if @debug
|
38
|
+
|
36
39
|
if x.is_a? String then
|
37
|
-
head, body = x.split("\n",2)
|
38
|
-
[:node, {id: head[/#(\w+)/,1]}, body.strip]
|
40
|
+
head, body = x.split("\n", 2)
|
41
|
+
[:node, {id: head[/#(\w+)/,1]}, '',['![', {}, body.strip]]
|
42
|
+
elsif x.length < 2
|
43
|
+
x.flatten!(1)
|
44
|
+
head, body = x.shift.split("\n", 2)
|
45
|
+
[:node, {id: head[/#(\w+)/,1].rstrip}, '',['![', {}, body.rstrip, ]]
|
39
46
|
else
|
40
47
|
x.flatten!(1)
|
41
|
-
head, body = x.shift.split("\n",2)
|
48
|
+
head, body = x.shift.split("\n", 2)
|
42
49
|
[:node, {id: head[/#(\w+)/,1].rstrip}, body.rstrip, *build(x)]
|
43
50
|
end
|
44
51
|
|
@@ -50,12 +57,14 @@ end
|
|
50
57
|
|
51
58
|
class Weblet
|
52
59
|
|
53
|
-
def initialize(raws, b)
|
60
|
+
def initialize(raws, b, debug: false)
|
61
|
+
|
62
|
+
@debug = debug
|
54
63
|
|
55
64
|
raws.strip!
|
56
|
-
obj = raws[0] == '<' ? raws : WebletBuilder.new(raws).to_a
|
57
|
-
doc = Rexle.new(obj)
|
58
|
-
@h = scan doc.root
|
65
|
+
obj = raws[0] == '<' ? raws : WebletBuilder.new(raws, debug: debug).to_a
|
66
|
+
@doc = Rexle.new(obj)
|
67
|
+
@h = scan @doc.root
|
59
68
|
@b = b
|
60
69
|
|
61
70
|
end
|
@@ -63,6 +72,10 @@ class Weblet
|
|
63
72
|
def to_h()
|
64
73
|
@h
|
65
74
|
end
|
75
|
+
|
76
|
+
def to_xml()
|
77
|
+
@doc.root.xml pretty: true
|
78
|
+
end
|
66
79
|
|
67
80
|
def render(*args)
|
68
81
|
|
@@ -73,6 +86,12 @@ class Weblet
|
|
73
86
|
end
|
74
87
|
|
75
88
|
r = @h.dig *path
|
89
|
+
|
90
|
+
if r.nil? then
|
91
|
+
found = @doc.root.element("//node[@id='#{path.join}']")
|
92
|
+
r = found.cdatas.join if found
|
93
|
+
end
|
94
|
+
|
76
95
|
eval('%Q(' + r + ')', @b) if r
|
77
96
|
|
78
97
|
end
|
@@ -82,10 +101,14 @@ class Weblet
|
|
82
101
|
def scan(node)
|
83
102
|
|
84
103
|
a = node.elements.map do |e|
|
104
|
+
|
105
|
+
puts 'e: ' + e.inspect if @debug
|
85
106
|
|
86
107
|
nodes = e.xpath('node')
|
87
|
-
|
88
|
-
|
108
|
+
|
109
|
+
puts 'nodes: ' + nodes.inspect if @debug
|
110
|
+
|
111
|
+
r = nodes.any? ? scan(e) : e.cdatas.join()
|
89
112
|
|
90
113
|
[e.attributes[:id].to_sym, r]
|
91
114
|
|
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.2.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: 2021-04-
|
38
|
+
date: 2021-04-03 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rexle
|
metadata.gz.sig
CHANGED
Binary file
|