weblet 0.1.0 → 0.2.0

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: 188d4008035db1c75dee24819614915edc2a32eadd6ead9e5b792d9381458655
4
- data.tar.gz: 68136024110f77153101601d8115607c966e36c660e42c0e1b2b708cebd16e27
3
+ metadata.gz: db2437f118c3c20ae3793072517fb43614ab736e31ceddb2e94c25e9f5f7f2f6
4
+ data.tar.gz: 2624d3afc74ac2dc93867e4423614c483b6f26f091f27c081335210799d93222
5
5
  SHA512:
6
- metadata.gz: b7a4492500cab87adf86d969e0ef4324ec4ea41d46fd389d84e37895f19f166729e5eb4b2f54ce649d7d2dbf6834d5e3dbe9aaec8b4d9b13dd2802209fe913c0
7
- data.tar.gz: 67d9cca9a3aa8ff32edc6137c614b8ae3cb6e020643c91b20fc445a48b7699897c0a54242c499d9d72504a5ccb2c38e6ab3eedc8f2728a196f1a1beba8e448a2
6
+ metadata.gz: b464034193c7a1972c1554423198bb48a3b07cf97737b278c048d25ee59bbfa2b189514a6b35143e9d1352b0c1f1dae4b27afdc85c1c54bf77733a7392f92b3a
7
+ data.tar.gz: b715617193855dbbde52a3ac3dd78bc22ab6c1af7643c6a329f78f778f5d7018c09f3b92a07edd01c86890609a71777911a1d7de17be041d515e635418fb4bd2
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/weblet.rb CHANGED
@@ -7,8 +7,9 @@ require 'rexle'
7
7
 
8
8
  class WebletBuilder
9
9
 
10
- def initialize(s)
10
+ def initialize(s, debug: false)
11
11
 
12
+ @debug = debug
12
13
  @a = build(scan(s.strip))
13
14
  @a.unshift *['weblet', {}, '']
14
15
 
@@ -32,13 +33,19 @@ class WebletBuilder
32
33
  def build(a)
33
34
 
34
35
  a.map do |x|
35
-
36
+
37
+ puts 'x: ' + x.inspect if @debug
38
+
36
39
  if x.is_a? String then
37
- head, body = x.split("\n",2)
38
- [:node, {id: head[/#(\w+)/,1]}, body.strip]
40
+ head, body = x.split("\n", 2)
41
+ [:node, {id: head[/#(\w+)/,1]}, '',['![', {}, body.strip]]
42
+ elsif x.length < 2
43
+ x.flatten!(1)
44
+ head, body = x.shift.split("\n", 2)
45
+ [:node, {id: head[/#(\w+)/,1].rstrip}, '',['![', {}, body.rstrip, ]]
39
46
  else
40
47
  x.flatten!(1)
41
- head, body = x.shift.split("\n",2)
48
+ head, body = x.shift.split("\n", 2)
42
49
  [:node, {id: head[/#(\w+)/,1].rstrip}, body.rstrip, *build(x)]
43
50
  end
44
51
 
@@ -50,12 +57,14 @@ end
50
57
 
51
58
  class Weblet
52
59
 
53
- def initialize(raws, b)
60
+ def initialize(raws, b, debug: false)
61
+
62
+ @debug = debug
54
63
 
55
64
  raws.strip!
56
- obj = raws[0] == '<' ? raws : WebletBuilder.new(raws).to_a
57
- doc = Rexle.new(obj)
58
- @h = scan doc.root
65
+ obj = raws[0] == '<' ? raws : WebletBuilder.new(raws, debug: debug).to_a
66
+ @doc = Rexle.new(obj)
67
+ @h = scan @doc.root
59
68
  @b = b
60
69
 
61
70
  end
@@ -63,6 +72,10 @@ class Weblet
63
72
  def to_h()
64
73
  @h
65
74
  end
75
+
76
+ def to_xml()
77
+ @doc.root.xml pretty: true
78
+ end
66
79
 
67
80
  def render(*args)
68
81
 
@@ -73,6 +86,12 @@ class Weblet
73
86
  end
74
87
 
75
88
  r = @h.dig *path
89
+
90
+ if r.nil? then
91
+ found = @doc.root.element("//node[@id='#{path.join}']")
92
+ r = found.cdatas.join if found
93
+ end
94
+
76
95
  eval('%Q(' + r + ')', @b) if r
77
96
 
78
97
  end
@@ -82,10 +101,14 @@ class Weblet
82
101
  def scan(node)
83
102
 
84
103
  a = node.elements.map do |e|
104
+
105
+ puts 'e: ' + e.inspect if @debug
85
106
 
86
107
  nodes = e.xpath('node')
87
-
88
- r = nodes.any? ? scan(e) : e.children.join()
108
+
109
+ puts 'nodes: ' + nodes.inspect if @debug
110
+
111
+ r = nodes.any? ? scan(e) : e.cdatas.join()
89
112
 
90
113
  [e.attributes[:id].to_sym, r]
91
114
 
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.1.0
4
+ version: 0.2.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-02 00:00:00.000000000 Z
38
+ date: 2021-04-03 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
metadata.gz.sig CHANGED
Binary file