weblet 0.2.1 → 0.3.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.tar.gz.sig +0 -0
  4. data/lib/weblet.rb +60 -18
  5. metadata +24 -4
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab44a31aac8707efb70785c2ed488d5ee1a1db55c7eece43369bf6c011a98011
4
- data.tar.gz: db483e53188fde625e1ad1ee9f0309e6f837005f4a115ccfa49291aee179721b
3
+ metadata.gz: 032dd5ce3fc7237ea08c37f074873ef744afff5a35d51a16aeb293786d60fbf8
4
+ data.tar.gz: db870c39d48a31a3cd50f063212a7582a3656464f26b2f5db1fde340153d17c0
5
5
  SHA512:
6
- metadata.gz: ec04da0a74d5e73bd5d5392332293499ce21bbc8794d6287118b63f65e3655be09e986da7bd72915aa8dfa59489999c5439b3585c0f2dd8c2b9f60c52b3c9658
7
- data.tar.gz: 9d18a68fed44fc9e096275c19b64c193f7245f7f294672d0cc513846c333e109c0e09d5bc5d312be807c59eb96a8371c0ea0fe7b17e969ebbc7ecb350a92ab1f
6
+ metadata.gz: 9bbefcb010f857e04619611f848505059fd00c1dba11efb12ba97677cd4e9e079bf136e86f04ce2728137072f4080fab7e8994db8a927233fa26e96abb56f57f
7
+ data.tar.gz: c6c07b881b3dbe33aceeb1afb85dc37dd5db60411ccd8e3e93254bb9501bcd18a67b8b5289abde84dbb7240cf0fc96927bb2214c8fa5e485c32f0bb4cb7a058a
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/weblet.rb CHANGED
@@ -3,15 +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, marker: '#', debug: false)
11
+ def initialize(s, marker: nil, debug: false)
11
12
 
12
13
  @marker, @debug = marker, debug
13
14
 
14
- @a = build(scan(s.strip))
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)
15
25
  @a.unshift *['weblet', {}, '']
16
26
 
17
27
  end
@@ -33,21 +43,23 @@ class WebletBuilder
33
43
 
34
44
  def build(a)
35
45
 
46
+ puts 'a: ' + a.inspect if @debug
47
+
36
48
  a.map do |x|
37
49
 
38
50
  puts 'x: ' + x.inspect if @debug
39
51
 
40
- if x.is_a? String then
41
- head, body = x.split("\n", 2)
52
+ if x[0].is_a? String then
53
+
54
+ head, body = x[0].split("\n", 2)
42
55
  [:node, {id: head[/#{@marker}(\w+)/,1]}, '',['![', {}, body.strip]]
43
- elsif x.length < 2
44
- x.flatten!(1)
45
- head, body = x.shift.split("\n", 2)
46
- [:node, {id: head[/#{@marker}(\w+)/,1].rstrip}, '',['![', {}, body.rstrip, ]]
47
- else
48
- x.flatten!(1)
49
- head, body = x.shift.split("\n", 2)
50
- [:node, {id: head[/#{@marker}(\w+)/,1].rstrip}, body.rstrip, *build(x)]
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
+
51
63
  end
52
64
 
53
65
  end
@@ -58,12 +70,13 @@ end
58
70
 
59
71
  class Weblet
60
72
 
61
- def initialize(raws, b, marker: '#', debug: false)
73
+ def initialize(raws, b, marker: nil, debug: false)
62
74
 
63
75
  @debug = debug
76
+
77
+ s, _ = RXFHelper.read(raws.strip)
64
78
 
65
- raws.strip!
66
- obj = raws[0] == '<' ? raws : WebletBuilder.new(raws, marker: marker, \
79
+ obj = s[0] == '<' ? s : WebletBuilder.new(s, marker: marker, \
67
80
  debug: debug).to_a
68
81
  @doc = Rexle.new(obj)
69
82
  @h = scan @doc.root
@@ -81,13 +94,21 @@ class Weblet
81
94
 
82
95
  def render(*args)
83
96
 
97
+ @b = args.pop if args.last.is_a? Binding
98
+
84
99
  if args.first.is_a? String then
85
- path = args.first.split('/',2).map(&:to_sym)
100
+ path = args.first.split('/').map(&:to_sym)
86
101
  else
87
102
  path = *args.flatten(1)
88
103
  end
89
104
 
90
- r = @h.dig *path
105
+ #r = @h.dig *path
106
+ r = digx(@h, path)
107
+
108
+ # check for interpolated substitution tags e.g/ <:card/svg/link>
109
+ r.gsub!(/<:([^>]+)>/) {|x| self.render($1) }
110
+
111
+ puts 'r: ' + r.inspect if @debug
91
112
 
92
113
  if r.nil? then
93
114
  found = @doc.root.element("//node[@id='#{path.join}']")
@@ -99,6 +120,20 @@ class Weblet
99
120
  end
100
121
 
101
122
  private
123
+
124
+ def digx(obj, a)
125
+
126
+ h = obj.is_a?(Array) ? obj.last : obj
127
+
128
+ r = h.dig(a.shift)
129
+
130
+ if a.any? then
131
+ digx(r, a)
132
+ else
133
+ r.is_a?(Array) ? r.first : r
134
+ end
135
+
136
+ end
102
137
 
103
138
  def scan(node)
104
139
 
@@ -110,7 +145,14 @@ class Weblet
110
145
 
111
146
  puts 'nodes: ' + nodes.inspect if @debug
112
147
 
113
- r = nodes.any? ? scan(e) : e.cdatas.join()
148
+ r = if nodes.any? then
149
+
150
+ r2 = scan(e)
151
+ e.cdatas.any? ? [e.cdatas.join(), r2] : r2
152
+
153
+ else
154
+ e.cdatas.join()
155
+ end
114
156
 
115
157
  [e.attributes[:id].to_sym, r]
116
158
 
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.1
4
+ version: 0.3.1
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-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.10
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.10
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