weblet 0.2.4 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a20edd9605c808815e0aa3cfc7e9779406760cca57fd34db6011c81f2abaa3f2
4
- data.tar.gz: 1b99f0adc8fde98fe110fb06783644c3245ced80a4c5b03a4aa6f8bb20410e1e
3
+ metadata.gz: c38324cb006650b466537f08eb043e9fa44249e8d8046e4a05e318a12750aacc
4
+ data.tar.gz: e41b0ccb1fde8b1c318cc7cd371da07ddbc93a30d670df52af8d9cab8e7f7442
5
5
  SHA512:
6
- metadata.gz: 3e7690b5ee283aee9c596e4496c738b756579801c54994bf0761e78a3a0825f9968eb84c5998675d3b6c8daf6a958a682872712f34a94631c60c74748cc3a156
7
- data.tar.gz: 1aef800f17899e8b11e48bac43fdbfa254e848ff3db59ea840da8b2ecbfd7808cef3a4ff6257adda2b3a351f7bfedc8c36806769f5e91f07b897084a97c7f768
6
+ metadata.gz: 78f84ff8aa3bc2913fed7b1cdb037855ddec86305b5dc79a2d2fefa331cb6c21b45c4d3377c431625c4d96409edf51ffeaf8b06ebd5b25fdb1fc6cdd52003bdf
7
+ data.tar.gz: 9b694e463e7ac4e52b1c61dc9645e296eb359e35ff974362c0139a83747cb3c018f599c87100ecec0b1db09a21dbb4b72317c98ff1051c1267dad286a3808f7d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- Nl�흢�>)�{`Bz�zp(RčQ ��'C16mN��{s���$�"rצB�P����.�b��=y�\pcq4A�G�ꓒ��sxuO[�w�����������Z�9
2
- iS��M��,��l�?
3
- r�{���9���uD
1
+ D��v�/�ƅ�Bw^Y�<5E��VLn�K�B~��}[nI>�e1| J��$����qՕ�^���G��Ƽ�d��t#P�j���� �� C4}j��E�`X��N3���fޱ2��
2
+ OQ�x>�0��'ՓM��.Γ(�W�Ȍ�w?�3r�O���D> �A)t�1)ԾE ��t!ݷ��-����Et�?\
data/lib/weblet.rb CHANGED
@@ -56,7 +56,9 @@ class WebletBuilder
56
56
 
57
57
  elsif x[0] and x[0].is_a? Array
58
58
 
59
- [:node, {id: x[0][0][/#{@marker}(\w+)/,1]}, '', *build(x[1..-1])]
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])]
60
62
 
61
63
  end
62
64
 
@@ -68,7 +70,7 @@ end
68
70
 
69
71
  class Weblet
70
72
 
71
- def initialize(raws, b, marker: nil, debug: false)
73
+ def initialize(raws, marker: nil, debug: false)
72
74
 
73
75
  @debug = debug
74
76
 
@@ -78,7 +80,6 @@ class Weblet
78
80
  debug: debug).to_a
79
81
  @doc = Rexle.new(obj)
80
82
  @h = scan @doc.root
81
- @b = b
82
83
 
83
84
  end
84
85
 
@@ -86,11 +87,17 @@ class Weblet
86
87
  @h
87
88
  end
88
89
 
90
+ def to_outline()
91
+ treeize(scan_h(@h))
92
+ end
93
+
89
94
  def to_xml()
90
95
  @doc.root.xml pretty: true
91
96
  end
92
97
 
93
- def render(*args, b=@b)
98
+ def render(*args)
99
+
100
+ b = args.pop if args.last.is_a? Binding
94
101
 
95
102
  if args.first.is_a? String then
96
103
  path = args.first.split('/').map(&:to_sym)
@@ -98,7 +105,13 @@ class Weblet
98
105
  path = *args.flatten(1)
99
106
  end
100
107
 
101
- r = @h.dig *path
108
+ #r = @h.dig *path
109
+ r = digx(@h, path)
110
+
111
+ # check for interpolated substitution tags e.g/ <:card/svg/link>
112
+ r.gsub!(/<:([^>]+)>/) {|x| self.render($1) } if r
113
+
114
+ puts 'r: ' + r.inspect if @debug
102
115
 
103
116
  if r.nil? then
104
117
  found = @doc.root.element("//node[@id='#{path.join}']")
@@ -110,6 +123,20 @@ class Weblet
110
123
  end
111
124
 
112
125
  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
113
140
 
114
141
  def scan(node)
115
142
 
@@ -121,11 +148,43 @@ class Weblet
121
148
 
122
149
  puts 'nodes: ' + nodes.inspect if @debug
123
150
 
124
- r = nodes.any? ? scan(e) : e.cdatas.join()
151
+ r = if nodes.any? then
152
+
153
+ r2 = scan(e)
154
+ e.cdatas.any? ? [e.cdatas.join(), r2] : r2
155
+
156
+ else
157
+ e.cdatas.join()
158
+ end
125
159
 
126
160
  [e.attributes[:id].to_sym, r]
127
161
 
128
162
  end.to_h
129
163
 
130
164
  end
165
+
166
+ def scan_h(h)
167
+
168
+ a = h.map do |key, value|
169
+ value.is_a?(Array) ? [key, scan_h(value.last)] : [key]
170
+ end
171
+
172
+ end
173
+
174
+ def treeize(a, indent=-2)
175
+
176
+ indent += 1
177
+ a.map do |x|
178
+
179
+ if x.is_a? Symbol then
180
+ (' ' * indent) + x.to_s
181
+ else
182
+ treeize(x, indent)
183
+ end
184
+
185
+ end.join("\n")
186
+
187
+ end
188
+
189
+
131
190
  end
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.2.4
4
+ version: 0.3.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-03 00:00:00.000000000 Z
38
+ date: 2021-04-06 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
metadata.gz.sig CHANGED
Binary file