weblet 0.3.0 → 0.3.5

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: a554a34daec79c81fca1f25d822c6d0ceb784f9e86b8420cd6fada8372057995
4
- data.tar.gz: 22ba08494032e5b230e5837baab8c821b23321a3d4cb91b507fe99ca6afa0fd2
3
+ metadata.gz: e27f4831158495cbf179b607ccb378ae7a966d27abf52cb62a2381d45efcbf43
4
+ data.tar.gz: c9e3288adb19d3b9f01288932e852970cfb7ab86922ef8fce7de7e61db7af530
5
5
  SHA512:
6
- metadata.gz: e665e8e8b68bd5fb7de8020b5f648087e4d8abeaf8580118a1f2ea786820dd69f359252ed51a502e171b9b59d9f3928f1ec457502e8eb5e9c52e1c15c632c917
7
- data.tar.gz: be1d18c638b4628bfad7da54e717d476df9b339dc74233f08efa03dc5ca6ddc7ec42b0e377d97197c4dc85f8e04c911073fe817f20e44eed965e83b01791aae6
6
+ metadata.gz: 8b61a25a7e5c1a44e1949f99fa040a1be54e6c534d358de2dda6deee1d5f8353adf4a59405e7eb581e7ee4ce05f4baf34c773b61e3591ecc3e62095df7addec8
7
+ data.tar.gz: 65fd2f1ed959b189c87fd630fef8284db76e4d242ce95f5bd038ce9cc22082e14a080009fb9c2cac29fe2f7d71b79ad8cbd3344fee069265cf922121366af535
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/weblet.rb CHANGED
@@ -49,9 +49,21 @@ class WebletBuilder
49
49
 
50
50
  puts 'x: ' + x.inspect if @debug
51
51
 
52
- if x[0].is_a? String then
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
53
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
@@ -70,7 +82,7 @@ end
70
82
 
71
83
  class Weblet
72
84
 
73
- def initialize(raws, b, marker: nil, debug: false)
85
+ def initialize(raws, marker: nil, debug: false)
74
86
 
75
87
  @debug = debug
76
88
 
@@ -78,9 +90,9 @@ class Weblet
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
 
@@ -88,13 +100,17 @@ class Weblet
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
112
 
97
- @b = args.pop if args.last.is_a? Binding
113
+ b = args.pop if args.last.is_a? Binding
98
114
 
99
115
  if args.first.is_a? String then
100
116
  path = args.first.split('/').map(&:to_sym)
@@ -105,6 +121,9 @@ class Weblet
105
121
  #r = @h.dig *path
106
122
  r = digx(@h, path)
107
123
 
124
+ # check for interpolated substitution tags e.g/ <:card/svg/link>
125
+ r.gsub!(/<:([^>]+)>/) {|x| self.render($1) } if r
126
+
108
127
  puts 'r: ' + r.inspect if @debug
109
128
 
110
129
  if r.nil? then
@@ -112,7 +131,7 @@ class Weblet
112
131
  r = found.cdatas.join if found
113
132
  end
114
133
 
115
- eval('%Q(' + r + ')', @b) if r
134
+ eval('%Q(' + r + ')', b) if r
116
135
 
117
136
  end
118
137
 
@@ -156,4 +175,29 @@ class Weblet
156
175
  end.to_h
157
176
 
158
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
+
159
203
  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.3.0
4
+ version: 0.3.5
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-04 00:00:00.000000000 Z
38
+ date: 2021-04-11 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
metadata.gz.sig CHANGED
Binary file