jstreebuilder 0.2.1 → 0.3.1

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: d776f9c33266197c777807bd162beb3c2415b82686fe2fa8c1a8a2ba4d33dfab
4
- data.tar.gz: b2df7d91ba2d3365089f952ec7817183e194c2c62ed9b706acbc1ca2fa1fcea2
3
+ metadata.gz: 78cae4a1eca195d5911489593cd19215b7ff070f3a64dda3d335d475e204ffa3
4
+ data.tar.gz: 9eaeee9e2f4ed52fa14d3f84a32fae4cd451e7f13c46601e2fa01a7a61cf0dad
5
5
  SHA512:
6
- metadata.gz: 45ee0172a25404b048847b43a6c61ecb2ed8f568c7c79ca2949864c68a80a34a1b3b45b487467b2537f4c4b3ee5cb2dd6dcba6aa6bafddcb86bd74e891e1ac32
7
- data.tar.gz: 7e64e35b0fbfdbc91769b45698f305adbea9acd115f0e09ecc53543f728d740b81a51618c6bc4ce172d2f953ff9e2f5a03ac159658a329c2c8a18abb121118e2
6
+ metadata.gz: e3bdc4fcc00377c1acebf131867c6c221549f0193430c97026f745398cadaa60d348e7dd4002f3defe59e79733a7f1eab0a977d4a6779f51ea6227702448b5b5
7
+ data.tar.gz: 6ddaf977fdeeb5dc201ec701ca06db70bae1cfa9fbc3ec22665559b57b41feceb58c762a10343816b48eb2a6694e656b53788b8f53cf6bdf8723010b1ecd440d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/jstreebuilder.rb CHANGED
@@ -16,15 +16,15 @@ XSLT = %q[
16
16
 
17
17
  <xsl:element name='ul'>
18
18
  <xsl:attribute name='id'>myUL</xsl:attribute>
19
- <xsl:apply-templates select='records/entry' />
19
+ <xsl:apply-templates select='records/link' />
20
20
  </xsl:element>
21
21
 
22
22
  </xsl:template>
23
23
 
24
- <xsl:template match='entry'>
24
+ <xsl:template match='link'>
25
25
 
26
26
  <xsl:choose>
27
- <xsl:when test='records/entry'>
27
+ <xsl:when test='records/link'>
28
28
 
29
29
  <xsl:element name='li'>
30
30
 
@@ -43,7 +43,7 @@ XSLT = %q[
43
43
  </xsl:choose>
44
44
  </xsl:element>
45
45
  <ul class='nested'>
46
- <xsl:apply-templates select='records/entry' />
46
+ <xsl:apply-templates select='records/link' />
47
47
  </ul>
48
48
  </xsl:element>
49
49
 
@@ -70,6 +70,66 @@ XSLT = %q[
70
70
  </xsl:stylesheet>
71
71
  ]
72
72
 
73
+ PLAIN = %q[
74
+ <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
75
+ <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
76
+
77
+ <xsl:template match='entries'>
78
+
79
+ <xsl:element name='ul'>
80
+ <xsl:attribute name='id'>myUL</xsl:attribute>
81
+ <xsl:apply-templates select='records/link' />
82
+ </xsl:element>
83
+
84
+ </xsl:template>
85
+
86
+ <xsl:template match='link'>
87
+
88
+ <xsl:choose>
89
+ <xsl:when test='records/link'>
90
+
91
+ <xsl:element name='li'>
92
+
93
+ <xsl:choose>
94
+ <xsl:when test='summary/url != ""'>
95
+ <xsl:element name='a'>
96
+ <xsl:attribute name='href'><xsl:value-of select='summary/url'/></xsl:attribute>
97
+ <xsl:value-of select='summary/title'/>
98
+ </xsl:element>
99
+ </xsl:when>
100
+ <xsl:otherwise>
101
+ <xsl:value-of select='summary/title'/>
102
+ </xsl:otherwise>
103
+ </xsl:choose>
104
+ </xsl:element>
105
+ <ul>
106
+ <xsl:apply-templates select='records/link' />
107
+ </ul>
108
+
109
+
110
+ </xsl:when>
111
+ <xsl:otherwise>
112
+ <xsl:element name='li'>
113
+ <xsl:choose>
114
+ <xsl:when test='summary/url != ""'>
115
+ <xsl:element name='a'>
116
+ <xsl:attribute name='href'><xsl:value-of select='summary/url'/></xsl:attribute>
117
+ <xsl:value-of select='summary/title'/>
118
+ </xsl:element>
119
+ </xsl:when>
120
+ <xsl:otherwise>
121
+ <xsl:value-of select='summary/title'/>
122
+ </xsl:otherwise>
123
+ </xsl:choose>
124
+ </xsl:element>
125
+ </xsl:otherwise>
126
+ </xsl:choose>
127
+
128
+ </xsl:template>
129
+
130
+ </xsl:stylesheet>
131
+ ]
132
+
73
133
 
74
134
  class JsTreeBuilder
75
135
  using ColouredText
@@ -128,6 +188,8 @@ body {
128
188
  z-index: 1;
129
189
  top: 20px;
130
190
  left: 10px;
191
+ height: 90%;
192
+ overflow: auto;
131
193
  background: #eee;
132
194
  overflow-x: hidden;
133
195
  padding: 12px 0;
@@ -157,6 +219,18 @@ body {
157
219
  }
158
220
  ]
159
221
 
222
+ PLAIN_CSS = "
223
+ ul {
224
+ list-style-type: none;
225
+ background-color: transparent;
226
+ margin: 0.1em 0.1em; padding: 0.3em 1.3em
227
+ }
228
+ ul li {
229
+ background-color: transparent;
230
+ margin: 0.1em 0.1em; padding: 0.3em 0.3em
231
+ }
232
+ "
233
+
160
234
  TREE_JS =<<EOF
161
235
  var toggler = document.getElementsByClassName("caret");
162
236
  var i;
@@ -171,14 +245,16 @@ EOF
171
245
 
172
246
  SIDEBAR_JS = TREE_JS
173
247
 
248
+ PLAIN_JS = ''
249
+
174
250
  class TreeBuilder
175
251
  using ColouredText
176
252
 
177
253
  attr_reader :to_tree
178
254
 
179
- def initialize(s, debug: false)
255
+ def initialize(s, hn: 1, debug: false)
180
256
 
181
- @debug = debug
257
+ @debug, @hn = debug, hn
182
258
  html = Kramdown::Document.new(s).to_html
183
259
  puts ('html: ' + html.inspect) if @debug
184
260
  a = scan_headings(html)
@@ -204,7 +280,7 @@ SIDEBAR_JS = TREE_JS
204
280
 
205
281
  end
206
282
 
207
- def make_tree(a, indent=0, hn=1)
283
+ def make_tree(a, indent=0, hn=@hn)
208
284
 
209
285
  if @debug then
210
286
  puts 'inside make_tree'.debug
@@ -235,7 +311,7 @@ SIDEBAR_JS = TREE_JS
235
311
 
236
312
  end
237
313
 
238
- def scan_headings(s, n=1)
314
+ def scan_headings(s, n=@hn)
239
315
 
240
316
  s.split(/(?=<h#{n})/).map do |x|
241
317
  x.include?('<h' + (n+1).to_s) ? scan_headings(x, n+1) : x
@@ -259,7 +335,7 @@ SIDEBAR_JS = TREE_JS
259
335
 
260
336
  @debug = options[:debug]
261
337
 
262
- @types = %i(tree sidebar)
338
+ @types = %i(tree sidebar plain)
263
339
 
264
340
  build(type, options) if type
265
341
 
@@ -324,14 +400,14 @@ SIDEBAR_JS = TREE_JS
324
400
  @html = s.gsub(/<\/div>/,'\0' + "\n").strip.lines[1..-2]\
325
401
  .map {|x| x.sub(/^ /,'') }.join
326
402
 
327
- @css = Object.const_get 'JsTreeBuilder::' + type.to_s.upcase + '_CSS'
328
- @js = Object.const_get 'JsTreeBuilder::' + type.to_s.upcase + '_JS'
403
+ @css = type.to_s.upcase + '_CSS'
404
+ @js = type.to_s.upcase + '_JS'
329
405
 
330
406
  end
331
407
 
332
408
  def build_px(tree)
333
409
 
334
- schema = 'entries/entry[title, url]'
410
+ schema = 'entries/link[title, url]'
335
411
  xslt_schema = 'tree/item[@title:title, @url:url]'
336
412
 
337
413
  # transform the tree xml into a polyrex document
@@ -342,29 +418,44 @@ SIDEBAR_JS = TREE_JS
342
418
  end
343
419
 
344
420
 
345
- def tree(opt={})
421
+ def tree(opt={}, xslt=XSLT)
346
422
 
347
- src = opt[:src]
423
+ raw_src = opt[:src]
348
424
 
349
- s = if src =~ /<tree>/ then
425
+ px = if raw_src.is_a? String then
426
+
427
+ src, _ = RXFHelper.read raw_src
428
+
429
+ header = "<?polyrex schema='entries[title]/link[title,url]' \
430
+ delimiter=' # '?>\n\n"
431
+
432
+ s = if src =~ /<tree>/ then
433
+
434
+ build_px(src)
435
+
436
+ elsif src =~ /<\?polyrex-links\?>/
437
+ header + src.sub(/<\?polyrex-links\?>/,'').lstrip
438
+ elsif src =~ /<\?polyrex /
439
+ src
440
+ elsif src =~ /^#+/
441
+ build_px(TreeBuilder.new(src, hn: opt[:hn],debug: @debug).to_tree)
442
+ else
443
+ header + src.lstrip
444
+ end
350
445
 
351
- build_px(src)
446
+ puts ('s: ' + s.inspect).debug if @debug
447
+ Polyrex.new(s)
352
448
 
353
- elsif src =~ /<?polyrex /
354
- src
355
- else
356
- build_px(TreeBuilder.new(src, debug: @debug).to_tree)
449
+ elsif raw_src.is_a?(Polyrex) # detects PolyrexLinks as Polyrex too
450
+ raw_src
357
451
  end
358
452
 
359
- puts ('s: ' + s.inspect).debug if @debug
360
- px = Polyrex.new(s)
361
-
362
453
  # transform the polyrex xml into a nested HTML list
363
454
  #@ul = Rexslt.new(px.to_xml, XSLT).to_xml
364
455
  puts ('px: ' + px.inspect).debug if @debug
365
456
  puts ('px.to_xml: ' + px.to_xml.inspect).debug if @debug
366
457
  doc = Nokogiri::XML(px.to_xml)
367
- xslt = Nokogiri::XSLT(XSLT)
458
+ xslt = Nokogiri::XSLT(xslt)
368
459
 
369
460
  @ul = xslt.transform(doc).to_s.lines[1..-1].join
370
461
 
@@ -375,5 +466,9 @@ SIDEBAR_JS = TREE_JS
375
466
  doc.root.attributes[:class] = 'sidenav'
376
467
  @ul = doc.xml(declaration: false)
377
468
  end
469
+
470
+ def plain(opt={})
471
+ tree opt, PLAIN
472
+ end
378
473
 
379
474
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jstreebuilder
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
@@ -11,31 +11,31 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwODA1MjExNDQ4WhcN
15
- MjAwODA0MjExNDQ4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24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34
- uBJ1bPJvkq1hhYuPfw6FEXgyodyKcU98x77XUgJk7leb6jN1nXiWx5Ox1/TQL8WX
35
- /YHvF368/KpwUw6rBLVUbFvCsNvDTe+bPAG72P5om2g/aope7mb9Qc4kATQgWiys
36
- rqRI7UAQ3N9ojGSXl6KSySfi
28
+ BgkqhkiG9w0BAQsFAAOCAYEAK2zu4AMtsc4SyemYdrxWU+H7mq8f7DOGxBLLmyvr
29
+ 4nrXLRtXIXyLh5A+PSZZYo4yPMTWBceu9llFl/DQz6LAy3DWhrJeIkQLhjr2yMcj
30
+ 2AYCywZoz21O4ZAD/VWGVBXoiwBKgGVHKH5Tg0YP+rPamQpTx/R504XJtsyDDl8c
31
+ 8Dkxnyujqc5uhuRYzTdg2uB8tN/yGLjxp4TserAddrAXmT4eyX2pz5wLw3T4QnUM
32
+ M5Rbh265lM2dto4oF8l99nEqzjizaTYSqW/QUez+H+8LBuUL3vOZiLJVWpouE2q4
33
+ RRwa4taVOEYrfq15x2CCvAGTyAmVemNhMNKd1iQEbf0CCzlC9iUlhy71/7OwkFgP
34
+ Ylqv2eiEKke192rff7eV/rDZhR70zordGPaRHgkuRRs6Ld9yeKS0CduK9YiMeoaf
35
+ 8XaALSKxr3idyvVbBK920Fok7uGfchqJrIU5aP7qDogCmzHHHbiKzd+2arCbxISY
36
+ +eOXFHOtwvjBqRlX2zAMEukI
37
37
  -----END CERTIFICATE-----
38
- date: 2019-09-15 00:00:00.000000000 Z
38
+ date: 2021-05-25 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: nokogiri
@@ -43,40 +43,40 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.10'
46
+ version: '1.11'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.10.4
49
+ version: 1.11.5
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '1.10'
56
+ version: '1.11'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.10.4
59
+ version: 1.11.5
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: polyrex
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: 1.3.0
67
64
  - - "~>"
68
65
  - !ruby/object:Gem::Version
69
66
  version: '1.3'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.2
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: 1.3.0
77
74
  - - "~>"
78
75
  - !ruby/object:Gem::Version
79
76
  version: '1.3'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.3.2
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: polyrex-xslt
82
82
  requirement: !ruby/object:Gem::Requirement
@@ -101,24 +101,24 @@ dependencies:
101
101
  name: kramdown
102
102
  requirement: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: 2.1.0
107
104
  - - "~>"
108
105
  - !ruby/object:Gem::Version
109
- version: '2.1'
106
+ version: '2.3'
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.3.1
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: 2.1.0
117
114
  - - "~>"
118
115
  - !ruby/object:Gem::Version
119
- version: '2.1'
116
+ version: '2.3'
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.3.1
120
120
  description:
121
- email: james@jamesrobertson.eu
121
+ email: digital.robertson@gmail.com
122
122
  executables: []
123
123
  extensions: []
124
124
  extra_rdoc_files: []
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.0.3
146
+ rubygems_version: 3.1.2
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Generates an HTML tree from XML or Markdown.
metadata.gz.sig CHANGED
Binary file