wikisys 0.3.0 → 0.4.3

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: c1d9909e650b607db0429fcf09233a3775f1493fca6ae612354c205e4dccf69d
4
- data.tar.gz: 646db1e4c483057d9b7d220edbd0164d9f9dce8e90408faf55da71aea2e661b4
3
+ metadata.gz: efc308c07d4ba81540d515d9e0ea02f7c60c74aedeea31e771a228af9c29b436
4
+ data.tar.gz: fccd8271b207195f628a8f0bd7aea544545b02aead003bfd401cb51b1b589ac2
5
5
  SHA512:
6
- metadata.gz: 856dfe0a483521ef2db25f220df0891f23ad2bb99d5b77b136a18df40965c9a51cc2ac1ac7789cc8345ac372fd4768b4ff93b656fc22f418479bf7351f96579f
7
- data.tar.gz: 3cab93f28ea693edd42c273f8a5a387ed8811825943e7859a3e0ff38e3c2be877f226fd5bde967aac8d766d40dfecfbf3e71803dbabbaf4dee81d0cdd128eeee
6
+ metadata.gz: 25bfc39f238a76d18e37d62b104abb495adb83739a1cb2122c03078b92d1b6b353b5331f7bd483aeb6760ac580fa7823b82c9f1d9bfe2ae59f68b5b7718bd46a
7
+ data.tar.gz: 0b0e0335c7e15496b52b8f09bd14442f1bf9877671de04e46f47d7e73f610711052896c967f0fe05569322ed2b3d11377449731cbbafca593fcb957e47fa3c13
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -6,10 +6,33 @@ require 'dxlite'
6
6
  require 'dir-to-xml'
7
7
  require 'mindwords'
8
8
  require 'martile'
9
+ require 'hashcache'
10
+
11
+ module FileFetch
12
+
13
+ def fetch_filepath(filename)
14
+
15
+ lib = File.dirname(__FILE__)
16
+ File.join(lib,'..','stylesheet',filename)
17
+
18
+ end
19
+
20
+ def fetch_file(filename)
21
+
22
+ filepath = fetch_filepath filename
23
+ read filepath
24
+ end
25
+
26
+ def read(s)
27
+ RXFHelper.read(s).first
28
+ end
29
+ end
9
30
 
10
31
  module Wikisys
11
32
 
12
- class Wiki
33
+ class Wiki
34
+ include FileFetch
35
+ using ColouredText
13
36
 
14
37
  attr_accessor :title, :content, :tags
15
38
  attr_reader :to_xml
@@ -19,6 +42,8 @@ module Wikisys
19
42
  @filepath = filepath
20
43
  @page = ''
21
44
  @debug = debug
45
+
46
+ @hc = HashCache.new(size:30)
22
47
 
23
48
  @entries = if entries.is_a? DxLite then
24
49
 
@@ -36,6 +61,17 @@ module Wikisys
36
61
 
37
62
  end
38
63
 
64
+ def create_breadcrumb(filepath, links)
65
+
66
+ doc = Rexle.new(read_file(filepath))
67
+ heading = doc.root.element('heading')
68
+
69
+ menu = Rexle.new(HtmlCom::Menu.new(:breadcrumb, links).to_html)
70
+
71
+ heading.insert_before menu.root
72
+ write_file filepath, doc.root.xml
73
+
74
+ end
39
75
 
40
76
  def page(title)
41
77
 
@@ -68,16 +104,24 @@ module Wikisys
68
104
 
69
105
  def modify_build(filename)
70
106
 
107
+ puts 'inside modify_buld' if @debug
108
+
71
109
  @title, @content, @tags = read_md(filename)
72
110
 
73
111
  # find the entry
74
112
  # modify the tags if necessary
113
+ puts '@title: ' + @title.inspect if @debug
114
+ puts '_ @content: ' + @content.inspect if @debug
75
115
 
76
116
  r = @entries.find_by_title @title
77
117
  puts 'r: ' + r.inspect if @debug
78
- return unless r
79
118
 
80
- write_xml(@title, build_xml(@title, @content, @tags))
119
+ if r.nil? then
120
+ r = @entries.create title: @title, tags: @tags.join(' ')
121
+ end
122
+
123
+ xmlfile = filename.sub(/\.md$/,'.xml')
124
+ write_xml(xmlfile, build_xml(@title, @content, @tags))
81
125
 
82
126
  r.tags = @tags.join(' ') if r.tags != @tags
83
127
 
@@ -93,20 +137,45 @@ module Wikisys
93
137
 
94
138
  end
95
139
 
140
+ def read_file(file='index.html')
141
+ @hc.read(file) { File.read(file) }
142
+ end
143
+
144
+ def to_css()
145
+ fetch_file 'pg.css'
146
+ end
147
+
148
+ def write_html(filename)
149
+
150
+ FileUtils.mkdir_p File.join(@filepath, 'html')
151
+
152
+ xml = read_file File.join(@filepath, 'xml', filename)
153
+ puts 'about to fetch_file' if @debug
154
+ xsl = fetch_file 'pg.xsl'
155
+ puts 'xsl: ' + xsl.inspect if @debug
156
+
157
+ html_file = File.join(@filepath, 'html', filename.sub(/\.xml$/,'.html'))
158
+ write_file(html_file, transform(xsl, xml))
159
+
160
+ end
161
+
96
162
  private
97
163
 
98
164
  def read_md(filename)
99
165
 
100
166
  filepath = File.join(@filepath, 'md', filename)
167
+ puts 'filepath : ' + filepath.inspect if @debug
101
168
  return unless File.exists? filepath
102
169
 
103
- s = File.read(filepath).strip
170
+ s = read_file(filepath).strip.gsub(/\r/,'')
171
+ puts 's: ' + s.inspect if @debug
104
172
 
105
173
  # read the title
106
174
  title = s.lines.first.chomp.sub(/^# +/,'')
107
175
 
108
176
  # read the hashtags if there is any
109
177
  tagsline = s.lines.last[/^ *\+ +(.*)/,1]
178
+ puts 'tagsline: ' + tagsline.inspect if @debug
110
179
 
111
180
  if tagsline then
112
181
 
@@ -114,14 +183,13 @@ module Wikisys
114
183
 
115
184
  else
116
185
 
117
- [title, s.lines[1..--1].join, []]
186
+ [title, s.lines[1..-1].join, []]
118
187
 
119
188
  end
120
189
 
121
- end
122
-
190
+ end
123
191
 
124
- def build_xml(title, content, tags)
192
+ def build_xml(title, content, rawtags)
125
193
 
126
194
  puts 'content: ' + content.inspect if @debug
127
195
  s = content.gsub(/\[\[[^\]]+\]\]/) do |raw_link|
@@ -150,7 +218,7 @@ module Wikisys
150
218
 
151
219
  heading = "<heading>%s</heading>" % title
152
220
 
153
- if tags.any? then
221
+ if rawtags.any? then
154
222
 
155
223
  list = tags.map {|tag| " <tag>%s</tag>" % tag}
156
224
  tags = "<tags>\n%s\n </tags>" % list.join("\n")
@@ -161,23 +229,43 @@ module Wikisys
161
229
  else
162
230
 
163
231
  body = "<body>%s</body>" % Martile.new(s.lines[1..-1].join.strip).to_html
232
+ tags = ''
164
233
 
165
234
  end
166
235
 
167
- "<article>\n %s\n %s\n %s\n</article>" % [heading, body, tags]
236
+ "<article id='%s'>\n %s\n %s\n %s\n</article>" % \
237
+ [title.gsub(/ +/,'-'), heading, body, tags]
168
238
 
169
239
 
170
240
  end
171
241
 
172
- def write_xml(title, content)
242
+
243
+ def transform(xsl, xml)
244
+
245
+ doc = Nokogiri::XML(xml)
246
+ xslt = Nokogiri::XSLT(xsl)
247
+
248
+ xslt.transform(doc)
249
+
250
+ end
251
+
252
+ def write_xml(s, content)
173
253
 
174
- filepath = File.join(File.absolute_path(@filepath), 'xml',
175
- title.gsub(/ +/,'_') + '.xml')
254
+ filename = s =~ /\.xml$/ ? s : s.gsub(/ +/,'_') + '.xml'
255
+ filepath = File.join(File.absolute_path(@filepath), 'xml', filename)
176
256
  FileUtils.mkdir_p File.dirname(filepath)
177
- File.write filepath, content
257
+ #File.write filepath, content
258
+ write_file filepath, content
178
259
 
179
260
  end
180
261
 
262
+ def write_file(filepath, content)
263
+
264
+ puts 'writing file: ' + filepath.inspect if @debug
265
+ File.write filepath, content
266
+ @hc.write(filepath) { content }
267
+ end
268
+
181
269
  def make_page(title, raw_tags=title.downcase.gsub(/['\.\(\)]/,''))
182
270
 
183
271
  tags = raw_tags.split.join(' ')
@@ -200,8 +288,9 @@ module Wikisys
200
288
 
201
289
  def write_md(title, content)
202
290
 
203
- filepath = File.join(File.absolute_path(@filepath), 'md',
204
- title.gsub(/ +/,'_') + '.md')
291
+ puts 'inside write_md' if @debug
292
+ filename = s =~ /\.md$/ ? s : s.gsub(/ +/,'_') + '.md'
293
+ filepath = File.join(File.absolute_path(@filepath), 'md', filename)
205
294
  FileUtils.mkdir_p File.dirname(filepath)
206
295
  File.write filepath, content
207
296
 
@@ -236,10 +325,26 @@ module Wikisys
236
325
  @mw.filepath = mindwords_file
237
326
  end
238
327
 
239
- scan_md_files()
328
+ @pg = Wiki.new @filepath, entries: @entries, debug: @debug
329
+
330
+ #scan_md_files()
240
331
 
241
332
  end
242
333
 
334
+ def new_pg(filename)
335
+
336
+ @pg.new_build(filename)
337
+ update_mw(@pg.title, @pg.tags)
338
+
339
+ end
340
+
341
+ def update_pg(filename)
342
+
343
+ @pg.modify_build(filename)
344
+ update_mw(@pg.title, @pg.tags)
345
+
346
+ end
347
+
243
348
  private
244
349
 
245
350
 
@@ -253,25 +358,41 @@ module Wikisys
253
358
  h = dir.activity
254
359
  puts 'h: ' + h.inspect if @debug
255
360
 
256
- pg = Wiki.new @filepath, entries: @entries
257
-
361
+ return if (h[:new] + h[:modified]).empty?
258
362
 
259
- h[:new].each do |filename|
363
+ h[:new].each {|filename| new_pg(filename) }
364
+ h[:modified].each {|filename| update_pg(filename) }
260
365
 
261
- pg.new_build(filename)
262
- update_mw(pg.title, pg.tags)
263
-
264
- end
366
+ @mw.save if @mw.lines.any?
367
+ outline_filepath = File.join(@filepath, 'myoutline.txt')
265
368
 
266
- h[:modified].each do |filename|
369
+ File.write outline_filepath, @mw.to_outline
370
+
371
+ (h[:new] + h[:modified]).each do |filename|
372
+
373
+ xml_file = filename.sub(/\.md$/,'.xml')
374
+ filepath = File.join(@filepath, 'xml', xml_file)
375
+ s = pg.read_file filepath
376
+ title = Rexle.new(s).root.text('heading')
377
+ puts 'about to search title: ' + title.inspect if @debug
378
+ found = @mw.search(title)
379
+
380
+ if found then
381
+
382
+ links = found.breadcrumb.map do |x|
383
+ [x, x.gsub(/ +/,'-') + '.html']
384
+ end
385
+
386
+ pg.create_breadcrumb(filepath, links)
387
+
388
+ end
389
+
390
+ pg.write_html xml_file
267
391
 
268
- pg.modify_build(filename)
269
- update_mw(pg.title, pg.tags)
270
-
271
392
  end
272
393
 
273
394
  @entries.save
274
- @mw.save if @mw.lines.any?
395
+
275
396
 
276
397
  end # /scan_md_files
277
398
 
@@ -324,5 +445,11 @@ module Wikisys
324
445
  end
325
446
 
326
447
  end
448
+
449
+
450
+ def view_file(file='index.html')
451
+ @hc.read(file) { File.read(file) }
452
+ end
453
+
327
454
  end
328
455
  end
@@ -0,0 +1,75 @@
1
+
2
+
3
+ /* begin breadcrumb.css */
4
+
5
+ body {font-family: Arial;}
6
+
7
+ /* Style the list */
8
+ ul.breadcrumb {
9
+ padding: 10px 16px;
10
+ list-style: none;
11
+ background-color: #eee;
12
+ }
13
+
14
+ /* Display list items side by side */
15
+ ul.breadcrumb li {
16
+ display: inline;
17
+ font-size: 18px;
18
+ }
19
+
20
+ /* Add a slash symbol (/) before/behind each list item */
21
+ ul.breadcrumb li+li:before {
22
+ padding: 8px;
23
+ color: black;
24
+ content: "/\00a0";
25
+ }
26
+
27
+ /* Add a color to all links inside the list */
28
+ ul.breadcrumb li a {
29
+ color: #0275d8;
30
+ text-decoration: none;
31
+ }
32
+
33
+ /* Add a color on mouse-over */
34
+ ul.breadcrumb li a:hover {
35
+ color: #01447e;
36
+ text-decoration: underline;
37
+ }
38
+
39
+ /* end breadcrumb */
40
+
41
+ article {
42
+ background-color: rgba(255,255,255,0.5);
43
+ padding: 1.1em;
44
+ margin: 0.4em;
45
+ }
46
+
47
+ header div {text-align: right}
48
+ #tags {
49
+ background-color: transparent;
50
+ padding: 2.5em 1.0em;
51
+ margin: 1.0em 0em;
52
+ list-style-type: none
53
+ }
54
+ #tags li {
55
+ background-color: transparent;
56
+ display: inline;
57
+ padding: 0.1em;
58
+ margin: 1.3em 0.1em;
59
+ color: #fff;
60
+ }
61
+
62
+ #tags li a {
63
+ background-color: #eee;
64
+ color: #a95;
65
+ text-decoration: none;
66
+ font-family: "Courier";
67
+ font-weight: 600;
68
+ font-size: 0.9em;
69
+ padding: 0.4em 0.6em;
70
+ margin: 0.3em;
71
+
72
+ }
73
+
74
+ #tags li:hover {background-color: transparent; }
75
+ #tags li a:hover { background-color: #ededed; color: #66e; }
@@ -0,0 +1,52 @@
1
+ <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
2
+
3
+ <xsl:template match='article'>
4
+
5
+ <html>
6
+ <head>
7
+ <link rel="stylesheet" type="text/css" href=pg.css"/>
8
+ </head>
9
+ <body>
10
+ <xsl:variable name='id' select='@id'/>
11
+ <header><div><a href='../edit?id={$id}'>edit</a></div></header>
12
+ <div>
13
+ <xsl:copy-of select='ul[@class="breadcrumb"]' />
14
+ </div>
15
+ <article>
16
+ <xsl:apply-templates select='heading' />
17
+ <xsl:copy-of select='body/*' />
18
+ </article>
19
+ <xsl:apply-templates select='tags' />
20
+ </body>
21
+ </html>
22
+
23
+ </xsl:template>
24
+
25
+ <xsl:template match='heading'>
26
+
27
+ <h1><xsl:value-of select='.' /></h1>
28
+
29
+ </xsl:template>
30
+
31
+ <xsl:template match='tags'>
32
+
33
+ <ul id='tags'>
34
+ <xsl:apply-templates select='tag' />
35
+ </ul>
36
+
37
+ </xsl:template>
38
+
39
+ <xsl:template match='tag'>
40
+
41
+ <li>
42
+ <xsl:element name='a'>
43
+ <xsl:attribute name='href'>
44
+ ../hashtags.html#<xsl:value-of select='.' />
45
+ </xsl:attribute>
46
+ <xsl:value-of select='.' />
47
+ </xsl:element>
48
+ </li>
49
+
50
+ </xsl:template>
51
+
52
+ </xsl:stylesheet>
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.3.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  O3SRDzvvWXrwDFGyRDmGqdEw51FKHPw/6pk4ci0QPIvQEgOyPKfdSesPWmNmtxpf
36
36
  KX/89ohIpftt89vtcCI21R5u
37
37
  -----END CERTIFICATE-----
38
- date: 2021-01-29 00:00:00.000000000 Z
38
+ date: 2021-01-31 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: dir-to-xml
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0.5'
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 0.5.3
69
+ version: 0.5.4
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0.5'
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: 0.5.3
79
+ version: 0.5.4
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: martile
82
82
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +97,26 @@ dependencies:
97
97
  - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: 1.4.6
100
+ - !ruby/object:Gem::Dependency
101
+ name: hashcache
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '0.2'
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 0.2.10
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.2'
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 0.2.10
100
120
  description:
101
121
  email: james@jamesrobertson.eu
102
122
  executables: []
@@ -104,6 +124,8 @@ extensions: []
104
124
  extra_rdoc_files: []
105
125
  files:
106
126
  - lib/wikisys.rb
127
+ - stylesheet/pg.css
128
+ - stylesheet/pg.xsl
107
129
  homepage: https://github.com/jrobertson/wikisys
108
130
  licenses:
109
131
  - MIT
metadata.gz.sig CHANGED
Binary file