Permalink
Browse files

add function to convert soyfile:// to file://

For autochdir compatibility it will first try to resolve the path
relative to the current namespace; if this fails it will default
back to a path relative to the wikis root directory.

Also add a helper function to determine full namespace path.
  • Loading branch information...
1 parent d8ac29c commit 15cc852e94c8a10c9c0ac8600068bc494b2b05ad @0robustus1 0robustus1 committed Aug 23, 2013
Showing with 28 additions and 0 deletions.
  1. +28 −0 lib/soywiki.vim
View
@@ -13,6 +13,7 @@ let mapleader = ','
" This regex matches namedspaced WikiWords and unqualified WikiWords
let s:wiki_link_pattern = '\C\m\<\([a-z0-9][[:alnum:]_]\+\.\)\?[A-Z][a-z]\+[A-Z0-9]\w*\>'
let s:uri_link_pattern = '\v(https|http|file|soyfile):[^ >)\]]+\V'
+let s:soyfile_pattern = '\v^soyfile:[^ >)\]]+\V'
let s:wiki_or_web_link_pattern = '\C\<\([a-z0-9][[:alnum:]_]\+\.\)\?[A-Z][a-z]\+[A-Z0-9]\w*\>\|https\?:[^ >)\]]\+'
let s:rename_links_command = 'soywiki-rename '
@@ -33,6 +34,12 @@ func! s:page_title()
return page_title
endfunc
+func! s:current_namespace_path()
+ let absolutepath = expand('%:p')
+ let dir_path = fnamemodify(absolutepath, ':h')
+ return dir_path
+endfunc
+
func! s:wiki_root()
let root_path = split(system("git rev-parse --show-toplevel"), "\n")[0] . '/'
return root_path
@@ -608,6 +615,27 @@ func! s:find_next_href_and_open()
endif
endfunc
+func! s:expand_iana_uri(soyuri)
+ if match(a:soyuri, s:soyfile_pattern) != -1
+ let autochdir_rel_path = s:current_namespace_path()
+ let wiki_rel_path = s:wiki_root()
+
+ let filepath = substitute(a:soyuri, 'soyfile://', '', '')
+
+ let autochdir_path = fnamemodify(autochdir_rel_path . '/' . filepath, ':p')
+ let wiki_path = fnamemodify(wiki_rel_path . '/' . filepath, ':p')
+ let uri_path_part = wiki_path
+
+ if filereadable(autochdir_path)
+ let uri_path_part = autochdir_path
+ endif
+
+ return 'file://' . uri_path_part
+ else
+ return a:soyuri
+ end
+endfunc
+
func! s:goto_homepage(main)
if a:main
call s:load_page("main.HomePage", 0)

0 comments on commit 15cc852

Please sign in to comment.