wikisys 0.2.0 → 0.3.0
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.tar.gz.sig +0 -0
- data/lib/wikisys.rb +198 -24
- metadata +31 -10
- 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: c1d9909e650b607db0429fcf09233a3775f1493fca6ae612354c205e4dccf69d
|
4
|
+
data.tar.gz: 646db1e4c483057d9b7d220edbd0164d9f9dce8e90408faf55da71aea2e661b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 856dfe0a483521ef2db25f220df0891f23ad2bb99d5b77b136a18df40965c9a51cc2ac1ac7789cc8345ac372fd4768b4ff93b656fc22f418479bf7351f96579f
|
7
|
+
data.tar.gz: 3cab93f28ea693edd42c273f8a5a387ed8811825943e7859a3e0ff38e3c2be877f226fd5bde967aac8d766d40dfecfbf3e71803dbabbaf4dee81d0cdd128eeee
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/wikisys.rb
CHANGED
@@ -3,12 +3,15 @@
|
|
3
3
|
# file: wikisys.rb
|
4
4
|
|
5
5
|
require 'dxlite'
|
6
|
+
require 'dir-to-xml'
|
7
|
+
require 'mindwords'
|
6
8
|
require 'martile'
|
7
9
|
|
8
10
|
module Wikisys
|
9
11
|
|
10
12
|
class Wiki
|
11
13
|
|
14
|
+
attr_accessor :title, :content, :tags
|
12
15
|
attr_reader :to_xml
|
13
16
|
|
14
17
|
def initialize(filepath='.', entries: 'entries.json', debug: false)
|
@@ -17,17 +20,22 @@ module Wikisys
|
|
17
20
|
@page = ''
|
18
21
|
@debug = debug
|
19
22
|
|
20
|
-
@entries = if
|
23
|
+
@entries = if entries.is_a? DxLite then
|
24
|
+
|
25
|
+
entries
|
26
|
+
|
27
|
+
elsif File.exists?(entries) then
|
21
28
|
|
22
29
|
DxLite.new(entries)
|
23
30
|
|
24
31
|
else
|
25
32
|
|
26
|
-
DxLite.new('entries/entry(title, tags)'
|
33
|
+
DxLite.new('entries/entry(title, tags)')
|
27
34
|
|
28
35
|
end
|
29
36
|
|
30
37
|
end
|
38
|
+
|
31
39
|
|
32
40
|
def page(title)
|
33
41
|
|
@@ -48,8 +56,8 @@ module Wikisys
|
|
48
56
|
make_page(title, raw_content.lines.last.chomp[/(?<=\+ )/]) unless r
|
49
57
|
|
50
58
|
write_md title, raw_content
|
51
|
-
|
52
|
-
@to_xml = build_xml
|
59
|
+
title, content, tags = read_md()
|
60
|
+
@to_xml = build_xml title, content, tags
|
53
61
|
write_xml title, @to_xml
|
54
62
|
|
55
63
|
|
@@ -58,13 +66,65 @@ module Wikisys
|
|
58
66
|
|
59
67
|
end
|
60
68
|
|
69
|
+
def modify_build(filename)
|
70
|
+
|
71
|
+
@title, @content, @tags = read_md(filename)
|
72
|
+
|
73
|
+
# find the entry
|
74
|
+
# modify the tags if necessary
|
75
|
+
|
76
|
+
r = @entries.find_by_title @title
|
77
|
+
puts 'r: ' + r.inspect if @debug
|
78
|
+
return unless r
|
79
|
+
|
80
|
+
write_xml(@title, build_xml(@title, @content, @tags))
|
81
|
+
|
82
|
+
r.tags = @tags.join(' ') if r.tags != @tags
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def new_build(filename)
|
87
|
+
|
88
|
+
@title, @content, @tags = read_md(filename)
|
89
|
+
@entries.create title: @title, tags: @tags.join(' ')
|
90
|
+
|
91
|
+
puts 'md contents: ' + [@title, @content, @tags].inspect if @debug
|
92
|
+
write_xml(@title, build_xml(@title, @content, @tags))
|
93
|
+
|
94
|
+
end
|
95
|
+
|
61
96
|
private
|
62
97
|
|
63
|
-
def
|
98
|
+
def read_md(filename)
|
64
99
|
|
65
|
-
|
100
|
+
filepath = File.join(@filepath, 'md', filename)
|
101
|
+
return unless File.exists? filepath
|
102
|
+
|
103
|
+
s = File.read(filepath).strip
|
104
|
+
|
105
|
+
# read the title
|
106
|
+
title = s.lines.first.chomp.sub(/^# +/,'')
|
107
|
+
|
108
|
+
# read the hashtags if there is any
|
109
|
+
tagsline = s.lines.last[/^ *\+ +(.*)/,1]
|
110
|
+
|
111
|
+
if tagsline then
|
112
|
+
|
113
|
+
[title, s.lines[1..-2].join, tagsline.split]
|
114
|
+
|
115
|
+
else
|
116
|
+
|
117
|
+
[title, s.lines[1..--1].join, []]
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
66
122
|
|
67
|
-
|
123
|
+
|
124
|
+
def build_xml(title, content, tags)
|
125
|
+
|
126
|
+
puts 'content: ' + content.inspect if @debug
|
127
|
+
s = content.gsub(/\[\[[^\]]+\]\]/) do |raw_link|
|
68
128
|
|
69
129
|
r = @entries.find_by_title title
|
70
130
|
|
@@ -88,12 +148,11 @@ module Wikisys
|
|
88
148
|
end
|
89
149
|
|
90
150
|
|
91
|
-
heading = "<heading>%s</heading>" %
|
92
|
-
tags = ''
|
151
|
+
heading = "<heading>%s</heading>" % title
|
93
152
|
|
94
|
-
if
|
153
|
+
if tags.any? then
|
95
154
|
|
96
|
-
list =
|
155
|
+
list = tags.map {|tag| " <tag>%s</tag>" % tag}
|
97
156
|
tags = "<tags>\n%s\n </tags>" % list.join("\n")
|
98
157
|
|
99
158
|
body = "<body>\n %s </body>" % \
|
@@ -110,6 +169,15 @@ module Wikisys
|
|
110
169
|
|
111
170
|
end
|
112
171
|
|
172
|
+
def write_xml(title, content)
|
173
|
+
|
174
|
+
filepath = File.join(File.absolute_path(@filepath), 'xml',
|
175
|
+
title.gsub(/ +/,'_') + '.xml')
|
176
|
+
FileUtils.mkdir_p File.dirname(filepath)
|
177
|
+
File.write filepath, content
|
178
|
+
|
179
|
+
end
|
180
|
+
|
113
181
|
def make_page(title, raw_tags=title.downcase.gsub(/['\.\(\)]/,''))
|
114
182
|
|
115
183
|
tags = raw_tags.split.join(' ')
|
@@ -121,13 +189,12 @@ module Wikisys
|
|
121
189
|
|
122
190
|
return s
|
123
191
|
|
124
|
-
end
|
192
|
+
end
|
125
193
|
|
126
|
-
def
|
127
|
-
|
128
|
-
filepath = File.join(
|
129
|
-
|
130
|
-
File.read(title.gsub(/ +/,'_') + '.md')
|
194
|
+
def read_md_file(filename)
|
195
|
+
|
196
|
+
filepath = File.join(@filepath, 'md', filename)
|
197
|
+
File.read(filepath)
|
131
198
|
|
132
199
|
end
|
133
200
|
|
@@ -138,17 +205,124 @@ module Wikisys
|
|
138
205
|
FileUtils.mkdir_p File.dirname(filepath)
|
139
206
|
File.write filepath, content
|
140
207
|
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
class Pages
|
213
|
+
|
214
|
+
attr_accessor :mw, :entries
|
215
|
+
|
216
|
+
def initialize(filepath='.', debug: false)
|
217
|
+
|
218
|
+
@filepath, @debug = filepath, debug
|
219
|
+
|
220
|
+
entries_file = File.join(@filepath, 'entries.txt')
|
221
|
+
|
222
|
+
if File.exists?(entries_file) then
|
223
|
+
@entries = DxLite.new(entries_file)
|
224
|
+
else
|
225
|
+
@entries = DxLite.new('entries/entry(title, tags)')
|
226
|
+
@entries.save entries_file
|
227
|
+
end
|
228
|
+
|
229
|
+
# check for the mindwords raw document file
|
230
|
+
mindwords_file = File.join(@filepath, 'mindwords.txt')
|
231
|
+
|
232
|
+
if File.exists?(mindwords_file) then
|
233
|
+
@mw = MindWords.new(mindwords_file)
|
234
|
+
else
|
235
|
+
@mw = MindWords.new
|
236
|
+
@mw.filepath = mindwords_file
|
237
|
+
end
|
238
|
+
|
239
|
+
scan_md_files()
|
240
|
+
|
141
241
|
end
|
142
242
|
|
143
|
-
|
243
|
+
private
|
244
|
+
|
245
|
+
|
246
|
+
# Check if any of the md files have been modified or newly created
|
247
|
+
#
|
248
|
+
def scan_md_files()
|
144
249
|
|
145
|
-
filepath = File.join(
|
146
|
-
|
147
|
-
|
148
|
-
|
250
|
+
filepath = File.join(@filepath, 'md')
|
251
|
+
puts 'about to scan ' + filepath.inspect if @debug
|
252
|
+
dir = DirToXML.new(filepath, index: 'dir.json', debug: @debug)
|
253
|
+
h = dir.activity
|
254
|
+
puts 'h: ' + h.inspect if @debug
|
149
255
|
|
150
|
-
|
256
|
+
pg = Wiki.new @filepath, entries: @entries
|
257
|
+
|
258
|
+
|
259
|
+
h[:new].each do |filename|
|
260
|
+
|
261
|
+
pg.new_build(filename)
|
262
|
+
update_mw(pg.title, pg.tags)
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
h[:modified].each do |filename|
|
267
|
+
|
268
|
+
pg.modify_build(filename)
|
269
|
+
update_mw(pg.title, pg.tags)
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
@entries.save
|
274
|
+
@mw.save if @mw.lines.any?
|
275
|
+
|
276
|
+
end # /scan_md_files
|
151
277
|
|
152
|
-
|
278
|
+
def update_mw(title, line_tags)
|
279
|
+
|
280
|
+
# read the file
|
153
281
|
|
282
|
+
tags = line_tags.reject {|x| x =~ /#{title.strip}/i}
|
283
|
+
puts 'tags: ' + tags.inspect if @debug
|
284
|
+
puts 'title: ' + title.inspect if @debug
|
285
|
+
|
286
|
+
return if tags.empty?
|
287
|
+
|
288
|
+
line = title + ' ' + tags.map {|x| "#" + x }.join(' ') + "\n"
|
289
|
+
puts 'line: ' + line.inspect if @debug
|
290
|
+
|
291
|
+
# does the tagsline contain the topic hashtag?
|
292
|
+
|
293
|
+
#if tagsline =~ /#/ # not yet implemented
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
# check if the title already exists
|
298
|
+
found = @mw.lines.grep(/^#{title} +(?=#)/i)
|
299
|
+
|
300
|
+
if found.any? then
|
301
|
+
|
302
|
+
found_tags = found.first.scan(/(?<=#)\w+/)
|
303
|
+
|
304
|
+
if @debug then
|
305
|
+
|
306
|
+
puts 'tags: ' + tags.inspect
|
307
|
+
puts 'found_tags: ' + found_tags.inspect
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
new_tags = tags - found_tags
|
312
|
+
|
313
|
+
# add the new tags to the mindwords line
|
314
|
+
|
315
|
+
hashtags = (found_tags + new_tags).map {|x| '#' + x }.join(' ')
|
316
|
+
|
317
|
+
i = @mw.lines.index(found.first)
|
318
|
+
@mw.lines[i] = line
|
319
|
+
|
320
|
+
else
|
321
|
+
|
322
|
+
@mw.lines << line
|
323
|
+
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
end
|
154
328
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikisys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,28 +35,48 @@ cert_chain:
|
|
35
35
|
O3SRDzvvWXrwDFGyRDmGqdEw51FKHPw/6pk4ci0QPIvQEgOyPKfdSesPWmNmtxpf
|
36
36
|
KX/89ohIpftt89vtcCI21R5u
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2021-01-29 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: dir-to-xml
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0
|
46
|
+
version: '1.0'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 0.
|
49
|
+
version: 1.0.4
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '0
|
56
|
+
version: '1.0'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 0.
|
59
|
+
version: 1.0.4
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: mindwords
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.5'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.5.3
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.5'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.5.3
|
60
80
|
- !ruby/object:Gem::Dependency
|
61
81
|
name: martile
|
62
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +86,7 @@ dependencies:
|
|
66
86
|
version: '1.4'
|
67
87
|
- - ">="
|
68
88
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.4.
|
89
|
+
version: 1.4.6
|
70
90
|
type: :runtime
|
71
91
|
prerelease: false
|
72
92
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -76,7 +96,7 @@ dependencies:
|
|
76
96
|
version: '1.4'
|
77
97
|
- - ">="
|
78
98
|
- !ruby/object:Gem::Version
|
79
|
-
version: 1.4.
|
99
|
+
version: 1.4.6
|
80
100
|
description:
|
81
101
|
email: james@jamesrobertson.eu
|
82
102
|
executables: []
|
@@ -103,7 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
123
|
- !ruby/object:Gem::Version
|
104
124
|
version: '0'
|
105
125
|
requirements: []
|
106
|
-
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.7.10
|
107
128
|
signing_key:
|
108
129
|
specification_version: 4
|
109
130
|
summary: A poor man's wiki.
|
metadata.gz.sig
CHANGED
Binary file
|