weblet 0.3.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/weblet.rb +92 -71
  4. data.tar.gz.sig +0 -0
  5. metadata +32 -33
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c38324cb006650b466537f08eb043e9fa44249e8d8046e4a05e318a12750aacc
4
- data.tar.gz: e41b0ccb1fde8b1c318cc7cd371da07ddbc93a30d670df52af8d9cab8e7f7442
3
+ metadata.gz: 9cdf3dd81231ca9ee4385a6bb250af42f86677e30951cea62e74c5dac3a2ed19
4
+ data.tar.gz: 0f5aead405414359f202d14c97f4da26fb102d55a5b077822a4f2ebf1087c5d1
5
5
  SHA512:
6
- metadata.gz: 78f84ff8aa3bc2913fed7b1cdb037855ddec86305b5dc79a2d2fefa331cb6c21b45c4d3377c431625c4d96409edf51ffeaf8b06ebd5b25fdb1fc6cdd52003bdf
7
- data.tar.gz: 9b694e463e7ac4e52b1c61dc9645e296eb359e35ff974362c0139a83747cb3c018f599c87100ecec0b1db09a21dbb4b72317c98ff1051c1267dad286a3808f7d
6
+ metadata.gz: c2062764f51b7343e8800a9e32a823efed674af59c8e088705916e53da12b61d61c5f42ae7778940fb1f214507e672bdbb4d1dc460219ca585f23dc7a8624c7e
7
+ data.tar.gz: 6bca43e05423533b06f0ad10645c0ef8e0d9376a6335d6a26302946d18e6f8cbf0db1941da34b7c112896e1d73248111c76509e52ede277c17b0f0d70726454c
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/weblet.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # file: weblet.rb
4
4
 
5
5
  require 'rexle'
6
- require 'rxfhelper'
6
+ require 'rxfreader'
7
7
 
8
8
 
9
9
  class WebletBuilder
@@ -11,19 +11,19 @@ class WebletBuilder
11
11
  def initialize(s, marker: nil, debug: false)
12
12
 
13
13
  @marker, @debug = marker, debug
14
-
14
+
15
15
  s.strip!
16
-
17
- # the default marker is the hash symbol (#) but the client can set their
16
+
17
+ # the default marker is the hash symbol (#) but the client can set their
18
18
  # own marker by simply using their custom symbol in the 1st line of input
19
19
  @marker ||= s[0]
20
-
20
+
21
21
  a = scan(s.strip)
22
22
  puts 'a: ' + a.inspect if @debug
23
-
23
+
24
24
  @a = build(a)
25
25
  @a.unshift *['weblet', {}, '']
26
-
26
+
27
27
  end
28
28
 
29
29
  def to_a()
@@ -38,30 +38,42 @@ class WebletBuilder
38
38
  return a unless a.length > 1
39
39
 
40
40
  a.map {|x| scan(x, indent+1)}
41
-
41
+
42
42
  end
43
43
 
44
44
  def build(a)
45
45
 
46
46
  puts 'a: ' + a.inspect if @debug
47
-
47
+
48
48
  a.map do |x|
49
-
49
+
50
50
  puts 'x: ' + x.inspect if @debug
51
-
52
- if x[0].is_a? String then
53
-
51
+
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
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
58
-
70
+
59
71
  head, body = x[0][0].split("\n", 2)
60
72
  [:node, {id: head[/#{@marker}(\w+)/,1]}, '', \
61
73
  ['![', {}, body.to_s.strip], *build(x[1..-1])]
62
-
74
+
63
75
  end
64
-
76
+
65
77
  end
66
78
 
67
79
  end
@@ -71,98 +83,80 @@ end
71
83
  class Weblet
72
84
 
73
85
  def initialize(raws, marker: nil, debug: false)
74
-
86
+
75
87
  @debug = debug
76
-
77
- s, _ = RXFHelper.read(raws.strip)
88
+
89
+ s, _ = RXFReader.read(raws.strip)
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
96
+ @kvp = scan2keypair(@h).to_h
97
+
98
+ end
83
99
 
100
+ def [](key)
101
+ @kvp[key.to_s]
102
+ end
103
+
104
+ def []=(key, value)
105
+ @kvp[key.to_s] = value
84
106
  end
85
107
 
86
108
  def to_h()
87
109
  @h
88
110
  end
89
-
111
+
112
+ # key-value pair
113
+ def to_kvp()
114
+ @kvp
115
+ end
116
+
90
117
  def to_outline()
91
118
  treeize(scan_h(@h))
92
119
  end
93
-
120
+
94
121
  def to_xml()
95
122
  @doc.root.xml pretty: true
96
123
  end
97
124
 
98
- def render(*args)
99
-
100
- b = args.pop if args.last.is_a? Binding
101
-
102
- if args.first.is_a? String then
103
- path = args.first.split('/').map(&:to_sym)
104
- else
105
- path = *args.flatten(1)
106
- end
125
+ def render(rawkey, bindingx=nil)
126
+
127
+ key = rawkey.to_s
128
+ return unless @kvp.has_key?(key)
107
129
 
108
- #r = @h.dig *path
109
- r = digx(@h, path)
110
-
111
130
  # 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
115
-
116
- if r.nil? then
117
- found = @doc.root.element("//node[@id='#{path.join}']")
118
- r = found.cdatas.join if found
119
- end
120
-
121
- eval('%Q(' + r + ')', b) if r
131
+ r = @kvp[key].gsub(/<:([^>]+)>/) {|x| self.render($1) }
132
+
133
+ eval('%Q(' + r + ')', bindingx)
122
134
 
123
135
  end
124
136
 
125
137
  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
140
138
 
141
139
  def scan(node)
142
140
 
143
141
  a = node.elements.map do |e|
144
-
145
- puts 'e: ' + e.inspect if @debug
146
142
 
147
143
  nodes = e.xpath('node')
148
-
149
- puts 'nodes: ' + nodes.inspect if @debug
150
-
144
+
151
145
  r = if nodes.any? then
152
-
146
+
153
147
  r2 = scan(e)
154
148
  e.cdatas.any? ? [e.cdatas.join(), r2] : r2
155
-
149
+
156
150
  else
157
151
  e.cdatas.join()
158
152
  end
159
153
 
160
154
  [e.attributes[:id].to_sym, r]
161
-
155
+
162
156
  end.to_h
163
-
157
+
164
158
  end
165
-
159
+
166
160
  def scan_h(h)
167
161
 
168
162
  a = h.map do |key, value|
@@ -170,7 +164,7 @@ class Weblet
170
164
  end
171
165
 
172
166
  end
173
-
167
+
174
168
  def treeize(a, indent=-2)
175
169
 
176
170
  indent += 1
@@ -185,6 +179,33 @@ class Weblet
185
179
  end.join("\n")
186
180
 
187
181
  end
188
-
189
-
182
+
183
+ def scan2keypair(h, trail=nil)
184
+
185
+ h.inject([]) do |r,x|
186
+
187
+ if x.last.is_a? String then
188
+
189
+ key, val = x
190
+
191
+ new_key = if r.last and r.last.first.length > 0 then
192
+ key.to_s
193
+ else
194
+ key.to_s
195
+ end
196
+
197
+ r << [[trail, new_key].compact.join('/'), val]
198
+
199
+ else
200
+
201
+ new_key = x.first.to_s
202
+ r << [new_key, x.last.first]
203
+ r.concat scan2keypair(x.last.last, [trail, new_key].compact.join('/'))
204
+
205
+ end
206
+
207
+ end
208
+
209
+ end
210
+
190
211
  end
data.tar.gz.sig CHANGED
Binary file
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.4
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,31 +11,31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04-19 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.11
49
+ version: 1.5.14
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,27 +56,27 @@ dependencies:
56
56
  version: '1.5'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.5.11
59
+ version: 1.5.14
60
60
  - !ruby/object:Gem::Dependency
61
- name: rxfhelper
61
+ name: rxfreader
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '1.1'
66
+ version: '0.1'
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 1.1.3
69
+ version: 0.1.2
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '1.1'
76
+ version: '0.1'
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: 1.1.3
79
+ version: 0.1.2
80
80
  description:
81
81
  email: digital.robertson@gmail.com
82
82
  executables: []
@@ -103,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.7.10
106
+ rubygems_version: 3.2.22
108
107
  signing_key:
109
108
  specification_version: 4
110
109
  summary: Intended for retrieving HTML templates from a convenient to use Hash-like
metadata.gz.sig CHANGED
Binary file