weblet 0.2.0 → 0.3.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 +62 -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: a554a34daec79c81fca1f25d822c6d0ceb784f9e86b8420cd6fada8372057995
|
4
|
+
data.tar.gz: 22ba08494032e5b230e5837baab8c821b23321a3d4cb91b507fe99ca6afa0fd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e665e8e8b68bd5fb7de8020b5f648087e4d8abeaf8580118a1f2ea786820dd69f359252ed51a502e171b9b59d9f3928f1ec457502e8eb5e9c52e1c15c632c917
|
7
|
+
data.tar.gz: be1d18c638b4628bfad7da54e717d476df9b339dc74233f08efa03dc5ca6ddc7ec42b0e377d97197c4dc85f8e04c911073fe817f20e44eed965e83b01791aae6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/weblet.rb
CHANGED
@@ -3,14 +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, debug: false)
|
11
|
+
def initialize(s, marker: nil, debug: false)
|
11
12
|
|
12
|
-
@debug = debug
|
13
|
-
|
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)
|
14
25
|
@a.unshift *['weblet', {}, '']
|
15
26
|
|
16
27
|
end
|
@@ -23,7 +34,7 @@ class WebletBuilder
|
|
23
34
|
|
24
35
|
def scan(s, indent=0)
|
25
36
|
|
26
|
-
a = s.split(/(?=^#{' ' * indent}
|
37
|
+
a = s.split(/(?=^#{(' ' * indent) + @marker})/)
|
27
38
|
return a unless a.length > 1
|
28
39
|
|
29
40
|
a.map {|x| scan(x, indent+1)}
|
@@ -32,21 +43,23 @@ class WebletBuilder
|
|
32
43
|
|
33
44
|
def build(a)
|
34
45
|
|
46
|
+
puts 'a: ' + a.inspect if @debug
|
47
|
+
|
35
48
|
a.map do |x|
|
36
49
|
|
37
50
|
puts 'x: ' + x.inspect if @debug
|
38
51
|
|
39
|
-
if x.is_a? String then
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
+
head, body = x[0][0].split("\n", 2)
|
60
|
+
[:node, {id: head[/#{@marker}(\w+)/,1]}, '', \
|
61
|
+
['![', {}, body.to_s.strip], *build(x[1..-1])]
|
62
|
+
|
50
63
|
end
|
51
64
|
|
52
65
|
end
|
@@ -57,12 +70,14 @@ end
|
|
57
70
|
|
58
71
|
class Weblet
|
59
72
|
|
60
|
-
def initialize(raws, b, debug: false)
|
73
|
+
def initialize(raws, b, marker: nil, debug: false)
|
61
74
|
|
62
75
|
@debug = debug
|
76
|
+
|
77
|
+
s, _ = RXFHelper.read(raws.strip)
|
63
78
|
|
64
|
-
|
65
|
-
|
79
|
+
obj = s[0] == '<' ? s : WebletBuilder.new(s, marker: marker, \
|
80
|
+
debug: debug).to_a
|
66
81
|
@doc = Rexle.new(obj)
|
67
82
|
@h = scan @doc.root
|
68
83
|
@b = b
|
@@ -79,13 +94,18 @@ class Weblet
|
|
79
94
|
|
80
95
|
def render(*args)
|
81
96
|
|
97
|
+
@b = args.pop if args.last.is_a? Binding
|
98
|
+
|
82
99
|
if args.first.is_a? String then
|
83
|
-
path = args.first.split('/'
|
100
|
+
path = args.first.split('/').map(&:to_sym)
|
84
101
|
else
|
85
102
|
path = *args.flatten(1)
|
86
103
|
end
|
87
104
|
|
88
|
-
r = @h.dig *path
|
105
|
+
#r = @h.dig *path
|
106
|
+
r = digx(@h, path)
|
107
|
+
|
108
|
+
puts 'r: ' + r.inspect if @debug
|
89
109
|
|
90
110
|
if r.nil? then
|
91
111
|
found = @doc.root.element("//node[@id='#{path.join}']")
|
@@ -97,6 +117,20 @@ class Weblet
|
|
97
117
|
end
|
98
118
|
|
99
119
|
private
|
120
|
+
|
121
|
+
def digx(obj, a)
|
122
|
+
|
123
|
+
h = obj.is_a?(Array) ? obj.last : obj
|
124
|
+
|
125
|
+
r = h.dig(a.shift)
|
126
|
+
|
127
|
+
if a.any? then
|
128
|
+
digx(r, a)
|
129
|
+
else
|
130
|
+
r.is_a?(Array) ? r.first : r
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
100
134
|
|
101
135
|
def scan(node)
|
102
136
|
|
@@ -108,7 +142,14 @@ class Weblet
|
|
108
142
|
|
109
143
|
puts 'nodes: ' + nodes.inspect if @debug
|
110
144
|
|
111
|
-
r = nodes.any?
|
145
|
+
r = if nodes.any? then
|
146
|
+
|
147
|
+
r2 = scan(e)
|
148
|
+
e.cdatas.any? ? [e.cdatas.join(), r2] : r2
|
149
|
+
|
150
|
+
else
|
151
|
+
e.cdatas.join()
|
152
|
+
end
|
112
153
|
|
113
154
|
[e.attributes[:id].to_sym, r]
|
114
155
|
|
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.3.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-04 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
|