soywiki 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -490,6 +490,19 @@ pattern. But SoyWiki stands with CamelCase.
490
490
  No wiki link pattern is perfect! All involve trade-offs. The CamelCase
491
491
  pattern gives you a lot in return for its particular compromises.
492
492
 
493
+ ## Hyperlinks
494
+
495
+ There may come the time when you want to link to content, that
496
+ isn't part of your wiki. The common link-syntax will allow
497
+ you to refer to websites. But if you want to link
498
+ to something in your own filesystem you can
499
+ also use the `file://` schema. This schema
500
+ actually only allows absolute file paths. To circumvent
501
+ this problem we have added support for our own schema:
502
+ `soyfile://` which allows to link to files relative
503
+ to the wiki root or, if you use vim's
504
+ *autochdir* option, relative to the current namespace.
505
+
493
506
 
494
507
  ## Bug reports and feature requests
495
508
 
@@ -1,9 +1,10 @@
1
1
  require 'string_ext'
2
2
  module Template_Substitution; end
3
3
  module Soywiki
4
- VERSION = '0.9.6'
4
+ VERSION = '0.9.7'
5
5
  WIKI_WORD = /\b([a-z0-9][\w_]+\.)?[A-Z][a-z]+[A-Z0-9]\w*\b/
6
- HYPERLINK = %r|\bhttps?://[^ >)\n\]]+|
6
+ SCHEMES = %w{https http file soyfile}
7
+ HYPERLINK = %r|\b(?:#{SCHEMES.join('|')})://[^ >)\n\]]+|
7
8
 
8
9
  def self.run
9
10
  require 'getoptlong'
@@ -12,7 +12,8 @@ let mapleader = ','
12
12
 
13
13
  " This regex matches namedspaced WikiWords and unqualified WikiWords
14
14
  let s:wiki_link_pattern = '\C\m\<\([a-z0-9][[:alnum:]_]\+\.\)\?[A-Z][a-z]\+[A-Z0-9]\w*\>'
15
- let s:http_link_pattern = '\v(https|http|file|):[^ >)\]]+\V'
15
+ let s:uri_link_pattern = '\v(https|http|file|soyfile):[^ >)\]]+\V'
16
+ let s:soyfile_pattern = '\v^soyfile:[^ >)\]]+\V'
16
17
  let s:wiki_or_web_link_pattern = '\C\<\([a-z0-9][[:alnum:]_]\+\.\)\?[A-Z][a-z]\+[A-Z0-9]\w*\>\|https\?:[^ >)\]]\+'
17
18
 
18
19
  let s:rename_links_command = 'soywiki-rename '
@@ -33,6 +34,12 @@ func! s:page_title()
33
34
  return page_title
34
35
  endfunc
35
36
 
37
+ func! s:current_namespace_path()
38
+ let absolutepath = expand('%:p')
39
+ let dir_path = fnamemodify(absolutepath, ':h')
40
+ return dir_path
41
+ endfunc
42
+
36
43
  func! s:wiki_root()
37
44
  let root_path = split(system("git rev-parse --show-toplevel"), "\n")[0] . '/'
38
45
  return root_path
@@ -167,7 +174,7 @@ endfunc
167
174
 
168
175
  func! s:follow_link_under_cursor(split)
169
176
  let word = expand("<cWORD>")
170
- if match(word, s:http_link_pattern) != -1
177
+ if match(word, s:uri_link_pattern) != -1
171
178
  call s:open_href_under_cursor()
172
179
  return
173
180
  endif
@@ -595,19 +602,49 @@ endfunc
595
602
  "------------------------------------------------------------------------
596
603
  func! s:open_href_under_cursor()
597
604
  let word = expand("<cWORD>")
598
- let href = matchstr(word, s:http_link_pattern)
599
- let command = g:SoyWiki#browser_command . " '" . href . "' "
605
+ let soyuri = matchstr(word, s:uri_link_pattern)
606
+ let uri = s:expand_iana_uri(soyuri)
607
+ let command = g:SoyWiki#browser_command . " '" . uri . "' "
600
608
  call system(command)
601
609
  echom command
602
610
  endfunc
603
611
 
604
612
  func! s:find_next_href_and_open()
605
- let res = search(s:http_link_pattern, 'cw')
613
+ let res = search(s:uri_link_pattern, 'cw')
606
614
  if res != 0
607
615
  call s:open_href_under_cursor()
608
616
  endif
609
617
  endfunc
610
618
 
619
+ func! s:expand_iana_uri(soyuri)
620
+ if match(a:soyuri, s:soyfile_pattern) != -1
621
+ let autochdir_rel_path = s:current_namespace_path()
622
+ let wiki_rel_path = s:wiki_root()
623
+
624
+ let filepath = substitute(a:soyuri, 'soyfile://', '', '')
625
+
626
+ " the case that the soyfile is actually an absolute path
627
+ if match(filepath, '\v^/') != -1
628
+ return "file://" . filepath
629
+ endif
630
+
631
+ let autochdir_path = fnamemodify(autochdir_rel_path . '/' . filepath, ':p')
632
+ let wiki_path = fnamemodify(wiki_rel_path . '/' . filepath, ':p')
633
+ let uri_path_part = wiki_path
634
+
635
+ " the case that the path supplied was relative to
636
+ " the current namespace directory (autochdir-option)
637
+ if filereadable(autochdir_path)
638
+ let uri_path_part = autochdir_path
639
+ endif
640
+
641
+ return 'file://' . uri_path_part
642
+ else
643
+ " return non-soyfile uris unchanged
644
+ return a:soyuri
645
+ end
646
+ endfunc
647
+
611
648
  func! s:goto_homepage(main)
612
649
  if a:main
613
650
  call s:load_page("main.HomePage", 0)
@@ -701,7 +738,7 @@ func! s:highlight_wikiwords()
701
738
  if (s:is_wiki_page())
702
739
  "syntax clear
703
740
  exe "syn match Comment /". s:wiki_link_pattern. "/"
704
- exe "syn match Constant /". s:http_link_pattern . "/"
741
+ exe "syn match Constant /". s:uri_link_pattern . "/"
705
742
  endif
706
743
  endfunc
707
744
 
@@ -7,6 +7,7 @@ module Soywiki
7
7
  HTML_DIR = 'html-export'
8
8
  INDEX_PAGE_TEMPLATE = File.read(File.join(File.dirname(__FILE__), '..', 'index_template.html.haml'))
9
9
  BROKEN_MARKDOWN_HYPERLINK = %r|\[([^\]]+)\]\(\[(#{HYPERLINK})\]\(\2\)\)|
10
+ @current_namespace = nil
10
11
 
11
12
  def self.href_wiki_links(text)
12
13
  text = text.gsub(WIKI_WORD) {|match|
@@ -24,17 +25,38 @@ module Soywiki
24
25
  substitute = if @markdown then '[\\0](\\0)' else '<a href="\\0">\\0</a>' end
25
26
  text = text.gsub(HYPERLINK, substitute)
26
27
  if @markdown
27
- text = text.gsub(BROKEN_MARKDOWN_HYPERLINK, '[\\1](\\2)')
28
+ text = text.gsub(BROKEN_MARKDOWN_HYPERLINK, '[\\1](\\2)')
28
29
  end
30
+ text = text.gsub(HYPERLINK) { |uri| soyfile_to_uri(uri) }
29
31
  return text
30
32
  end
31
33
 
34
+ def self.soyfile_to_uri(uri)
35
+ uri_after_scheme = %r{[^ >)\n\]]+}
36
+ if uri =~ %r{^soyfile://(#{uri_after_scheme})}
37
+ path = choose_soyfile_path($1)
38
+ return "file://#{path}" if path[0] == '/'
39
+ else
40
+ return uri
41
+ end
42
+ end
43
+
44
+ def self.choose_soyfile_path(path)
45
+ return path if path[0] == '/'
46
+ wiki_root = Dir.getwd
47
+ autochdir_path = File.absolute_path(
48
+ File.join(wiki_root, @current_namespace, path))
49
+ wiki_path = File.absolute_path(File.join(wiki_root, path))
50
+ File.exists?(autochdir_path) ? autochdir_path : wiki_path
51
+ end
52
+
32
53
  def self.process(t)
33
54
  href_hyperlinks(href_wiki_links(t))
34
55
  end
35
56
 
36
57
  PAGE_TEMPLATE = File.read(File.join(File.dirname(__FILE__), '..', 'page_template.html.haml'))
37
58
  def self.generate_page(text, namespace, pages, namespaces)
59
+ @current_namespace = namespace
38
60
  text = text.split("\n")
39
61
 
40
62
  title = text.shift || ''
@@ -123,11 +145,13 @@ module Soywiki
123
145
  count = Dir["#{namespace}/*"].select {|f| wiki_page?(f)}.size
124
146
  [namespace, count]
125
147
  }
148
+ @current_namespace = nil
126
149
  namespaces.each do |namespace_dir, count|
127
150
  make_pages namespace_dir, namespaces
128
151
  end
129
152
  # make root index page
130
153
  make_root_index_page namespaces
154
+ @current_namespace = nil
131
155
  puts "HTML files written to #{HTML_DIR}/"
132
156
  end
133
157
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soywiki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-21 00:00:00.000000000 Z
12
+ date: 2013-09-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A personal and collaborative wiki for Vim users
15
15
  email: