jstreebuilder 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78cae4a1eca195d5911489593cd19215b7ff070f3a64dda3d335d475e204ffa3
4
- data.tar.gz: 9eaeee9e2f4ed52fa14d3f84a32fae4cd451e7f13c46601e2fa01a7a61cf0dad
3
+ metadata.gz: fa844d152f822a43de4979ae351e7fa30a9adbd35ae6f18cf07a6824f5da74a3
4
+ data.tar.gz: 91928df4b49e8f62a26ed9529c602300324df0059c2e93da9c54e6d6e77f6c12
5
5
  SHA512:
6
- metadata.gz: e3bdc4fcc00377c1acebf131867c6c221549f0193430c97026f745398cadaa60d348e7dd4002f3defe59e79733a7f1eab0a977d4a6779f51ea6227702448b5b5
7
- data.tar.gz: 6ddaf977fdeeb5dc201ec701ca06db70bae1cfa9fbc3ec22665559b57b41feceb58c762a10343816b48eb2a6694e656b53788b8f53cf6bdf8723010b1ecd440d
6
+ metadata.gz: 2ae8e3756a51d79dcea3e222fc43a2fafa2f233a497096bb2e0d733082d8339ff63b2fca0252c44871895ced3b5eae4aae0abc8cc0d053b6211684fa0d1a24ca
7
+ data.tar.gz: 1e1ef267edb8bf7eaa6197b7bbc9b5bfb2af8059c43ae214a3073fab07103dfb16edb0ab22277f201306e164e544dbe8af64cc02b2c1b99597cc100751afbb34
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/jstreebuilder.rb CHANGED
@@ -28,17 +28,17 @@ XSLT = %q[
28
28
 
29
29
  <xsl:element name='li'>
30
30
 
31
- <xsl:element name='span'>
31
+ <xsl:element name='span'>
32
32
  <xsl:attribute name="class">caret</xsl:attribute>
33
33
  <xsl:choose>
34
34
  <xsl:when test='summary/url != ""'>
35
35
  <xsl:element name='a'>
36
36
  <xsl:attribute name='href'><xsl:value-of select='summary/url'/></xsl:attribute>
37
- <xsl:value-of select='summary/title'/>
37
+ <xsl:value-of select='summary/title'/>
38
38
  </xsl:element>
39
39
  </xsl:when>
40
40
  <xsl:otherwise>
41
- <xsl:value-of select='summary/title'/>
41
+ <xsl:value-of select='summary/title'/>
42
42
  </xsl:otherwise>
43
43
  </xsl:choose>
44
44
  </xsl:element>
@@ -49,16 +49,16 @@ XSLT = %q[
49
49
 
50
50
  </xsl:when>
51
51
  <xsl:otherwise>
52
- <xsl:element name='li'>
52
+ <xsl:element name='li'>
53
53
  <xsl:choose>
54
54
  <xsl:when test='summary/url != ""'>
55
55
  <xsl:element name='a'>
56
56
  <xsl:attribute name='href'><xsl:value-of select='summary/url'/></xsl:attribute>
57
- <xsl:value-of select='summary/title'/>
57
+ <xsl:value-of select='summary/title'/>
58
58
  </xsl:element>
59
59
  </xsl:when>
60
60
  <xsl:otherwise>
61
- <xsl:value-of select='summary/title'/>
61
+ <xsl:value-of select='summary/title'/>
62
62
  </xsl:otherwise>
63
63
  </xsl:choose>
64
64
  </xsl:element>
@@ -94,11 +94,11 @@ PLAIN = %q[
94
94
  <xsl:when test='summary/url != ""'>
95
95
  <xsl:element name='a'>
96
96
  <xsl:attribute name='href'><xsl:value-of select='summary/url'/></xsl:attribute>
97
- <xsl:value-of select='summary/title'/>
97
+ <xsl:value-of select='summary/title'/>
98
98
  </xsl:element>
99
99
  </xsl:when>
100
100
  <xsl:otherwise>
101
- <xsl:value-of select='summary/title'/>
101
+ <xsl:value-of select='summary/title'/>
102
102
  </xsl:otherwise>
103
103
  </xsl:choose>
104
104
  </xsl:element>
@@ -109,16 +109,16 @@ PLAIN = %q[
109
109
 
110
110
  </xsl:when>
111
111
  <xsl:otherwise>
112
- <xsl:element name='li'>
112
+ <xsl:element name='li'>
113
113
  <xsl:choose>
114
114
  <xsl:when test='summary/url != ""'>
115
115
  <xsl:element name='a'>
116
116
  <xsl:attribute name='href'><xsl:value-of select='summary/url'/></xsl:attribute>
117
- <xsl:value-of select='summary/title'/>
117
+ <xsl:value-of select='summary/title'/>
118
118
  </xsl:element>
119
119
  </xsl:when>
120
120
  <xsl:otherwise>
121
- <xsl:value-of select='summary/title'/>
121
+ <xsl:value-of select='summary/title'/>
122
122
  </xsl:otherwise>
123
123
  </xsl:choose>
124
124
  </xsl:element>
@@ -148,7 +148,7 @@ ul, #myUL {
148
148
 
149
149
  /* Style the caret/arrow */
150
150
  .caret {
151
- cursor: pointer;
151
+ cursor: pointer;
152
152
  user-select: none; /* Prevent text selection */
153
153
  }
154
154
 
@@ -162,7 +162,7 @@ ul, #myUL {
162
162
 
163
163
  /* Rotate the caret/arrow icon when clicked on (using JavaScript) */
164
164
  .caret-down::before {
165
- transform: rotate(90deg);
165
+ transform: rotate(90deg);
166
166
  }
167
167
 
168
168
  /* Hide the nested list */
@@ -177,7 +177,7 @@ ul, #myUL {
177
177
  ]
178
178
 
179
179
  SIDEBAR_CSS = TREE_CSS + %q[
180
-
180
+
181
181
  body {
182
182
  font-family: "Lato", sans-serif;
183
183
  }
@@ -221,12 +221,12 @@ body {
221
221
 
222
222
  PLAIN_CSS = "
223
223
  ul {
224
- list-style-type: none;
225
- background-color: transparent;
224
+ list-style-type: none;
225
+ background-color: transparent;
226
226
  margin: 0.1em 0.1em; padding: 0.3em 1.3em
227
227
  }
228
228
  ul li {
229
- background-color: transparent;
229
+ background-color: transparent;
230
230
  margin: 0.1em 0.1em; padding: 0.3em 0.3em
231
231
  }
232
232
  "
@@ -259,42 +259,42 @@ PLAIN_JS = ''
259
259
  puts ('html: ' + html.inspect) if @debug
260
260
  a = scan_headings(html)
261
261
  puts ('a: ' + a.inspect) if @debug
262
-
262
+
263
263
  s2 = make_tree(a)
264
264
  puts ('s2: ' + s2.inspect) if @debug
265
265
  tree = LineTree.new(s2).to_tree
266
-
266
+
267
267
  puts ('tree: ' + tree.inspect).debug if @debug
268
-
268
+
269
269
  doc = Rexle.new(tree)
270
270
  doc.root.each_recursive do |node|
271
-
272
- h = node.attributes
271
+
272
+ h = node.attributes
273
273
  puts ('h: ' + h.inspect).debug if @debug
274
274
  h[:url] = '#' + h[:title].strip.downcase.gsub(' ', '-')
275
-
275
+
276
276
  end
277
277
  puts ('doc.xml: ' + doc.xml.inspect) if @debug
278
-
278
+
279
279
  @to_tree = doc.xml pretty: true
280
280
 
281
281
  end
282
-
282
+
283
283
  def make_tree(a, indent=0, hn=@hn)
284
-
284
+
285
285
  if @debug then
286
- puts 'inside make_tree'.debug
286
+ puts 'inside make_tree'.debug
287
287
  puts ('a: ' + a.inspect).debug
288
288
  end
289
-
289
+
290
290
  a.map.with_index do |x, i|
291
-
291
+
292
292
  puts ('x: ' + x.inspect).debug if @debug
293
-
293
+
294
294
  if x.is_a? Array then
295
295
 
296
296
  puts 'before make_tree()'.info if @debug
297
-
297
+
298
298
  make_tree(x, indent+1, hn)
299
299
 
300
300
  else
@@ -309,11 +309,11 @@ PLAIN_JS = ''
309
309
 
310
310
  end.compact.join("\n")
311
311
 
312
- end
312
+ end
313
313
 
314
314
  def scan_headings(s, n=@hn)
315
-
316
- s.split(/(?=<h#{n})/).map do |x|
315
+
316
+ s.split(/(?=<h#{n})/).map do |x|
317
317
  x.include?('<h' + (n+1).to_s) ? scan_headings(x, n+1) : x
318
318
  end
319
319
 
@@ -325,42 +325,42 @@ PLAIN_JS = ''
325
325
  attr_reader :html, :css, :js
326
326
 
327
327
  def initialize(unknown=nil, options={})
328
-
328
+
329
329
  if unknown.is_a? String or unknown.is_a? Symbol then
330
330
  type = unknown.to_sym
331
331
  elsif unknown.is_a? Hash
332
332
  options = {type: :tree}.merge(unknown)
333
333
  type = options[:type]
334
334
  end
335
-
335
+
336
336
  @debug = options[:debug]
337
337
 
338
338
  @types = %i(tree sidebar plain)
339
-
339
+
340
340
  build(type, options) if type
341
341
 
342
342
  end
343
-
343
+
344
344
  def to_css()
345
345
  @css
346
346
  end
347
-
347
+
348
348
  def to_html()
349
349
  @html
350
350
  end
351
-
351
+
352
352
  def to_js()
353
353
  @js
354
354
  end
355
-
355
+
356
356
  def to_ul()
357
357
  @ul
358
358
  end
359
-
359
+
360
360
  def to_webpage()
361
361
 
362
362
  a = RexleBuilder.build do |xml|
363
- xml.html do
363
+ xml.html do
364
364
  xml.head do
365
365
  xml.meta name: "viewport", content: \
366
366
  "width=device-width, initial-scale=1"
@@ -370,105 +370,111 @@ PLAIN_JS = ''
370
370
  end
371
371
  end
372
372
 
373
- doc = Rexle.new(a)
374
-
373
+ doc = Rexle.new(a)
374
+
375
375
  doc.root.element('body').add \
376
- Rexle::Element.new('script').add_text "\n" +
376
+ Rexle::Element.new('script').add_text "\n" +
377
377
  @js.gsub(/^ +\/\/[^\n]+\n/,'')
378
-
378
+
379
379
  "<!DOCTYPE html>\n" + doc.xml(pretty: true, declaration: false)\
380
380
  .gsub(/<\/div>/,'\0' + "\n").gsub(/\n *<!--[^>]+>/,'')
381
-
381
+
382
382
  end
383
-
383
+
384
384
  def to_xml()
385
385
  @xml
386
386
  end
387
-
388
-
387
+
388
+
389
389
  private
390
-
390
+
391
391
  def build(type, options)
392
-
392
+
393
393
  puts 'inside build'.info if @debug
394
- puts "type: %s\noptions: %s".debug % [type, options] if @debug
395
-
394
+ puts "type: %s\noptions: %s".debug % [type, options] if @debug
395
+
396
396
  return unless @types.include? type.to_sym
397
-
397
+
398
398
  s = method(type.to_sym).call(options)
399
-
399
+
400
400
  @html = s.gsub(/<\/div>/,'\0' + "\n").strip.lines[1..-2]\
401
401
  .map {|x| x.sub(/^ /,'') }.join
402
-
403
- @css = type.to_s.upcase + '_CSS'
404
- @js = type.to_s.upcase + '_JS'
405
-
402
+
403
+ @css = Object.const_get self.class.to_s + '::' + type.to_s.upcase + '_CSS'
404
+ @js = Object.const_get self.class.to_s + '::' + type.to_s.upcase + '_JS'
405
+
406
406
  end
407
-
407
+
408
408
  def build_px(tree)
409
-
409
+
410
410
  schema = 'entries/link[title, url]'
411
411
  xslt_schema = 'tree/item[@title:title, @url:url]'
412
412
 
413
413
  # transform the tree xml into a polyrex document
414
414
  pxsl = PolyrexXSLT.new(schema: schema, xslt_schema: xslt_schema).to_xslt
415
415
  puts 'pxsl: ' + pxsl if @debug
416
- Rexslt.new(pxsl, tree).to_s
417
-
416
+ Rexslt.new(pxsl, tree).to_s
417
+
418
418
  end
419
-
419
+
420
420
 
421
421
  def tree(opt={}, xslt=XSLT)
422
422
 
423
+ puts 'inside tree' if @debug
424
+
423
425
  raw_src = opt[:src]
424
-
426
+
425
427
  px = if raw_src.is_a? String then
426
-
428
+
427
429
  src, _ = RXFHelper.read raw_src
428
-
430
+
429
431
  header = "<?polyrex schema='entries[title]/link[title,url]' \
430
432
  delimiter=' # '?>\n\n"
431
-
433
+
432
434
  s = if src =~ /<tree>/ then
433
-
435
+
434
436
  build_px(src)
435
-
436
- elsif src =~ /<\?polyrex-links\?>/
437
+
438
+ elsif src =~ /<\?polyrex-links\?>/
437
439
  header + src.sub(/<\?polyrex-links\?>/,'').lstrip
438
- elsif src =~ /<\?polyrex /
439
- src
440
+ elsif src =~ /<\?polyrex /
441
+ src
440
442
  elsif src =~ /^#+/
441
443
  build_px(TreeBuilder.new(src, hn: opt[:hn],debug: @debug).to_tree)
442
444
  else
443
445
  header + src.lstrip
444
446
  end
445
-
447
+
446
448
  puts ('s: ' + s.inspect).debug if @debug
447
449
  Polyrex.new(s)
448
-
450
+
449
451
  elsif raw_src.is_a?(Polyrex) # detects PolyrexLinks as Polyrex too
450
452
  raw_src
451
453
  end
452
-
454
+
453
455
  # transform the polyrex xml into a nested HTML list
454
456
  #@ul = Rexslt.new(px.to_xml, XSLT).to_xml
455
457
  puts ('px: ' + px.inspect).debug if @debug
456
458
  puts ('px.to_xml: ' + px.to_xml.inspect).debug if @debug
459
+
457
460
  doc = Nokogiri::XML(px.to_xml)
458
461
  xslt = Nokogiri::XSLT(xslt)
459
462
 
460
463
  @ul = xslt.transform(doc).to_s.lines[1..-1].join
464
+ puts '@ul:' + @ul.inspect if @debug
465
+
466
+ return @ul
461
467
 
462
468
  end
463
-
469
+
464
470
  def sidebar(opt={})
465
471
  doc = Rexle.new(tree(opt))
466
472
  doc.root.attributes[:class] = 'sidenav'
467
473
  @ul = doc.xml(declaration: false)
468
474
  end
469
-
475
+
470
476
  def plain(opt={})
471
477
  tree opt, PLAIN
472
- end
478
+ end
473
479
 
474
480
  end
data.tar.gz.sig CHANGED
Binary file
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  8XaALSKxr3idyvVbBK920Fok7uGfchqJrIU5aP7qDogCmzHHHbiKzd+2arCbxISY
36
36
  +eOXFHOtwvjBqRlX2zAMEukI
37
37
  -----END CERTIFICATE-----
38
- date: 2021-05-25 00:00:00.000000000 Z
38
+ date: 2021-12-28 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: nokogiri
@@ -43,20 +43,20 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.11'
46
+ version: '1.12'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.11.5
49
+ version: 1.12.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.11'
56
+ version: '1.12'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.11.5
59
+ version: 1.12.5
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: polyrex
62
62
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '1.3'
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 1.3.2
69
+ version: 1.3.4
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '1.3'
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: 1.3.2
79
+ version: 1.3.4
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: polyrex-xslt
82
82
  requirement: !ruby/object:Gem::Requirement
@@ -143,7 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.1.2
146
+ rubyforge_project:
147
+ rubygems_version: 2.7.10
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: Generates an HTML tree from XML or Markdown.
metadata.gz.sig CHANGED
Binary file