myoutline 0.4.2 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -1
  4. data/lib/myoutline.rb +146 -158
  5. metadata +39 -35
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5c4004c2ecb1afce40d2b3aa042578578bebba47
4
- data.tar.gz: 0b56c3f9048ca5d40819ed1d96e795f854da0cb9
2
+ SHA256:
3
+ metadata.gz: 6614e36ff7173aa1c349e602e06c6da38cad3131cd4b728002b749113b33d434
4
+ data.tar.gz: efebcbfbc31ea18c4dff00019885a085de2953054c936bf3b620e2d35e0a48a1
5
5
  SHA512:
6
- metadata.gz: f6c0f793663fe9d98428f9e460347903031edbddde7731aa7f077aae511a1b8ff58f4407bce6930af2404d69ec06ba4de73d09a8b10a62317317d67e81e48d05
7
- data.tar.gz: 5aac295a3314a04544c26dae80f9e5d5dc3acec2952234f69278da81b80d43ddd53ad92f67415c810238abbc6afe99a38bb246cd6bc5b3c0b5180b380569bee4
6
+ metadata.gz: 61019834b793cd3db0dad4c5d3be5eadde1647cd37f6a604e78832dc287bab795e6da3da2bb826d768d9ea2b565e1a7e1eec0e3ff02f545baa950b21aaaa5b4b
7
+ data.tar.gz: 5b16e5c117f62c53c9541bf930609e7d9b12403d14211fcf7c15e19bf8ff05444ced5993cba6b608a078eee9de639364ebf73fc0e7d30326940e5bff9bcf25d9
Binary file
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- �����p��p��(�v��ݱ��Xb6ͬ~w������"(���(�\uVgcc '}��� 嚄�5��:�_eR�g1"cf�{�Ƌ�$���Y^|W�e}^���*�r2S��O�&�J_@��H�(w ���rú1��:�Yb����B�[xY6�;����ea�*2[J���֣Vĺ\��,Q\Np�����Hti�a"QSdC'<�z�^"2p�_6� �Ÿ:��4F'�=�׍H]��8N�[��c��Ue
1
+ 3*4hW���:�e�;P ��>DW�q,�G��WO˨W���>�߶�B܎�1�[�,��a�e����wPRD�W�����/��J�E[� ���)���Yȶ��uV��u�a��ϋ/ɭRxigdT���.j���q{򄦤��Eo�`�}�>���G
@@ -11,142 +11,200 @@ require 'md_edit'
11
11
 
12
12
  class MyOutline
13
13
 
14
- attr_reader :pxi, :links
14
+ attr_reader :outline
15
15
  attr_accessor :md
16
+
17
+ class Outline
18
+ using ColouredText
19
+
20
+ attr_reader :ftx, :links, :pxi
21
+
22
+ def initialize(source, debug: false, allsorted: true, autoupdate: true)
23
+
24
+ @debug, @source = debug, source
25
+ @allsorted, @autoupdate = allsorted, autoupdate
26
+
27
+ build_index(source)
28
+
29
+ end
30
+
31
+ def autosave(s=nil)
32
+
33
+ puts ('inside autosave ; @autoupdate: ' + @autoupdate.inspect).debug if @debug
34
+
35
+ if @autoupdate then
36
+ puts 'before save'.info if @debug
37
+ save() if s.nil? or self.to_s != s
38
+ end
39
+
40
+ end
41
+
42
+ def build_html(&blk)
43
+ @pxi.build_html(&blk)
44
+ end
45
+
46
+ def locate(s)
47
+ @links.locate s
48
+ end
49
+
50
+ def ls(path='.')
51
+ @ftx.ls(path).map(&:to_s)
52
+ end
53
+
54
+ def save(filename=nil)
55
+
56
+ if filename.nil? then
57
+ filename = RXFHelper.writeable?(@source) ? @source : 'myoutline.txt'
58
+ end
59
+
60
+ RXFHelper.write filename, self.to_s(declaration: true)
61
+
62
+ end
63
+
64
+ def to_px()
65
+ @pxi.to_px
66
+ end
67
+
68
+ def to_s(declaration: false)
69
+
70
+ if declaration == true then
71
+ @pxi.to_s.sub(/(?<=^\<\?)([^\?]+)/,'myoutline')
72
+ else
73
+ @pxi.to_s.lines[1..-1].join.lstrip
74
+ end
75
+
76
+ end
77
+
78
+ def to_tree
79
+ format_tree(alphabet: true, nourl: true)
80
+ end
81
+
82
+ def to_treelinks
83
+ format_tree()
84
+ end
85
+
86
+ private
87
+
88
+ def build_index(s)
89
+
90
+ @pxi = PxIndex.new(debug: @debug, indexsorted: @indexsorted,
91
+ allsorted: @allsorted)
92
+ @pxi.import s
93
+ autosave(s)
94
+ read(self.to_treelinks)
95
+
96
+ end
97
+
98
+ def format_tree(alphabet: false, nourl: false)
99
+
100
+ a = @pxi.to_s.lines
101
+ a.shift # remove the ph declaration
102
+ a.reject! {|x| x =~ /^(?:#[^\n]+|\n+)$/} unless alphabet
103
+
104
+ if nourl then
105
+ # strip out the URLS?
106
+ a.map! {|x| r = x[/^.*(?= # )/]; r ? r + "\n" : x }
107
+ end
108
+
109
+ a.join
110
+
111
+ end
16
112
 
17
- def initialize(source, debug: false, allsorted: true,
18
- autoupdate: true, topic_url: '$topic', md_path: '.')
113
+ def read(s)
114
+
115
+ @links = PolyrexLinks.new.import(s, debug: @debug)
116
+
117
+ s3 = s.lines.map {|x| x.split(/ | # /,2)[0]}.join("\n")
118
+ @ftx = FileTreeXML.new(s3, debug: @debug)
119
+
120
+ end
121
+
122
+ end
123
+
124
+ def initialize(source, debug: false, allsorted: true, autoupdate: true,
125
+ topic_url: '$topic', md_path: '.', default_md: 'main.md')
19
126
 
20
- @debug, @source, @topic_url = debug, source, topic_url
21
- @allsorted, @autoupdate, @md_path = allsorted, autoupdate, md_path
127
+ @debug, @topic_url = debug, topic_url
128
+ @md_path = md_path
129
+ @default_md = default_md
130
+ @allsorted, @autoupdate = allsorted, autoupdate
22
131
 
23
- raw_s, _ = RXFHelper.read(source)
24
- build_index(raw_s)
132
+ @outline = Outline.new(source, debug: debug,
133
+ allsorted: allsorted, autoupdate: autoupdate)
25
134
 
26
135
  end
27
136
 
28
137
  def fetch(uri)
29
138
 
30
- s, remaining = @links.locate uri
139
+ s, remaining = @outline.locate(uri)
31
140
  puts 'fetch() s: ' + s.inspect if @debug
32
141
  redirect = s =~ /^\[r\] +/i
33
142
  return s if redirect
34
143
 
144
+ s ||= @default_md; remaining ||= ''
145
+
35
146
  f = File.join(@md_path, s)
36
147
  puts 'f: ' + f.inspect if @debug
37
148
  @md = MdEdit.new f, debug: @debug
38
149
  r = edit(remaining.sub(/^\//,'').gsub(/\//,' > '))
39
- puts 'r: ' + r.inspect if @debug
150
+ puts 'fetch() r: ' + r.inspect if @debug
40
151
  @md.update r
41
152
 
42
153
  r
43
154
  end
44
-
45
-
46
- def ls(path='.')
47
- @ftx.ls(path).map(&:to_s)
48
- end
49
155
 
50
156
  def rebuild(s)
51
- build_index(s)
157
+ @outline = Outline.new s
52
158
  end
53
159
 
54
160
  def update(section)
55
161
  @md.update section
56
- end
162
+ end
57
163
 
58
- def save(filename=nil)
164
+ def update_tree(s)
59
165
 
60
- if filename.nil? then
61
- filename = RXFHelper.writeable?(@source) ? @source : 'myoutline.txt'
62
- end
63
-
64
- RXFHelper.write filename, self.to_s(declaration: true)
166
+ mo2 = Outline.new(s, debug: @debug,
167
+ allsorted: @allsorted, autoupdate: @autoupdate)
65
168
 
66
- end
67
-
68
- def to_html()
69
-
70
- px = self.to_px
169
+ h = @outline.links.to_h
170
+ links = mo2.links
71
171
 
72
- px.each_recursive do |x, parent|
172
+ mo2.links.to_h.each do |title, file|
73
173
 
74
- if x.is_a? Entry then
75
-
76
- trail = parent.attributes[:trail]
77
- s = x.title.gsub(/ +/,'-')
78
- x.attributes[:trail] = trail.nil? ? s : trail + '/' + s
79
-
174
+ if @debug then
175
+ puts 'title: ' + title.inspect
176
+ puts 'h[title]: ' + h[title].inspect
80
177
  end
81
178
 
82
- end
83
-
84
- doc = Nokogiri::XML(px.to_xml)
85
- xsl = Nokogiri::XSLT(xslt())
86
-
87
- doc = Rexle.new(xsl.transform(doc).to_s)
88
-
89
- doc.root.css('.atopic').each do |e|
90
- puts 'e: ' + e.parent.parent.xml.inspect if @debug
91
- e.attributes[:href] = @topic_url.sub(/\$topic/, e.text)\
92
- .sub(/\$id/, e.attributes[:id]).sub(/\$trail/, e.attributes[:trail])\
93
- .to_s.gsub(/ +/,'-')
179
+ links.link(title).url = h[title] if h[title]
94
180
  end
95
181
 
96
- doc.xml(pretty: true)
182
+ puts 'before Outline.new: ' + links.to_s(header: false).inspect if @debug
97
183
 
184
+ @outline = Outline.new(links.to_s(header: false), debug: @debug,
185
+ allsorted: @allsorted, autoupdate: @autoupdate)
186
+ @outline.autosave
98
187
  end
99
188
 
100
- def to_px()
101
- @pxi.to_px
102
- end
103
-
104
- def to_s(declaration: false)
189
+ def to_html()
105
190
 
106
- if declaration == true then
107
- @pxi.to_s.sub(/(?<=^\<\?)([^\?]+)/,'myoutline')
108
- else
109
- @pxi.to_s.lines[1..-1].join.lstrip
110
- end
191
+ @outline.build_html do |e|
192
+
193
+ e.attributes[:href] = @topic_url.sub(/\$topic/, e.text)\
194
+ .sub(/\$id/, e.attributes[:id]).sub(/\$trail/, e.attributes[:trail])\
195
+ .to_s.gsub(/ +/,'-')
196
+
197
+ end
111
198
 
112
199
  end
113
200
 
114
-
115
- def to_tree
116
- format_tree(alphabet: true, nourl: true)
201
+ def to_s()
202
+ @outline
117
203
  end
118
204
 
119
- def to_treelinks
120
- format_tree()
121
- end
122
205
 
123
206
  private
124
207
 
125
- def build_index(raw_s)
126
-
127
- # find the entries which aren't on the main index
128
- s = raw_s.sub(/<[^>]+>\n/,'')
129
- doc = LineTree.new(s, debug: @debug).to_doc(encapsulate: true)
130
- a = doc.root.xpath('entry/text()')
131
- puts 'doc: ' + doc.xml if @debug
132
- a2 = doc.root.xpath('entry//entry/text()')
133
- puts 'a2: ' + a2.inspect if @debug
134
- a3 = a2 - a
135
- puts 'a3:' + a3.inspect if @debug
136
-
137
- # add the new entries to the main index
138
- s << "\n" + a3.join("\n")
139
-
140
- s.prepend '<?ph schema="entries/section[heading]/entry[title, url]"?>
141
-
142
- '
143
-
144
- @pxi = PxIndex.new(s, debug: @debug, indexsorted: true,
145
- allsorted: @allsorted)
146
- save() if @autoupdate and self.to_s != raw_s
147
- read(self.to_treelinks)
148
- end
149
-
150
208
  def edit(s)
151
209
 
152
210
  r = @md.find s
@@ -164,77 +222,7 @@ class MyOutline
164
222
 
165
223
  end
166
224
 
167
- end
168
-
169
- def format_tree(alphabet: false, nourl: false)
170
-
171
- a = @pxi.to_s.lines
172
- a.shift # remove the ph declaration
173
- a.reject! {|x| x =~ /^(?:#[^\n]+|\n+)$/} unless alphabet
174
-
175
- if nourl then
176
- # strip out the URLS?
177
- a.map! {|x| r = x[/^.*(?= # )/]; r ? r + "\n" : x }
178
- end
179
-
180
- a.join
181
-
182
- end
183
-
184
- def read(s)
185
- @links = PolyrexLinks.new.import(s, debug: @debug)
186
-
187
- s3 = s.lines.map {|x| x.split(/ | # /,2)[0]}.join("\n")
188
- @ftx = FileTreeXML.new(s3, debug: @debug)
189
225
  end
190
-
191
- def xslt()
192
- <<EOF
193
- <?xml version="1.0" encoding="UTF-8"?>
194
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
195
- <xsl:output method="xml" indent="yes" />
196
-
197
- <xsl:template match='entries'>
198
- <ul>
199
- <xsl:apply-templates select='summary'/>
200
- <xsl:apply-templates select='records'/>
201
- </ul>
202
- </xsl:template>
203
-
204
- <xsl:template match='entries/summary'>
205
- </xsl:template>
206
-
207
- <xsl:template match='records/section'>
208
- <li><h1><xsl:value-of select="summary/heading"/></h1><xsl:text>
209
- </xsl:text>
210
-
211
- <xsl:apply-templates select='records'/>
212
-
213
- <xsl:text>
214
- </xsl:text>
215
- </li>
216
- </xsl:template>
217
226
 
218
227
 
219
- <xsl:template match='records/entry'>
220
- <ul id="{summary/title}">
221
- <li><xsl:text>
222
- </xsl:text>
223
- <a href="{summary/url}" class='atopic' id='{@id}' trail='{@trail}'>
224
- <xsl:value-of select="summary/title"/></a><xsl:text>
225
- </xsl:text>
226
-
227
- <xsl:apply-templates select='records'/>
228
-
229
- <xsl:text>
230
- </xsl:text>
231
- </li>
232
- </ul>
233
- </xsl:template>
234
-
235
-
236
- </xsl:stylesheet>
237
- EOF
238
- end
239
-
240
228
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myoutline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,27 +10,32 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgwMzE2MDkzNzMyWhcN
15
- MTkwMzE2MDkzNzMyWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDmw8ez
17
- 0Fu54YodAyszPu1V/4n713Kj/PpK0ljLndPpYve04yZLTznWIgklk2iRSDhj1eco
18
- r94LZm7c4Ev6nYqF5AGOcZRJE0/TbeOc8YijW19+epvYZDRXzxQBtl5m3N2tMx7o
19
- TRDg2LARgEaGo1muHpJUeaIMHv/zHQf7wBTY31Pi/t6qE9GPlQzoDW5newihQ6PR
20
- QgzHQaRgLW8JIjBi0b6EQjFC8MpXg+ZhLsgYPw+xqlLMrLyB9m02SqimIbek3hIF
21
- Jy2kX+AOuQQ9dh+LRMdBLHHJyoIJk7CflwtpRNhsu/IaoDmoVgP0tqZo7R1IjTAi
22
- S5l2XkJ/L4wuOtZDAgMBAAGjgYowgYcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
23
- HQYDVR0OBBYEFMS1Y3RLQL7dg3mw6LVqg3BU4czgMCYGA1UdEQQfMB2BG2dlbW1h
24
- c3RlckBqYW1lc3JvYmVydHNvbi5ldTAmBgNVHRIEHzAdgRtnZW1tYXN0ZXJAamFt
25
- ZXNyb2JlcnRzb24uZXUwDQYJKoZIhvcNAQEFBQADggEBAJc2Wd+jJiB8pdwroE2e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NmDKoFXFxk3FxZMfGNtscL4Ea8D8mS7JZRrDWZp2
24
+ kmkchqxsDxDN5LOQfnnoPNbR0Dxlx7BxfekinuxwB9yMlNQ5OW6xyNep8WkCAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU46mMtONZ
26
+ ledzG9BdAwRk7f+anCUwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAJp3p1feQpxjMF/yXfb0CCcm9C4Yp243TjAf/ABgg
29
+ ANbrjPCcBmz3RWutZp/vXKaZ6uXmynWEfSYYryxWLux96mW7z/4g96L89xELSC3V
30
+ jj/o73UCMl2iN47zoe30HyQuVVFiAuiQlJvOkCaDzx+jFehw9SUttOHCEA/Synhs
31
+ XG+/ClCD0XGZel9roxo2adUZ/Rrhw+UYRHepS4ghRK2JXA523gAJqZZZi9Ou+qhx
32
+ iBtn22ypXSG+PFnJ+8m+HgRuUQhw3vwBPtSxgdPotAKnxvCmD4jrTGPNR/f0g5ia
33
+ YXxFLjCYQxtL4W0zCGNAorMl3OejJjxP63JO3jf4CyKPHT9ePYK486zYPbeMGMY6
34
+ PDihRV0tIV6bPPDEZmUX/a+tpncZR/nCGd8DQMZ4QDxlKnxEWtnq5kEhRi8HLUJD
35
+ RmpF1GU3b1rykHbNgsw/QI2gfMShVh2f1zceczUFr0SXwGzS0YYRpZoi4qyjgKeb
36
+ 6srwVtKTp+GTywnYzfiE5J4u
32
37
  -----END CERTIFICATE-----
33
- date: 2018-04-10 00:00:00.000000000 Z
38
+ date: 2021-01-08 00:00:00.000000000 Z
34
39
  dependencies:
35
40
  - !ruby/object:Gem::Dependency
36
41
  name: pxindex
@@ -38,20 +43,20 @@ dependencies:
38
43
  requirements:
39
44
  - - "~>"
40
45
  - !ruby/object:Gem::Version
41
- version: '0.1'
46
+ version: '0.2'
42
47
  - - ">="
43
48
  - !ruby/object:Gem::Version
44
- version: 0.1.6
49
+ version: 0.2.1
45
50
  type: :runtime
46
51
  prerelease: false
47
52
  version_requirements: !ruby/object:Gem::Requirement
48
53
  requirements:
49
54
  - - "~>"
50
55
  - !ruby/object:Gem::Version
51
- version: '0.1'
56
+ version: '0.2'
52
57
  - - ">="
53
58
  - !ruby/object:Gem::Version
54
- version: 0.1.6
59
+ version: 0.2.1
55
60
  - !ruby/object:Gem::Dependency
56
61
  name: nokogiri
57
62
  requirement: !ruby/object:Gem::Requirement
@@ -96,22 +101,22 @@ dependencies:
96
101
  name: polyrex-links
97
102
  requirement: !ruby/object:Gem::Requirement
98
103
  requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: '0.2'
102
104
  - - ">="
103
105
  - !ruby/object:Gem::Version
104
- version: 0.2.0
106
+ version: 0.3.0
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.3'
105
110
  type: :runtime
106
111
  prerelease: false
107
112
  version_requirements: !ruby/object:Gem::Requirement
108
113
  requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: '0.2'
112
114
  - - ">="
113
115
  - !ruby/object:Gem::Version
114
- version: 0.2.0
116
+ version: 0.3.0
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '0.3'
115
120
  - !ruby/object:Gem::Dependency
116
121
  name: md_edit
117
122
  requirement: !ruby/object:Gem::Requirement
@@ -158,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
163
  - !ruby/object:Gem::Version
159
164
  version: '0'
160
165
  requirements: []
161
- rubyforge_project:
162
- rubygems_version: 2.6.13
166
+ rubygems_version: 3.0.3
163
167
  signing_key:
164
168
  specification_version: 4
165
169
  summary: Helps build an outline from plain text.
metadata.gz.sig CHANGED
Binary file