myoutline 0.4.3 → 0.4.4

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
  SHA1:
3
- metadata.gz: fdaac78cb5087754de66fe05c22dd070d6cdb9f7
4
- data.tar.gz: a62c01bd4784c867d40538c68683c41129c545a3
3
+ metadata.gz: 8a3df25ba19223d3630612441c9c157b05b0b1aa
4
+ data.tar.gz: f1e325e49cd1f8a16215f446b712dd94b5367b47
5
5
  SHA512:
6
- metadata.gz: 21906e0f2104bb483a7bac41235b2a91597cefd49a553ccd09a25a863db05bbaf40b3f89e2e5842aa271d0bc3078dc696281b198393c0870da27eba9911e395b
7
- data.tar.gz: cf931109ea97b3c9fb92793693e6292b3164fa9b725592edbfb965d3b25a7624de46a9958cf9e6acbbd4d4dd1827b213ef6f32e2d97bcba76a1736537868f953
6
+ metadata.gz: b108ce8f581ae7be0eba62ea3246bdbaa85703acdb4a2f6443ae869bc2dc7c2725b056dafeb6e5623e06e0dbfa59a9963167c312d2898dbac474b8381d09e803
7
+ data.tar.gz: 954539f6c9df906323a4a072bfcc02a784459ce6e183e602a0b592c04f59ced91c22b33401131826e089f08adcd228885239e8decf4601e287a37c1ccc665818
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -11,24 +11,127 @@ 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
+
19
+ attr_reader :ftx, :links, :pxi
20
+
21
+ def initialize(source, debug: false, allsorted: true, autoupdate: true)
22
+
23
+ @debug, @source = debug, source
24
+ @allsorted, @autoupdate = allsorted, autoupdate
25
+
26
+ build_index(source)
27
+
28
+ end
29
+
30
+ def autosave(s=nil)
31
+
32
+ puts 'inside autosave ; @autoupdate: ' + @autoupdate.inspect if @debug
33
+
34
+ if @autoupdate then
35
+ puts 'before save' if @debug
36
+ save() if s.nil? or self.to_s != s
37
+ end
38
+
39
+ end
40
+
41
+ def locate(s)
42
+ @links.locate s
43
+ end
44
+
45
+ def ls(path='.')
46
+ @ftx.ls(path).map(&:to_s)
47
+ end
48
+
49
+ def save(filename=nil)
50
+
51
+ if filename.nil? then
52
+ filename = RXFHelper.writeable?(@source) ? @source : 'myoutline.txt'
53
+ end
54
+
55
+ RXFHelper.write filename, self.to_s(declaration: true)
56
+
57
+ end
58
+
59
+ def to_px()
60
+ @pxi.to_px
61
+ end
62
+
63
+ def to_s(declaration: false)
64
+
65
+ if declaration == true then
66
+ @pxi.to_s.sub(/(?<=^\<\?)([^\?]+)/,'myoutline')
67
+ else
68
+ @pxi.to_s.lines[1..-1].join.lstrip
69
+ end
70
+
71
+ end
72
+
73
+ def to_tree
74
+ format_tree(alphabet: true, nourl: true)
75
+ end
76
+
77
+ def to_treelinks
78
+ format_tree()
79
+ end
80
+
81
+ private
82
+
83
+ def build_index(s)
84
+
85
+ @pxi = PxIndex.new(debug: @debug, indexsorted: @indexsorted,
86
+ allsorted: @allsorted)
87
+ @pxi.import s
88
+ autosave(s)
89
+ read(self.to_treelinks)
90
+
91
+ end
92
+
93
+ def format_tree(alphabet: false, nourl: false)
94
+
95
+ a = @pxi.to_s.lines
96
+ a.shift # remove the ph declaration
97
+ a.reject! {|x| x =~ /^(?:#[^\n]+|\n+)$/} unless alphabet
98
+
99
+ if nourl then
100
+ # strip out the URLS?
101
+ a.map! {|x| r = x[/^.*(?= # )/]; r ? r + "\n" : x }
102
+ end
103
+
104
+ a.join
105
+
106
+ end
107
+
108
+ def read(s)
109
+
110
+ @links = PolyrexLinks.new.import(s, debug: @debug)
111
+
112
+ s3 = s.lines.map {|x| x.split(/ | # /,2)[0]}.join("\n")
113
+ @ftx = FileTreeXML.new(s3, debug: @debug)
114
+
115
+ end
116
+
117
+ end
16
118
 
17
119
  def initialize(source, debug: false, allsorted: true, autoupdate: true,
18
120
  topic_url: '$topic', md_path: '.', default_md: 'main.md')
19
121
 
20
- @debug, @source, @topic_url = debug, source, topic_url
21
- @allsorted, @autoupdate, @md_path = allsorted, autoupdate, md_path
122
+ @debug, @topic_url = debug, topic_url
123
+ @md_path = md_path
22
124
  @default_md = default_md
125
+ @allsorted, @autoupdate = allsorted, autoupdate
23
126
 
24
- raw_s, _ = RXFHelper.read(source)
25
- build_index(raw_s)
127
+ @outline = Outline.new(source, debug: debug,
128
+ allsorted: allsorted, autoupdate: autoupdate)
26
129
 
27
130
  end
28
131
 
29
132
  def fetch(uri)
30
133
 
31
- s, remaining = @links.locate(uri)
134
+ s, remaining = @outline.locate(uri)
32
135
  puts 'fetch() s: ' + s.inspect if @debug
33
136
  redirect = s =~ /^\[r\] +/i
34
137
  return s if redirect
@@ -39,33 +142,43 @@ class MyOutline
39
142
  puts 'f: ' + f.inspect if @debug
40
143
  @md = MdEdit.new f, debug: @debug
41
144
  r = edit(remaining.sub(/^\//,'').gsub(/\//,' > '))
42
- puts 'r: ' + r.inspect if @debug
145
+ puts 'fetch() r: ' + r.inspect if @debug
43
146
  @md.update r
44
147
 
45
148
  r
46
149
  end
47
-
48
-
49
- def ls(path='.')
50
- @ftx.ls(path).map(&:to_s)
51
- end
52
150
 
53
151
  def rebuild(s)
54
- build_index(s)
152
+ @outline = Outline.new s
55
153
  end
56
154
 
57
155
  def update(section)
58
156
  @md.update section
59
- end
157
+ end
60
158
 
61
- def save(filename=nil)
159
+ def update_tree(s)
160
+
161
+ mo2 = Outline.new(s, debug: @debug,
162
+ allsorted: @allsorted, autoupdate: @autoupdate)
62
163
 
63
- if filename.nil? then
64
- filename = RXFHelper.writeable?(@source) ? @source : 'myoutline.txt'
164
+ h = @outline.links.to_h
165
+ links = mo2.links
166
+
167
+ mo2.links.to_h.each do |title, file|
168
+
169
+ if @debug then
170
+ puts 'title: ' + title.inspect
171
+ puts 'h[title]: ' + h[title].inspect
172
+ end
173
+
174
+ links.link(title).url = h[title] if h[title]
65
175
  end
66
-
67
- RXFHelper.write filename, self.to_s(declaration: true)
68
176
 
177
+ puts 'before Outline.new: ' + links.to_s(header: false).inspect if @debug
178
+
179
+ @outline = Outline.new(links.to_s(header: false), debug: @debug,
180
+ allsorted: @allsorted, autoupdate: @autoupdate)
181
+ @outline.autosave
69
182
  end
70
183
 
71
184
  def to_html()
@@ -100,39 +213,9 @@ class MyOutline
100
213
 
101
214
  end
102
215
 
103
- def to_px()
104
- @pxi.to_px
105
- end
106
-
107
- def to_s(declaration: false)
108
-
109
- if declaration == true then
110
- @pxi.to_s.sub(/(?<=^\<\?)([^\?]+)/,'myoutline')
111
- else
112
- @pxi.to_s.lines[1..-1].join.lstrip
113
- end
114
-
115
- end
116
-
117
-
118
- def to_tree
119
- format_tree(alphabet: true, nourl: true)
120
- end
121
-
122
- def to_treelinks
123
- format_tree()
124
- end
125
216
 
126
217
  private
127
218
 
128
- def build_index(s)
129
-
130
- @pxi = PxIndex.new(debug: @debug, indexsorted: true, allsorted: @allsorted)
131
- @pxi.import s
132
- save() if @autoupdate and self.to_s != s
133
- read(self.to_treelinks)
134
- end
135
-
136
219
  def edit(s)
137
220
 
138
221
  r = @md.find s
@@ -150,30 +233,6 @@ class MyOutline
150
233
 
151
234
  end
152
235
 
153
- end
154
-
155
- def format_tree(alphabet: false, nourl: false)
156
-
157
- a = @pxi.to_s.lines
158
- a.shift # remove the ph declaration
159
- a.reject! {|x| x =~ /^(?:#[^\n]+|\n+)$/} unless alphabet
160
-
161
- if nourl then
162
- # strip out the URLS?
163
- a.map! {|x| r = x[/^.*(?= # )/]; r ? r + "\n" : x }
164
- end
165
-
166
- a.join
167
-
168
- end
169
-
170
- def read(s)
171
-
172
- @links = PolyrexLinks.new.import(s, debug: @debug)
173
-
174
- s3 = s.lines.map {|x| x.split(/ | # /,2)[0]}.join("\n")
175
- @ftx = FileTreeXML.new(s3, debug: @debug)
176
-
177
236
  end
178
237
 
179
238
  def xslt()
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.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  DFhc5TDtqEkJYiaiznQFl34HUKeCAdeAHkmD8jP3fUC8O7zcLXq69EAXGMXw4efB
31
31
  3Co=
32
32
  -----END CERTIFICATE-----
33
- date: 2018-04-14 00:00:00.000000000 Z
33
+ date: 2018-04-15 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: pxindex
metadata.gz.sig CHANGED
Binary file