line-tree 0.7.0 → 0.7.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: 821db5f0b61bcb5fee78287509993ee2eafb34f39fbb982f0bd53a5fb17bbcff
4
- data.tar.gz: 766337d1372c9de82920b668688d0c38535c5570b76a23c8d1a5a4ce700e3ea1
3
+ metadata.gz: 601c833fe53b9ba54b3d7540c858a047362ae6335d26365298d968de8f307722
4
+ data.tar.gz: 6e31cf3ab298e8d84904506e64ab537a4a90dc180f46edc34621b7f3119348c1
5
5
  SHA512:
6
- metadata.gz: 32c220a7277a2faa31f05f56b02e093c7cc552145261a395c3791bb3f6f6a81731da99170807d40332f2ab25cfcebad3b8b8a9d78f57dc8ca3fa03a598fc0800
7
- data.tar.gz: 9597470f8ccf14488d8e8b8dbd83d163ea6bc04f19c40a6c53e5fa85800b4b8c3ef7c4fc8a80d2b096bcebece24d883f6f8b18968eb33f149824c42409174495
6
+ metadata.gz: c350215508fb0b3aa17d064221bc5b87d4ff5e185dc282b3991e5c0fcbca6418b367ae4ae2ba76081f2676f4227349da1202781c899098e15efbb4c463cfc8d9
7
+ data.tar.gz: 2e542ba98ff13a7d5a0eac052ffa7193b3f03d5a42e2461b4c4009a8ec7f33b691894c32cd42f634166cf8879817df7e7edb77aafde76b2c58234fdf39e32c01
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/line-tree.rb CHANGED
@@ -6,14 +6,15 @@ require 'rexle'
6
6
 
7
7
 
8
8
  class LineTree
9
-
9
+ using ColouredText
10
+
10
11
  attr_reader :to_a
11
12
 
12
13
  def initialize(raw_s, level: nil, ignore_non_element: true,
13
14
  ignore_blank_lines: true, ignore_label: false,
14
15
  ignore_newline: true, root: nil, debug: false)
15
16
 
16
- puts 'inside linetree' if @debug
17
+ puts 'inside linetree'.info if @debug
17
18
  s = root ? root + "\n" + raw_s.lines.map {|x| ' ' + x}.join : raw_s
18
19
 
19
20
  @ignore_non_element = ignore_non_element
@@ -23,7 +24,7 @@ class LineTree
23
24
  @debug = debug
24
25
 
25
26
  lines = ignore_blank_lines ? s.gsub(/^ *$\n/,'') : s
26
- puts 'lines : ' + lines.inspect if @debug
27
+ puts ('lines : ' + lines.inspect).debug if @debug
27
28
  @to_a = scan_shift(lines.strip, level)
28
29
 
29
30
  end
@@ -45,6 +46,16 @@ class LineTree
45
46
  Rexle.new(a2)
46
47
 
47
48
  end
49
+
50
+ def to_html(numbered: false)
51
+
52
+ @numbered = numbered
53
+ s = "<ul>%s</ul>" % make_html_list(@to_a)
54
+ puts ('s: ' + s.inspect).debug if @debug
55
+ puts s
56
+ Rexle.new(s).xml pretty: true, declaration: false
57
+
58
+ end
48
59
 
49
60
  def to_xml(options={})
50
61
  to_doc.xml(options)
@@ -77,6 +88,51 @@ class LineTree
77
88
  a
78
89
 
79
90
  end
91
+
92
+ def make_html_list(a, indent=-1, count=nil)
93
+
94
+ puts 'inside make_html_list'.info if @debug
95
+
96
+ items = a.map.with_index do |x, i|
97
+
98
+ puts ('x:' + x.inspect).debug if @debug
99
+
100
+ if x.is_a? Array then
101
+
102
+ id, head, tail = if count then
103
+
104
+ [
105
+ count.to_s + '.' + i.to_s,
106
+ i == 1 ? "<ul>\n" : '',
107
+ i == a.length - 1 ? "</li>\n</ul>" : \
108
+ i == a.length - 1 ? '</ul></li>' : '</li>'
109
+ ]
110
+
111
+ else
112
+ [i+1, '', '']
113
+ end
114
+
115
+ head + make_html_list(x, indent+1, id) + tail
116
+
117
+ else
118
+
119
+ #"%s%s %s" % [' ' * indent, count, x]
120
+ r = if @numbered then
121
+ "%s<li id='n%s'>%s" % [' ' * indent, count.to_s.gsub('.','-'), x]
122
+ else
123
+ "%s<li>%s" % [' ' * indent, x]
124
+ end
125
+
126
+ i == 1 ? "<ul>" + r : r
127
+
128
+ end
129
+
130
+ end
131
+
132
+ items.join("\n")
133
+
134
+ end
135
+
80
136
 
81
137
  def scan_shift(lines, level=nil)
82
138
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  wN+2fv6EC2h0XIvfmiFpfz1F3AiA5cWUW8HuIO87gQy/9YbBrh4VK9WSnVaVEv0u
31
31
  6gM=
32
32
  -----END CERTIFICATE-----
33
- date: 2018-08-18 00:00:00.000000000 Z
33
+ date: 2018-12-18 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: rexle
@@ -38,20 +38,20 @@ dependencies:
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.4'
41
+ version: '1.5'
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 1.4.12
44
+ version: 1.5.0
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - "~>"
50
50
  - !ruby/object:Gem::Version
51
- version: '1.4'
51
+ version: '1.5'
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.4.12
54
+ version: 1.5.0
55
55
  description: Line-tree parses indented lines of text and returns an array representing
56
56
  a tree structure.
57
57
  email: james@r0bertson.co.uk
metadata.gz.sig CHANGED
Binary file