weblet 0.1.0 → 0.2.4
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.tar.gz.sig +0 -0
- data/lib/weblet.rb +57 -21
- metadata +24 -4
- 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: a20edd9605c808815e0aa3cfc7e9779406760cca57fd34db6011c81f2abaa3f2
|
4
|
+
data.tar.gz: 1b99f0adc8fde98fe110fb06783644c3245ced80a4c5b03a4aa6f8bb20410e1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e7690b5ee283aee9c596e4496c738b756579801c54994bf0761e78a3a0825f9968eb84c5998675d3b6c8daf6a958a682872712f34a94631c60c74748cc3a156
|
7
|
+
data.tar.gz: 1aef800f17899e8b11e48bac43fdbfa254e848ff3db59ea840da8b2ecbfd7808cef3a4ff6257adda2b3a351f7bfedc8c36806769f5e91f07b897084a97c7f768
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/weblet.rb
CHANGED
@@ -3,13 +3,25 @@
|
|
3
3
|
# file: weblet.rb
|
4
4
|
|
5
5
|
require 'rexle'
|
6
|
+
require 'rxfhelper'
|
6
7
|
|
7
8
|
|
8
9
|
class WebletBuilder
|
9
10
|
|
10
|
-
def initialize(s)
|
11
|
+
def initialize(s, marker: nil, debug: false)
|
11
12
|
|
12
|
-
@
|
13
|
+
@marker, @debug = marker, debug
|
14
|
+
|
15
|
+
s.strip!
|
16
|
+
|
17
|
+
# the default marker is the hash symbol (#) but the client can set their
|
18
|
+
# own marker by simply using their custom symbol in the 1st line of input
|
19
|
+
@marker ||= s[0]
|
20
|
+
|
21
|
+
a = scan(s.strip)
|
22
|
+
puts 'a: ' + a.inspect if @debug
|
23
|
+
|
24
|
+
@a = build(a)
|
13
25
|
@a.unshift *['weblet', {}, '']
|
14
26
|
|
15
27
|
end
|
@@ -22,7 +34,7 @@ class WebletBuilder
|
|
22
34
|
|
23
35
|
def scan(s, indent=0)
|
24
36
|
|
25
|
-
a = s.split(/(?=^#{' ' * indent}
|
37
|
+
a = s.split(/(?=^#{(' ' * indent) + @marker})/)
|
26
38
|
return a unless a.length > 1
|
27
39
|
|
28
40
|
a.map {|x| scan(x, indent+1)}
|
@@ -31,15 +43,21 @@ class WebletBuilder
|
|
31
43
|
|
32
44
|
def build(a)
|
33
45
|
|
46
|
+
puts 'a: ' + a.inspect if @debug
|
47
|
+
|
34
48
|
a.map do |x|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
x.
|
41
|
-
head,
|
42
|
-
|
49
|
+
|
50
|
+
puts 'x: ' + x.inspect if @debug
|
51
|
+
|
52
|
+
if x[0].is_a? String then
|
53
|
+
|
54
|
+
head, body = x[0].split("\n", 2)
|
55
|
+
[:node, {id: head[/#{@marker}(\w+)/,1]}, '',['![', {}, body.strip]]
|
56
|
+
|
57
|
+
elsif x[0] and x[0].is_a? Array
|
58
|
+
|
59
|
+
[:node, {id: x[0][0][/#{@marker}(\w+)/,1]}, '', *build(x[1..-1])]
|
60
|
+
|
43
61
|
end
|
44
62
|
|
45
63
|
end
|
@@ -50,12 +68,16 @@ end
|
|
50
68
|
|
51
69
|
class Weblet
|
52
70
|
|
53
|
-
def initialize(raws, b)
|
71
|
+
def initialize(raws, b, marker: nil, debug: false)
|
72
|
+
|
73
|
+
@debug = debug
|
74
|
+
|
75
|
+
s, _ = RXFHelper.read(raws.strip)
|
54
76
|
|
55
|
-
|
56
|
-
|
57
|
-
doc = Rexle.new(obj)
|
58
|
-
@h = scan doc.root
|
77
|
+
obj = s[0] == '<' ? s : WebletBuilder.new(s, marker: marker, \
|
78
|
+
debug: debug).to_a
|
79
|
+
@doc = Rexle.new(obj)
|
80
|
+
@h = scan @doc.root
|
59
81
|
@b = b
|
60
82
|
|
61
83
|
end
|
@@ -63,17 +85,27 @@ class Weblet
|
|
63
85
|
def to_h()
|
64
86
|
@h
|
65
87
|
end
|
88
|
+
|
89
|
+
def to_xml()
|
90
|
+
@doc.root.xml pretty: true
|
91
|
+
end
|
66
92
|
|
67
|
-
def render(*args)
|
93
|
+
def render(*args, b=@b)
|
68
94
|
|
69
95
|
if args.first.is_a? String then
|
70
|
-
path = args.first.split('/'
|
96
|
+
path = args.first.split('/').map(&:to_sym)
|
71
97
|
else
|
72
98
|
path = *args.flatten(1)
|
73
99
|
end
|
74
100
|
|
75
101
|
r = @h.dig *path
|
76
|
-
|
102
|
+
|
103
|
+
if r.nil? then
|
104
|
+
found = @doc.root.element("//node[@id='#{path.join}']")
|
105
|
+
r = found.cdatas.join if found
|
106
|
+
end
|
107
|
+
|
108
|
+
eval('%Q(' + r + ')', b) if r
|
77
109
|
|
78
110
|
end
|
79
111
|
|
@@ -82,10 +114,14 @@ class Weblet
|
|
82
114
|
def scan(node)
|
83
115
|
|
84
116
|
a = node.elements.map do |e|
|
117
|
+
|
118
|
+
puts 'e: ' + e.inspect if @debug
|
85
119
|
|
86
120
|
nodes = e.xpath('node')
|
87
|
-
|
88
|
-
|
121
|
+
|
122
|
+
puts 'nodes: ' + nodes.inspect if @debug
|
123
|
+
|
124
|
+
r = nodes.any? ? scan(e) : e.cdatas.join()
|
89
125
|
|
90
126
|
[e.attributes[:id].to_sym, r]
|
91
127
|
|
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.4
|
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
|
@@ -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.11
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -56,7 +56,27 @@ dependencies:
|
|
56
56
|
version: '1.5'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.5.
|
59
|
+
version: 1.5.11
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rxfhelper
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.1'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1.3
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.1'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.1.3
|
60
80
|
description:
|
61
81
|
email: digital.robertson@gmail.com
|
62
82
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|