wiki_md 0.6.1 → 0.7.0

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: 4d102bbd2d97c198ed236ce9c8c5e89167091cc402b583943e1bd8b596f5bc23
4
- data.tar.gz: 7ebd2fcca491e92a3154a1a0616a1fca32fef966e5fb9b0ab0772a8cd3654627
3
+ metadata.gz: 39807ec060776358c5aced8404ef1ea984764344f62f3e2780fba7f643eb1ac5
4
+ data.tar.gz: b3cf99153dd820c632300f47727c3201b657f500be7798cfbf62e6651b0e699a
5
5
  SHA512:
6
- metadata.gz: 45093acbd1e81207e314ae89d86e4a2eca90927f07fbf1929cc7e6abd80d677b29d7957f2d3aba668b76f1f98a0c44205c44faef153abcf8db9bc3aee4920a4b
7
- data.tar.gz: 1a134e25327c88c02e746e270e26ab5eccb7e3ef5933534ca1fbc660d601835fb0b77e997cf3d43897b26ab1594f92b51b75516695d230e2dae6147cebb15032
6
+ metadata.gz: 77b76727a5f71fcbf949d93f87b992bf5f0b2ef774994a69b6e0b3301629f0e759d7fac63c0f95f3b4c76c03475894e55b390c560307c9052e229a809c6a67ff
7
+ data.tar.gz: 46ed0505da571590568c795c8e5794a3edeb59470b80f5a67649789c9302a43f26f2bfd7dc80650615ed574cd84b96f15420e592b4d4e790351dc76b98e81e74
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/wiki_md.rb CHANGED
@@ -12,6 +12,47 @@ class WikiMd
12
12
 
13
13
  attr_reader :active_heading, :filename, :dx
14
14
 
15
+ class Entry
16
+
17
+ attr_reader :heading, :body, :footer, :tags, :x
18
+
19
+ def initialize(rx)
20
+
21
+ @rx = rx
22
+ @x = @rx.x
23
+ parse_x()
24
+
25
+ end
26
+
27
+ def body=(s)
28
+ text_entry = "%s\n\n%s\n\n%s" % [self.heading, s, self.footer]
29
+ self.x = text_entry
30
+ end
31
+
32
+ def footer=(s)
33
+ a = @x.lines
34
+ a[-1] = s
35
+ self.x = a.join
36
+ end
37
+
38
+ def x=(s)
39
+ @rx.x = s
40
+ parse_x()
41
+ end
42
+
43
+ private
44
+
45
+ def parse_x()
46
+
47
+ a = @rx.x.lines
48
+ @heading, @footer, @body = a.shift.chomp[/(?<=# ).*/], a.pop,
49
+ a.join.strip
50
+ @tags = @footer[1..-1].strip.split
51
+
52
+ end
53
+
54
+ end
55
+
15
56
  def initialize(wiki=nil, domain: nil, debug: false, base_url: '',
16
57
  tag_base_url: '/tag', order: 'ascending', title: 'MyWiki')
17
58
 
@@ -136,16 +177,17 @@ class WikiMd
136
177
  def find(q)
137
178
 
138
179
  puts ('WikiMd::find q: ' + q.inspect).debug if @debug
139
- return @dxsx.dx.find q if q =~ /^\d+$/
180
+ return Entry.new(@dxsx.dx.find q) if q =~ /^\d+$/
140
181
  regex = q.is_a?(String) ? /#{q}/i : q
141
182
  r = @dxsx.dx.all.find {|section| section.x.lines.first =~ regex }
142
183
  puts (' r: ' + r.inspect).debug if @debug
143
184
  return unless r
144
185
 
145
186
  heading2 = r.x.lines.last[/(?<=redirect ).*/]
146
- heading2 ? find(heading2) : r
187
+ heading2 ? find(heading2) : Entry.new(r)
147
188
 
148
- end
189
+ end
190
+
149
191
 
150
192
  def find_tag(tag)
151
193
  @dxtags.find tag
@@ -228,7 +270,7 @@ EOF
228
270
  @dxsx.save filename.sub(/\.md$/, '.xml')
229
271
  @dx = new_index(File.join(@filepath, 'index.xml')) unless @dx
230
272
 
231
- end
273
+ end
232
274
 
233
275
  def title()
234
276
  @dxsx.dx.title()
@@ -297,18 +339,7 @@ EOF
297
339
 
298
340
  # update the index entry if the title or tags have been modified
299
341
 
300
- title, tagline2 = rx.title.split(/\s+#/)
301
-
302
-
303
- if title != @active_heading or tagline2 != tagline1 then
304
-
305
- record = {title: @active_heading + ' #' + tagline1.split.join(' #'),
306
- url: [@base_url, File.basename(@filename)[/.*(?=\.\w+)/],
307
- URI.escape(title)].join('/')}
308
- rx.update record
309
- @dxtags.add record
310
-
311
- end
342
+ update_index(rx, tagline1, @active_heading)
312
343
 
313
344
 
314
345
  else
@@ -338,6 +369,28 @@ EOF
338
369
  @dxsx.dx
339
370
  end
340
371
 
372
+ def save_files()
373
+ @filepath = File.dirname(@filename)
374
+ FileX.write @filename=filename, @dxsx.to_s
375
+ @dx.save
376
+ end
377
+
378
+ def update_index(rx, tagline1, active_heading=nil)
379
+
380
+ title, tagline2 = rx.title.split(/\s+#/)
381
+ active_heading ||= title
382
+
383
+ if title != active_heading or tagline2 != tagline1 then
384
+
385
+ record = {title: active_heading + ' #' + tagline1.split.join(' #'),
386
+ url: [@base_url, File.basename(@filename)[/.*(?=\.\w+)/],
387
+ URI.escape(title.gsub(/ /,'_'))].join('/')}
388
+ rx.update record
389
+ @dxtags.add record
390
+
391
+ end
392
+ end
393
+
341
394
  private
342
395
 
343
396
  def load_index(indexfile)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wiki_md
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  nEQURKgvgTAqVg9tuqcjEE861mSCPc+12rmUHVBZDxMDQF6CQbnOxrYRIS+7fnia
36
36
  kikBQtN17cUMyGOrZTVRhVGR
37
37
  -----END CERTIFICATE-----
38
- date: 2019-01-04 00:00:00.000000000 Z
38
+ date: 2019-01-05 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: dxsectionx
metadata.gz.sig CHANGED
Binary file