10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/soywiki.rb', line 10
def self.run
require 'getoptlong'
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT],
[ '--version', '-v', GetoptLong::NO_ARGUMENT],
[ '--html', GetoptLong::NO_ARGUMENT],
[ '--markdown', GetoptLong::NO_ARGUMENT],
[ '--absolute', GetoptLong::NO_ARGUMENT],
[ '--relative', GetoptLong::NO_ARGUMENT],
[ '--install-plugin', GetoptLong::NO_ARGUMENT],
[ '--page', GetoptLong::REQUIRED_ARGUMENT],
[ '--index', GetoptLong::REQUIRED_ARGUMENT],
)
usage =->(version_only=false) do
puts "soywiki #{Soywiki::VERSION}"
puts "by Daniel Choi [email protected]"
exit if version_only
puts
puts <<-END
---
Usage: soywiki
Run the command in a directory you've made to contain soywiki files.
Soywiki will open the most recently modified wiki file or create a file
called main/HomePage.
Parse to html:
--html
assume that wiki-files are in markdown syntax:
--markdown
replace default haml-page-template with the one supplied:
--page template-file
replace default haml-index-template with the one supplied:
--index template-file
--absolute
generate absolute file://-style links
--relative
generate relative ../-style links
Install the soywiki vim plugin:
--install-plugin
Show this help:
[--help, -h]
Show version info:
[--version, -v]
---
END
exit
end
install_plugin = false
html = false
md = false
index = page = nil
relative_soyfile = false
opts.each do |opt, arg|
case opt
when '--help' then usage[]
when '--version' then usage[true]
when '--html' then html = true
when '--markdown' then md = true
when '--install-plugin' then install_plugin = true
when '--page' then page = arg
when '--index' then index = arg
when '--absolute' then relative_soyfile = false
when '--relative' then relative_soyfile = true
end
end
self.set_substitute %{INDEX_PAGE_TEMPLATE_SUB}.to_sym, index if index
self.set_substitute %{PAGE_TEMPLATE_SUB}.to_sym, page if page
self.html_export(md, relative_soyfile) if html
if install_plugin
require 'erb'
plugin_template = File.read(File.join(File.dirname(__FILE__), 'plugin.erb'))
vimscript_file = File.join(File.dirname(__FILE__), 'soywiki.vim')
plugin_body = ERB.new(plugin_template).result(binding)
`mkdir -p #{ENV['HOME']}/.vim/plugin`
File.open("#{ENV['HOME']}/.vim/plugin/soywiki_starter.vim", "w") {|f| f.write plugin_body}
else
vim = ENV['SOYWIKI_VIM'] || 'vim'
vimscript = File.expand_path("../soywiki.vim", __FILE__)
vim_command = "#{vim} -S #{vimscript}"
exec vim_command
end unless html
end
|