soywiki 0.9.8.2 → 0.9.8.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
  SHA1:
3
- metadata.gz: d23618b256b4671b2d1927fb643b43286d1053d4
4
- data.tar.gz: 74800d72cf547716ed9bacc3d7fe0f51689dc8e4
3
+ metadata.gz: 2d965f86a41dd8a0199176756ffce69430353f8d
4
+ data.tar.gz: 93be1425214fc3a89d46d4e4099246646ede174c
5
5
  SHA512:
6
- metadata.gz: 723e319fee814129cef4652a485039f93e889fe3e0d524ab6849b72670c11523b7ccd2c0ae12a1c2b6c06cd3bc9db9e8858c5e706ee6d1a63648ba49f37a5cf4
7
- data.tar.gz: f91e60b8d412a888e4a4bd0b185f465337dd2e31a7407e1a398b446616211c99d8372664669b5efb587d68a37a4afe76fe4aff301932163633d1ed813475e3a5
6
+ metadata.gz: 1158b3f573514e5a267929ad0934e040d7c5b73a3cef8e4b03e6ee79a3457c1512b47dad6c7748c740402f8984df3d270ec57c387344243d409a55f53a15ad27
7
+ data.tar.gz: 485916bcb2c38e3678000d87c23e39ed661f1a8370e2f9c72865563176f30aa443375eb0b55189385b777273152e2fdba93e9a1ad292a4234327a090706a5607
@@ -143,6 +143,46 @@ you traverse WikiLinks that don't yet reference any content.
143
143
 
144
144
  That's all you need to know to get started.
145
145
 
146
+ ### Configuring further
147
+
148
+ You can configure soywiki's vim-handling by setting certain variables
149
+ inside of your `~/.vimrc`. This is a list of the supported settings:
150
+
151
+ - `let g:soywiki_autosave = 1`
152
+ activates autosaving (the default), deactivate by setting `0`.
153
+
154
+ #### Mappings
155
+
156
+ Default mappings can be overridden by providing a custom mapping in your vimrc,
157
+ e.g. like this:
158
+
159
+ ```vim
160
+ let g:soywiki_mapping_follow_link_under_cursor_here = '<c-f>'
161
+ ```
162
+
163
+ This is a list of the standard mappings with their default values:
164
+
165
+ - `g:soywiki_mapping_follow_link_under_cursor_here` *defaults* to `<cr>`
166
+ - `g:soywiki_mapping_follow_link_under_cursor_vertical` *defaults* to `<c-l>`
167
+ - `g:soywiki_mapping_follow_link_under_cursor_horizontal` *defaults* to `<c-h>`
168
+ - `g:soywiki_mapping_fuzzy_follow` *defaults* to `<leader>f`
169
+ - `g:soywiki_mapping_next_link` *defaults* to `<c-j>`
170
+ - `g:soywiki_mapping_next_link` *defaults* to `<c-k>`
171
+ - `g:soywiki_mapping_show_history` *defaults* to `<leader>lp`
172
+ - `g:soywiki_mapping_show_files_history` *defaults* to `<leader>ls`
173
+ - `g:soywiki_mapping_show_blame` *defaults* to `<leader>b`
174
+ - `g:soywiki_mapping_expand_seamless_vertical` *defaults* to `<leader>x`
175
+ - `g:soywiki_mapping_expand_seamful_vertical` *defaults* to `<leader>X`
176
+ - `g:soywiki_mapping_expand_seamless_horizontal` *defaults* to `<leader>xx`
177
+ - `g:soywiki_mapping_expand_seamful_horizontal` *defaults* to `<leader>XX`
178
+ - `g:soywiki_mapping_goto_homepage` *defaults* to `<leader>h`
179
+ - `g:soywiki_mapping_goto_main_homepage` *defaults* to `<leader>H`
180
+ - `g:soywiki_mapping_show_help` *defaults* to `<leader>?`
181
+ - `g:soywiki_mapping_format` *defaults* to `\`
182
+ - `g:soywiki_mapping_add_delimiter_line` *defaults* to `<leader>-`
183
+ - `g:soywiki_mapping_add_date` *defaults* to `<leader>d`
184
+ - `g:soywiki_mapping_add_date_and_delimiter_line` *defaults* to `<leader>D`
185
+
146
186
  ## Namespaced WikiWords
147
187
 
148
188
  Every WikiWord in SoyWiki is implicitly or explicitly namespaced.
@@ -518,6 +558,14 @@ this problem we have added support for our own schema:
518
558
  to the wiki root or, if you use vim's
519
559
  *autochdir* option, relative to the current namespace.
520
560
 
561
+ If you want to generate html output in order to upload it
562
+ to a webpage you need to generate relative links if you are using
563
+ `soyfile://` (the default is to generate absolute `file://` links).
564
+ You can achieve this by calling:
565
+
566
+ - `soywiki --html --relative`
567
+ - `soywiki --html --markdown --relative`
568
+
521
569
 
522
570
  ## Bug reports and feature requests
523
571
 
@@ -2,7 +2,7 @@ require 'string_ext'
2
2
  require 'path_helper'
3
3
  module Template_Substitution; end
4
4
  module Soywiki
5
- VERSION = '0.9.8.2'
5
+ VERSION = '0.9.8.3'
6
6
  WIKI_WORD = /\b([a-z0-9][\w_]+\.)?[A-Z][a-z]+[A-Z0-9]\w*\b/
7
7
  SCHEMES = %w{https http file soyfile}
8
8
  HYPERLINK = %r|\b(?:#{SCHEMES.join('|')})://[^ >)\n\]]+|
@@ -15,6 +15,8 @@ module Soywiki
15
15
  [ '--version', '-v', GetoptLong::NO_ARGUMENT],
16
16
  [ '--html', GetoptLong::NO_ARGUMENT],
17
17
  [ '--markdown', GetoptLong::NO_ARGUMENT],
18
+ [ '--absolute', GetoptLong::NO_ARGUMENT],
19
+ [ '--relative', GetoptLong::NO_ARGUMENT],
18
20
  [ '--install-plugin', GetoptLong::NO_ARGUMENT],
19
21
  [ '--page', GetoptLong::REQUIRED_ARGUMENT],
20
22
  [ '--index', GetoptLong::REQUIRED_ARGUMENT],
@@ -42,6 +44,10 @@ Parse to html:
42
44
  --page template-file
43
45
  replace default haml-index-template with the one supplied:
44
46
  --index template-file
47
+ --absolute
48
+ generate absolute file://-style links
49
+ --relative
50
+ generate relative ../-style links
45
51
  Install the soywiki vim plugin:
46
52
  --install-plugin
47
53
  Show this help:
@@ -56,6 +62,7 @@ Show version info:
56
62
  html = false
57
63
  md = false
58
64
  index = page = nil
65
+ relative_soyfile = false
59
66
  opts.each do |opt, arg|
60
67
  case opt
61
68
  when '--help' then usage[]
@@ -65,11 +72,13 @@ Show version info:
65
72
  when '--install-plugin' then install_plugin = true
66
73
  when '--page' then page = arg
67
74
  when '--index' then index = arg
75
+ when '--absolute' then relative_soyfile = false
76
+ when '--relative' then relative_soyfile = true
68
77
  end
69
78
  end
70
79
  self.set_substitute %{INDEX_PAGE_TEMPLATE_SUB}.to_sym, index if index
71
80
  self.set_substitute %{PAGE_TEMPLATE_SUB}.to_sym, page if page
72
- self.html_export md if html
81
+ self.html_export(md, relative_soyfile) if html
73
82
  if install_plugin
74
83
  require 'erb'
75
84
  plugin_template = File.read(File.join(File.dirname(__FILE__), 'plugin.erb'))
@@ -85,9 +94,9 @@ Show version info:
85
94
  end unless html
86
95
  end
87
96
 
88
- def self.html_export(markdown=false)
97
+ def self.html_export(markdown, relative_soyfile)
89
98
  require 'soywiki/html'
90
- Html.export(markdown)
99
+ Html.export(markdown, relative_soyfile)
91
100
  end
92
101
 
93
102
  def self.set_substitute const, substitute_path
@@ -697,51 +697,127 @@ func! s:global_mappings()
697
697
  " autocmd BufEnter * call s:prep_buffer()
698
698
  endfunc
699
699
 
700
+ func! s:prep_mapping_default()
701
+ if !exists('g:soywiki_mapping_follow_link_under_cursor_here')
702
+ let g:soywiki_mapping_follow_link_under_cursor_here = '<cr>'
703
+ endif
704
+ if !exists('g:soywiki_mapping_follow_link_under_cursor_vertical')
705
+ let g:soywiki_mapping_follow_link_under_cursor_vertical = '<c-l>'
706
+ endif
707
+ if !exists('g:soywiki_mapping_follow_link_under_cursor_horizontal')
708
+ let g:soywiki_mapping_follow_link_under_cursor_horizontal = '<c-h>'
709
+ endif
710
+ if !exists('g:soywiki_mapping_fuzzy_follow')
711
+ let g:soywiki_mapping_fuzzy_follow = '<leader>f'
712
+ endif
713
+ if !exists('g:soywiki_mapping_next_link')
714
+ let g:soywiki_mapping_next_link = '<c-j>'
715
+ endif
716
+ if !exists('g:soywiki_mapping_previous_link')
717
+ let g:soywiki_mapping_previous_link = '<c-k>'
718
+ endif
719
+
720
+ if !exists('g:soywiki_mapping_show_history')
721
+ let g:soywiki_mapping_show_history = '<leader>lp'
722
+ endif
723
+ if !exists('g:soywiki_mapping_show_files_history')
724
+ let g:soywiki_mapping_show_files_history = '<leader>ls'
725
+ endif
726
+ if !exists('g:soywiki_mapping_show_blame')
727
+ let g:soywiki_mapping_show_blame = '<leader>b'
728
+ endif
729
+
730
+ if !exists('g:soywiki_mapping_expand_seamless_vertical')
731
+ let g:soywiki_mapping_expand_seamless_vertical = '<leader>x'
732
+ endif
733
+ if !exists('g:soywiki_mapping_expand_seamful_vertical')
734
+ let g:soywiki_mapping_expand_seamful_vertical = '<leader>X'
735
+ endif
736
+ if !exists('g:soywiki_mapping_expand_seamless_horizontal')
737
+ let g:soywiki_mapping_expand_seamless_horizontal = '<leader>xx'
738
+ endif
739
+ if !exists('g:soywiki_mapping_expand_seamful_horizontal')
740
+ let g:soywiki_mapping_expand_seamful_horizontal = '<leader>XX'
741
+ endif
742
+
743
+ if !exists('g:soywiki_mapping_goto_homepage')
744
+ let g:soywiki_mapping_goto_homepage = '<leader>h'
745
+ endif
746
+ if !exists('g:soywiki_mapping_goto_main_homepage')
747
+ let g:soywiki_mapping_goto_main_homepage = '<leader>H'
748
+ endif
749
+
750
+ if !exists('g:soywiki_mapping_show_help')
751
+ let g:soywiki_mapping_show_help = '<leader>?'
752
+ endif
753
+
754
+ if !exists('g:soywiki_mapping_format')
755
+ let g:soywiki_mapping_format = '\'
756
+ endif
757
+ if !exists('g:soywiki_mapping_add_delimiter_line')
758
+ let g:soywiki_mapping_add_delimiter_line = '<leader>-'
759
+ endif
760
+ if !exists('g:soywiki_mapping_add_date')
761
+ let g:soywiki_mapping_add_date = '<leader>d'
762
+ endif
763
+ if !exists('g:soywiki_mapping_add_date_and_delimiter_line')
764
+ let g:soywiki_mapping_add_date_and_delimiter_line = '<leader>D'
765
+ endif
766
+ endfunc
767
+
700
768
  " this checks if the buffer is a SoyWiki file (from firstline)
701
769
  " and then turns on syntax coloring and mappings as necessary
702
770
  func! s:prep_buffer()
703
771
  if (s:is_wiki_page() && !exists("b:mappings_loaded"))
772
+ call s:prep_mapping_default()
704
773
  " let user decide on the textwidth
705
774
  let &filetype=g:soywiki_filetype
706
- nnoremap <buffer> <cr> :call <SID>follow_link_under_cursor(0)<cr>
707
- nnoremap <buffer> <c-l> :call <SID>follow_link_under_cursor(2)<cr>
708
- nnoremap <buffer> <c-h> :call <SID>follow_link_under_cursor(1)<cr>
709
- noremap <buffer> <leader>f :call <SID>fuzzy_follow_link(0)<CR>
710
- noremap <buffer> <c-j> :call <SID>find_next_wiki_link(0)<CR>
711
- noremap <buffer> <c-k> :call <SID>find_next_wiki_link(1)<CR>
775
+ execute 'nnoremap <buffer> '.g:soywiki_mapping_follow_link_under_cursor_here.' :call <SID>follow_link_under_cursor(0)<cr>'
776
+ execute 'nnoremap <buffer> '.g:soywiki_mapping_follow_link_under_cursor_vertical.' :call <SID>follow_link_under_cursor(2)<cr>'
777
+ execute 'nnoremap <buffer> '.g:soywiki_mapping_follow_link_under_cursor_horizontal.' :call <SID>follow_link_under_cursor(1)<cr>'
778
+ execute 'noremap <buffer> '.g:soywiki_mapping_fuzzy_follow.' :call <SID>fuzzy_follow_link(0)<CR>'
779
+ execute 'noremap <buffer> '.g:soywiki_mapping_next_link.' :call <SID>find_next_wiki_link(0)<CR>'
780
+ execute 'noremap <buffer> '.g:soywiki_mapping_previous_link.' :call <SID>find_next_wiki_link(1)<CR>'
712
781
 
713
782
  command! -bar -nargs=1 -range -complete=file SWCreate :call <SID>create_page(<f-args>)
714
783
  command! -bar -nargs=1 -range -complete=file SWRenameTo :call <SID>rename_page(<f-args>)
715
784
  command! -buffer SWDelete :call s:delete_page()
716
785
 
717
786
  command! -buffer SWLog :call s:show_revision_history(0)
718
- noremap <buffer> <leader>lp :call <SID>show_revision_history(0)<CR>
787
+ execute 'noremap <buffer> '.g:soywiki_mapping_show_history.' :call <SID>show_revision_history(0)<CR>'
719
788
  command! -buffer SWLogStat :call s:show_revision_history(1)
720
- noremap <buffer> <leader>ls :call <SID>show_revision_history(1)<CR>
789
+ execute 'noremap <buffer> '.g:soywiki_mapping_show_files_history.' :call <SID>show_revision_history(1)<CR>'
721
790
  command! -buffer SWBlame :call s:show_blame()
722
- noremap <buffer> <leader>b :call <SID>show_blame()<CR>
791
+ execute 'noremap <buffer> '.g:soywiki_mapping_show_blame.' :call <SID>show_blame()<CR>'
723
792
 
724
- noremap <buffer> <leader>x :call <SID>expand(0,1)<CR>
725
- noremap <buffer> <leader>X :call <SID>expand(1,1)<CR>
726
- noremap <buffer> <leader>xx :call <SID>expand(0,0)<CR>
727
- noremap <buffer> <leader>XX :call <SID>expand(1,0)<CR>
793
+ execute 'noremap <buffer> '.g:soywiki_mapping_expand_seamless_vertical.' :call <SID>expand(0,1)<CR>'
794
+ execute 'noremap <buffer> '.g:soywiki_mapping_expand_seamful_vertical.' :call <SID>expand(1,1)<CR>'
795
+ execute 'noremap <buffer> '.g:soywiki_mapping_expand_seamless_horizontal.' :call <SID>expand(0,0)<CR>'
796
+ execute 'noremap <buffer> '.g:soywiki_mapping_expand_seamful_horizontal.' :call <SID>expand(1,0)<CR>'
728
797
 
729
- noremap <buffer> <leader>h :call <SID>goto_homepage(0)<CR>
730
- noremap <buffer> <leader>H :call <SID>goto_homepage(1)<CR>
798
+ execute 'noremap <buffer> '.g:soywiki_mapping_goto_homepage.' :call <SID>goto_homepage(0)<CR>'
799
+ execute 'noremap <buffer> '.g:soywiki_mapping_goto_main_homepage.' :call <SID>goto_homepage(1)<CR>'
731
800
 
732
- noremap <silent> <leader>? :call <SID>show_help()<cr>
801
+ execute 'noremap <silent> '.g:soywiki_mapping_show_help.' :call <SID>show_help()<cr>'
733
802
 
734
- nnoremap <buffer> \ gqap
735
- nnoremap <buffer> <Leader>- o<Esc>k72i-<Esc><CR>
736
- nnoremap <buffer> <Leader>d :r !date<CR>o<Esc>
737
- nnoremap <Leader>D :r !date<CR><Esc>k72i-<Esc>jo<Esc>
803
+ execute 'nnoremap <buffer> '.g:soywiki_mapping_format.' gqap '
804
+ execute 'nnoremap <buffer> '.'.g:soywiki_mapping_add_delimiter_line o<Esc>k72i-<Esc><CR>'
805
+ execute 'nnoremap <buffer> '.g:soywiki_mapping_add_date.' :r !date<CR>o<Esc>'
806
+ execute 'nnoremap '.g:soywiki_mapping_add_date_and_delimiter_line.' :r !date<CR><Esc>k72i-<Esc>jo<Esc>'
738
807
 
739
808
  " set nu
740
809
  setlocal completefunc=CompletePageTitle
741
- augroup save_revision
742
- au!
743
- autocmd FileWritePost,BufWritePost,BufUnload <buffer> call s:save_revision()
744
- augroup END
810
+
811
+ if !exists('g:soywiki_autosave')
812
+ let g:soywiki_autosave = 1
813
+ endif
814
+
815
+ if g:soywiki_autosave
816
+ augroup save_revision
817
+ au!
818
+ autocmd FileWritePost,BufWritePost,BufUnload <buffer> call s:save_revision()
819
+ augroup END
820
+ endif
745
821
  let b:mappings_loaded = 1
746
822
  endif
747
823
  endfunc
@@ -1,161 +1,199 @@
1
1
  require 'haml'
2
2
  require 'rdiscount'
3
3
  module Soywiki
4
- module Html
5
- include Template_Substitution
6
-
4
+ class Html
7
5
  HTML_DIR = 'html-export'
8
6
  INDEX_PAGE_TEMPLATE = File.read(File.join(File.dirname(__FILE__), '..', 'index_template.html.haml'))
9
7
  BROKEN_MARKDOWN_HYPERLINK = %r|\[([^\]]+)\]\(\[(#{HYPERLINK})\]\(\2\)\)|
10
- @current_namespace = nil
8
+ PAGE_TEMPLATE = File.read(File.join(File.dirname(__FILE__), '..', 'page_template.html.haml'))
11
9
 
12
- def self.href_wiki_links(text)
13
- text = text.gsub(WIKI_WORD) {|match|
14
- href = if match =~ /\w\./ # namespace
15
- "../#{match.gsub(".", "/")}.html"
16
- else
17
- match + '.html'
18
- end
19
- %{<a href="#{href}">#{match}</a>}
20
- }
21
- return text
10
+ include Template_Substitution
11
+
12
+ attr_reader :markdown, :relative_soyfile, :current_namespace
13
+
14
+ def self.export(markdown, relative_soyfile)
15
+ new(markdown, relative_soyfile).export
22
16
  end
23
17
 
24
- def self.href_hyperlinks(text)
25
- substitute = if @markdown then '[\\0](\\0)' else '<a href="\\0">\\0</a>' end
26
- text = text.gsub(HYPERLINK, substitute)
27
- if @markdown
28
- text = text.gsub(BROKEN_MARKDOWN_HYPERLINK, '[\\1](\\2)')
18
+ def initialize(markdown, relative_soyfile)
19
+ @markdown = markdown
20
+ @relative_soyfile = relative_soyfile
21
+ end
22
+
23
+ def export
24
+ clear_html_dir
25
+ @current_namespace = nil
26
+ namespaces.each do |namespace, _count|
27
+ make_pages(namespace)
29
28
  end
30
- text = text.gsub(HYPERLINK) { |uri| soyfile_to_uri(uri) }
31
- return text
29
+ make_root_index_page(namespaces)
30
+ @current_namespace = nil
31
+ puts "HTML files written to #{HTML_DIR}/"
32
32
  end
33
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
34
+ def clear_html_dir
35
+ `rm -rf #{HTML_DIR}/*`
36
+ end
37
+
38
+ def namespaces
39
+ @namespaces ||= Dir["*"].select do |file|
40
+ File.directory?(file) && file != HTML_DIR
41
+ end.sort.map do |namespace|
42
+ count = Dir["#{namespace}/*"].select { |f| wiki_page?(f) }.size
43
+ [namespace, count]
41
44
  end
42
45
  end
43
46
 
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
47
+ def wiki_page?(file)
48
+ file.gsub("/", '.') =~ WIKI_WORD
51
49
  end
52
50
 
53
- def self.process(t)
54
- href_hyperlinks(href_wiki_links(t))
51
+ def make_pages(namespace)
52
+ `mkdir -p #{HTML_DIR}/#{namespace}`
53
+ pages = wiki_pages(namespace)
54
+ inner_pages = pages.map { |p| p.split('/')[1] }.sort
55
+ pages.each do |file|
56
+ outfile = File.join(HTML_DIR, file + '.html')
57
+ html = generate_page(File.read(file), namespace, inner_pages)
58
+ File.open(outfile, 'w') { |f| f.write(html) }
59
+ end
60
+ make_index_page(namespace, inner_pages)
55
61
  end
56
62
 
57
- PAGE_TEMPLATE = File.read(File.join(File.dirname(__FILE__), '..', 'page_template.html.haml'))
58
- def self.generate_page(text, namespace, pages, namespaces)
63
+ def wiki_pages(namespace)
64
+ Dir["#{namespace}/*"].select { |file| wiki_page?(file) }
65
+ end
66
+
67
+ def generate_page(text, namespace, pages)
59
68
  @current_namespace = namespace
60
69
  text = text.split("\n")
61
70
 
62
71
  title = text.shift || ''
63
72
  body = ''
64
- if not text.empty?
65
- body = self.process(text.join("\n").strip)
66
- if @markdown
67
- body = RDiscount.new(body).to_html.gsub("<pre><code>","<pre><code>\n")
68
- end
73
+ unless text.empty?
74
+ body = process(text.join("\n").strip)
75
+ body = markdownify(body) if markdown
69
76
  end
70
77
 
71
- page_template = if defined?(PAGE_TEMPLATE_SUB)
72
- PAGE_TEMPLATE_SUB
73
- else
74
- PAGE_TEMPLATE
75
- end
76
- Haml::Engine.new(page_template).render(nil, :body => body,
77
- :title => title,
78
- :namespace => namespace,
79
- :namespaces => namespaces,
80
- :pages => pages,
81
- :markdown => @markdown)
78
+ Haml::Engine.new(page_template).
79
+ render(nil, :body => body,
80
+ :title => title,
81
+ :namespace => namespace,
82
+ :namespaces => namespaces,
83
+ :pages => pages,
84
+ :markdown => markdown)
82
85
  end
83
86
 
87
+ def process(text)
88
+ href_hyperlinks(href_wiki_links(text))
89
+ end
84
90
 
91
+ def href_wiki_links(text)
92
+ text.gsub(WIKI_WORD) do |match|
93
+ href =
94
+ if match =~ /\w\./ # namespace
95
+ "../#{match.gsub(".", "/")}.html"
96
+ else
97
+ match + '.html'
98
+ end
99
+ %{<a href="#{href}">#{match}</a>}
100
+ end
101
+ end
85
102
 
86
- def self.wiki_page?(file)
87
- file.gsub("/", '.') =~ WIKI_WORD
103
+ def href_hyperlinks(text)
104
+ substitute =
105
+ if markdown
106
+ '[\\0](\\0)'
107
+ else
108
+ '<a href="\\0">\\0</a>'
109
+ end
110
+ text = text.gsub(HYPERLINK, substitute)
111
+ if markdown
112
+ text = text.gsub(BROKEN_MARKDOWN_HYPERLINK, '[\\1](\\2)')
113
+ end
114
+ text.gsub(HYPERLINK) { |uri| soyfile_to_href(uri) }
88
115
  end
89
116
 
90
- def self.make_index_page(dir, pages, namespaces)
91
- index_page_template = if defined?(INDEX_PAGE_TEMPLATE_SUB)
92
- INDEX_PAGE_TEMPLATE_SUB
93
- else
94
- INDEX_PAGE_TEMPLATE
95
- end
96
- outfile = File.join(HTML_DIR, dir, 'index.html')
97
- html = Haml::Engine.new(index_page_template).render(nil,
98
- :namespace => dir,
99
- :root => false,
100
- :pages => pages.map {|p| p.split('/')[1]}.sort,
101
- :namespaces => namespaces)
102
- File.open(outfile, 'w') {|f| f.write html}
103
- # puts "=> Writing #{outfile}"
104
- end
105
-
106
- def self.make_pages(dir, namespaces)
107
- `mkdir -p #{HTML_DIR}/#{dir}`
108
- pages = Dir["#{dir}/*"].select {|file| wiki_page? file}
109
- # make pages
110
- pages.each do |file|
111
- outfile = File.join(HTML_DIR, file + '.html')
112
- html = Soywiki::Html.generate_page(File.read(file),
113
- dir,
114
- pages.map {|p| p.split('/')[1]}.sort,
115
- namespaces)
116
- File.open(outfile, 'w') {|f| f.write html}
117
- # puts "Writing #{outfile}"
117
+ def soyfile_to_href(uri)
118
+ match = soyfile_match(uri)
119
+ if match
120
+ path = choose_soyfile_path(match[1])
121
+ path[0] == '/' ? "file://#{path}" : path
122
+ else
123
+ uri
118
124
  end
119
- make_index_page(dir, pages, namespaces)
120
125
  end
121
126
 
122
- def self.make_root_index_page(namespaces)
123
- outfile = File.join(HTML_DIR, 'index.html')
124
- index_page_template = if defined?(INDEX_PAGE_TEMPLATE_SUB)
125
- INDEX_PAGE_TEMPLATE_SUB
126
- else
127
- INDEX_PAGE_TEMPLATE
128
- end
129
- html = Haml::Engine.new(index_page_template).render(nil,
130
- :namespace => nil,
131
- :pages => [],
132
- :root => true,
133
- :namespaces => namespaces)
134
- File.open(outfile, 'w') {|f| f.write html}
135
- # puts "=> Writing #{outfile}"
136
- end
137
-
138
- def self.export(markdown)
139
- @markdown = markdown
127
+ def soyfile_match(uri)
128
+ uri_after_scheme = %r{[^ >)\n\]]+}
129
+ regex = %r{^soyfile://(#{uri_after_scheme})}
130
+ uri.match(regex)
131
+ end
140
132
 
141
- `rm -rf #{HTML_DIR}/*`
142
- namespaces = Dir["*"].select {|f|
143
- File.directory?(f) && f != HTML_DIR
144
- }.sort.map {|namespace|
145
- count = Dir["#{namespace}/*"].select {|f| wiki_page?(f)}.size
146
- [namespace, count]
147
- }
148
- @current_namespace = nil
149
- namespaces.each do |namespace_dir, count|
150
- make_pages namespace_dir, namespaces
133
+ def choose_soyfile_path(path)
134
+ absolute_path = absolute_soyfile_path(path)
135
+ if relative_soyfile
136
+ Pathname.new(absolute_path).
137
+ relative_path_from(Pathname.new(wiki_root)).to_s
138
+ else
139
+ absolute_path
151
140
  end
152
- # make root index page
153
- make_root_index_page namespaces
154
- @current_namespace = nil
155
- puts "HTML files written to #{HTML_DIR}/"
156
141
  end
157
142
 
143
+ def absolute_soyfile_path(path)
144
+ return path if path[0] == '/'
145
+ autochdir_path = absolutify("#{current_namespace}/#{path}")
146
+ wiki_path = absolutify(path)
147
+ File.exists?(autochdir_path) ? autochdir_path : wiki_path
148
+ end
149
+
150
+ def absolutify(path)
151
+ File.absolute_path(File.join(wiki_root, path))
152
+ end
153
+
154
+ def wiki_root
155
+ Dir.getwd
156
+ end
157
+
158
+ def markdownify(text)
159
+ RDiscount.new(text).to_html.gsub("<pre><code>", "<pre><code>\n")
160
+ end
158
161
 
162
+ def page_template
163
+ if defined?(PAGE_TEMPLATE_SUB)
164
+ PAGE_TEMPLATE_SUB
165
+ else
166
+ PAGE_TEMPLATE
167
+ end
168
+ end
169
+
170
+ def make_index_page(namespace, inner_pages)
171
+ outfile = File.join(HTML_DIR, namespace, 'index.html')
172
+ html = Haml::Engine.new(index_page_template).
173
+ render(nil, :namespace => namespace,
174
+ :root => false,
175
+ :pages => inner_pages,
176
+ :namespaces => namespaces)
177
+ File.open(outfile, 'w') { |f| f.write(html) }
178
+ end
179
+
180
+ def index_page_template
181
+ if defined?(INDEX_PAGE_TEMPLATE_SUB)
182
+ INDEX_PAGE_TEMPLATE_SUB
183
+ else
184
+ INDEX_PAGE_TEMPLATE
185
+ end
186
+ end
187
+
188
+ def make_root_index_page(namespaces)
189
+ outfile = File.join(HTML_DIR, 'index.html')
190
+ html = Haml::Engine.new(index_page_template).
191
+ render(nil, :namespace => nil,
192
+ :pages => [],
193
+ :root => true,
194
+ :namespaces => namespaces)
195
+ File.open(outfile, 'w') { |f| f.write(html) }
196
+ end
159
197
  end
160
198
  end
161
199
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soywiki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.2
4
+ version: 0.9.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Choi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-15 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A personal and collaborative wiki for Vim users
14
14
  email:
@@ -74,7 +74,7 @@ requirements:
74
74
  and for markdown support:
75
75
  - rdiscount
76
76
  rubyforge_project: soywiki
77
- rubygems_version: 2.2.0
77
+ rubygems_version: 2.2.2
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Wiki with Vim interface and Git repo