jstreebuilder 0.2.0 → 0.3.0

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: a34efda76d17c49fe344f4cbdf3ac4e1e12f0ea04015838f51fdba695fe8c6fb
4
- data.tar.gz: 7d7748ad8a279fe205c0832b610463b26d7f5223235da94e5ed8d0a0c264fd92
3
+ metadata.gz: becee86e064c7f3cc2c1f85d276181bf4b4e8fbf5452c12653984c1bc1c18ea1
4
+ data.tar.gz: eaad9031c261b926b2bf5356dcc8aa915a096ab1277fcb562463d8df8667bc7d
5
5
  SHA512:
6
- metadata.gz: e93d1ed1bfb1d5607f2a7b41dea63503fbdf6bfc45a4d1a6c7b45922ebfefeb36b52346af29eda10d600f286ab578ef1653150447dcc79164c8fecb737156505
7
- data.tar.gz: 1851f88fd3da5fde59ec8d91ff9e6815b3037cc6562167644f7be0fef9407d57c6079d221113a60512e0181906b1a5edb3029004195f709130d87d3fc781a010
6
+ metadata.gz: 161ef34be304b151fb0ea7a3a796cf681b9b1d2b93edbbd43a5e055bcac2730feae245256ac95c5e1aeb33e5ced23ea500882f00c1e0e52e9015a4fe064f95ed
7
+ data.tar.gz: ebc9f22165fc91925d568dcb55423bc7986bc68189477c24a5223226c504d40b19c484dbc1d6295580525b01852149d61034adbf6cbdd8360c4cab30b66544bf
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/jstreebuilder.rb CHANGED
@@ -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/entry' />
82
+ </xsl:element>
83
+
84
+ </xsl:template>
85
+
86
+ <xsl:template match='entry'>
87
+
88
+ <xsl:choose>
89
+ <xsl:when test='records/entry'>
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/entry' />
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
@@ -116,6 +176,61 @@ ul, #myUL {
116
176
  }
117
177
  ]
118
178
 
179
+ SIDEBAR_CSS = TREE_CSS + %q[
180
+
181
+ body {
182
+ font-family: "Lato", sans-serif;
183
+ }
184
+
185
+ .sidenav {
186
+ width: 25%;
187
+ position: fixed;
188
+ z-index: 1;
189
+ top: 20px;
190
+ left: 10px;
191
+ height: 90%;
192
+ overflow: auto;
193
+ background: #eee;
194
+ overflow-x: hidden;
195
+ padding: 12px 0;
196
+ }
197
+
198
+ .sidenav a {
199
+ padding: 2px 8px 2px 6px;
200
+ text-decoration: none;
201
+ font-size: 23px;
202
+ color: #2166F3;
203
+
204
+ }
205
+
206
+ .sidenav a:hover {
207
+ color: #064579;
208
+ }
209
+
210
+ .main {
211
+ margin-left: 25%; /* Same width as the sidebar + left position in px */
212
+ font-size: 26px; /* Increased text to enable scrolling */
213
+ padding: 0px 10px;
214
+ }
215
+
216
+ @media screen and (max-height: 450px) {
217
+ .sidenav {padding-top: 15px;}
218
+ .sidenav a {font-size: 19 px;}
219
+ }
220
+ ]
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
+
119
234
  TREE_JS =<<EOF
120
235
  var toggler = document.getElementsByClassName("caret");
121
236
  var i;
@@ -128,14 +243,18 @@ for (i = 0; i < toggler.length; i++) {
128
243
  }
129
244
  EOF
130
245
 
246
+ SIDEBAR_JS = TREE_JS
247
+
248
+ PLAIN_JS = ''
249
+
131
250
  class TreeBuilder
132
251
  using ColouredText
133
252
 
134
253
  attr_reader :to_tree
135
254
 
136
- def initialize(s, debug: false)
255
+ def initialize(s, hn: 1, debug: false)
137
256
 
138
- @debug = debug
257
+ @debug, @hn = debug, hn
139
258
  html = Kramdown::Document.new(s).to_html
140
259
  puts ('html: ' + html.inspect) if @debug
141
260
  a = scan_headings(html)
@@ -161,7 +280,7 @@ EOF
161
280
 
162
281
  end
163
282
 
164
- def make_tree(a, indent=0, hn=1)
283
+ def make_tree(a, indent=0, hn=@hn)
165
284
 
166
285
  if @debug then
167
286
  puts 'inside make_tree'.debug
@@ -192,7 +311,7 @@ EOF
192
311
 
193
312
  end
194
313
 
195
- def scan_headings(s, n=1)
314
+ def scan_headings(s, n=@hn)
196
315
 
197
316
  s.split(/(?=<h#{n})/).map do |x|
198
317
  x.include?('<h' + (n+1).to_s) ? scan_headings(x, n+1) : x
@@ -208,7 +327,7 @@ EOF
208
327
  def initialize(unknown=nil, options={})
209
328
 
210
329
  if unknown.is_a? String or unknown.is_a? Symbol then
211
- type = unkown.to_sym
330
+ type = unknown.to_sym
212
331
  elsif unknown.is_a? Hash
213
332
  options = {type: :tree}.merge(unknown)
214
333
  type = options[:type]
@@ -216,7 +335,7 @@ EOF
216
335
 
217
336
  @debug = options[:debug]
218
337
 
219
- @types = %i(tree)
338
+ @types = %i(tree sidebar plain)
220
339
 
221
340
  build(type, options) if type
222
341
 
@@ -281,8 +400,8 @@ EOF
281
400
  @html = s.gsub(/<\/div>/,'\0' + "\n").strip.lines[1..-2]\
282
401
  .map {|x| x.sub(/^ /,'') }.join
283
402
 
284
- @css = Object.const_get 'JsTreeBuilder::' + type.to_s.upcase + '_CSS'
285
- @js = Object.const_get 'JsTreeBuilder::' + type.to_s.upcase + '_JS'
403
+ @css = type.to_s.upcase + '_CSS'
404
+ @js = type.to_s.upcase + '_JS'
286
405
 
287
406
  end
288
407
 
@@ -299,18 +418,27 @@ EOF
299
418
  end
300
419
 
301
420
 
302
- def tree(opt={})
421
+ def tree(opt={}, xslt=XSLT)
303
422
 
304
- src = opt[:src]
423
+ raw_src = opt[:src]
424
+
425
+ src, _ = RXFHelper.read raw_src
426
+
427
+ header = "<?polyrex schema='entries[title]/entry[title,url]' \
428
+ delimiter=' # '?>\n\n"
305
429
 
306
430
  s = if src =~ /<tree>/ then
307
431
 
308
432
  build_px(src)
309
433
 
310
- elsif src =~ /<?polyrex /
311
- src
434
+ elsif src =~ /<\?polyrex-links\?>/
435
+ header + src.sub(/<\?polyrex-links\?>/,'').lstrip
436
+ elsif src =~ /<\?polyrex /
437
+ src
438
+ elsif src =~ /^#+/
439
+ build_px(TreeBuilder.new(src, hn: opt[:hn],debug: @debug).to_tree)
312
440
  else
313
- build_px(TreeBuilder.new(src, debug: @debug).to_tree)
441
+ header + src.lstrip
314
442
  end
315
443
 
316
444
  puts ('s: ' + s.inspect).debug if @debug
@@ -321,10 +449,20 @@ EOF
321
449
  puts ('px: ' + px.inspect).debug if @debug
322
450
  puts ('px.to_xml: ' + px.to_xml.inspect).debug if @debug
323
451
  doc = Nokogiri::XML(px.to_xml)
324
- xslt = Nokogiri::XSLT(XSLT)
452
+ xslt = Nokogiri::XSLT(xslt)
325
453
 
326
454
  @ul = xslt.transform(doc).to_s.lines[1..-1].join
327
455
 
328
456
  end
457
+
458
+ def sidebar(opt={})
459
+ doc = Rexle.new(tree(opt))
460
+ doc.root.attributes[:class] = 'sidenav'
461
+ @ul = doc.xml(declaration: false)
462
+ end
463
+
464
+ def plain(opt={})
465
+ tree opt, PLAIN
466
+ end
329
467
 
330
468
  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.0
4
+ version: 0.3.0
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
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCxe/SK
17
- P63fEkWwc5zLyS7cQUh1CpPliXajuIL1pUxMyF0FBxs+GId3IZhCF8/3+RMVnz/e
18
- Gs0J9nDBrCctAHSi6VsjFocmiXqu96sx9Fxfs5wTqyT4fD22LoTBNVUZ0pZfxaBm
19
- G6ztBF1dmnrmsSCtLnq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f7DOGxBLLmyvr
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