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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/line-tree.rb +59 -3
- data.tar.gz.sig +0 -0
- metadata +6 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 601c833fe53b9ba54b3d7540c858a047362ae6335d26365298d968de8f307722
|
4
|
+
data.tar.gz: 6e31cf3ab298e8d84904506e64ab537a4a90dc180f46edc34621b7f3119348c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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-
|
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.
|
41
|
+
version: '1.5'
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: 1.
|
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.
|
51
|
+
version: '1.5'
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
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
|