morph-sdoc 0.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +2 -0
- data/LICENSE +21 -0
- data/README.rdoc +37 -0
- data/Rakefile +51 -0
- data/VERSION.yml +5 -0
- data/bin/sdoc +11 -0
- data/bin/sdoc-merge +12 -0
- data/lib/rdoc/discover.rb +1 -0
- data/lib/sdoc.rb +16 -0
- data/lib/sdoc/c_parser_fix.rb +31 -0
- data/lib/sdoc/generator/shtml.rb +352 -0
- data/lib/sdoc/generator/template/direct/_context.rhtml +172 -0
- data/lib/sdoc/generator/template/direct/class.rhtml +40 -0
- data/lib/sdoc/generator/template/direct/file.rhtml +30 -0
- data/lib/sdoc/generator/template/direct/index.rhtml +14 -0
- data/lib/sdoc/generator/template/direct/resources/apple-touch-icon.png +0 -0
- data/lib/sdoc/generator/template/direct/resources/css/main.css +278 -0
- data/lib/sdoc/generator/template/direct/resources/css/panel.css +383 -0
- data/lib/sdoc/generator/template/direct/resources/css/reset.css +53 -0
- data/lib/sdoc/generator/template/direct/resources/favicon.ico +0 -0
- data/lib/sdoc/generator/template/direct/resources/i/arrows.png +0 -0
- data/lib/sdoc/generator/template/direct/resources/i/results_bg.png +0 -0
- data/lib/sdoc/generator/template/direct/resources/i/tree_bg.png +0 -0
- data/lib/sdoc/generator/template/direct/resources/js/jquery-1.3.2.min.js +19 -0
- data/lib/sdoc/generator/template/direct/resources/js/jquery-effect.js +593 -0
- data/lib/sdoc/generator/template/direct/resources/js/main.js +22 -0
- data/lib/sdoc/generator/template/direct/resources/js/searchdoc.js +628 -0
- data/lib/sdoc/generator/template/direct/resources/panel/index.html +71 -0
- data/lib/sdoc/generator/template/merge/index.rhtml +14 -0
- data/lib/sdoc/generator/template/shtml/_context.rhtml +164 -0
- data/lib/sdoc/generator/template/shtml/class.rhtml +46 -0
- data/lib/sdoc/generator/template/shtml/file.rhtml +37 -0
- data/lib/sdoc/generator/template/shtml/index.rhtml +14 -0
- data/lib/sdoc/generator/template/shtml/resources/apple-touch-icon.png +0 -0
- data/lib/sdoc/generator/template/shtml/resources/css/main.css +191 -0
- data/lib/sdoc/generator/template/shtml/resources/css/panel.css +383 -0
- data/lib/sdoc/generator/template/shtml/resources/css/reset.css +53 -0
- data/lib/sdoc/generator/template/shtml/resources/favicon.ico +0 -0
- data/lib/sdoc/generator/template/shtml/resources/i/arrows.png +0 -0
- data/lib/sdoc/generator/template/shtml/resources/i/results_bg.png +0 -0
- data/lib/sdoc/generator/template/shtml/resources/i/tree_bg.png +0 -0
- data/lib/sdoc/generator/template/shtml/resources/js/jquery-1.3.2.min.js +19 -0
- data/lib/sdoc/generator/template/shtml/resources/js/main.js +34 -0
- data/lib/sdoc/generator/template/shtml/resources/js/searchdoc.js +628 -0
- data/lib/sdoc/generator/template/shtml/resources/panel/index.html +71 -0
- data/lib/sdoc/github.rb +61 -0
- data/lib/sdoc/helpers.rb +26 -0
- data/lib/sdoc/json_backend.rb +15 -0
- data/lib/sdoc/merge.rb +217 -0
- data/lib/sdoc/options.rb +329 -0
- data/lib/sdoc/templatable.rb +58 -0
- data/sdoc.gemspec +93 -0
- metadata +151 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
|
3
|
+
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
4
|
+
|
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
|
6
|
+
<head>
|
|
7
|
+
<title>layout</title>
|
|
8
|
+
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" charset="utf-8" />
|
|
9
|
+
<link rel="stylesheet" href="../css/panel.css" type="text/css" media="screen" charset="utf-8" />
|
|
10
|
+
<script src="search_index.js" type="text/javascript" charset="utf-8"></script>
|
|
11
|
+
<script src="tree.js" type="text/javascript" charset="utf-8"></script>
|
|
12
|
+
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
|
13
|
+
<script src="../js/searchdoc.js" type="text/javascript" charset="utf-8"></script>
|
|
14
|
+
<script type="text/javascript" charset="utf-8">
|
|
15
|
+
//<![CDATA[
|
|
16
|
+
function placeholder() {
|
|
17
|
+
if (jQuery.browser.safari) return;
|
|
18
|
+
$('#search-label').click(function() {
|
|
19
|
+
$('#search').focus();
|
|
20
|
+
$('#search-label').hide();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
$('#search').focus(function() {
|
|
24
|
+
$('#search-label').hide();
|
|
25
|
+
});
|
|
26
|
+
$('#search').blur(function() {
|
|
27
|
+
this.value == '' && $('#search-label').show()
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
$('#search')[0].value == '' && $('#search-label').show();
|
|
31
|
+
}
|
|
32
|
+
$(function() {
|
|
33
|
+
placeholder();
|
|
34
|
+
var panel = new Searchdoc.Panel($('#panel'), search_data, tree, top.frames[1]);
|
|
35
|
+
$('#search').focus();
|
|
36
|
+
|
|
37
|
+
var s = window.parent.location.search.match(/\?q=([^&]+)/);
|
|
38
|
+
if (s) {
|
|
39
|
+
s = decodeURIComponent(s[1]).replace(/\+/g, ' ');
|
|
40
|
+
if (s.length > 0)
|
|
41
|
+
{
|
|
42
|
+
$('#search').val(s);
|
|
43
|
+
panel.search(s, true);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
//]]>
|
|
48
|
+
</script>
|
|
49
|
+
</head>
|
|
50
|
+
<body>
|
|
51
|
+
<div class="panel panel_tree" id="panel">
|
|
52
|
+
<div class="header">
|
|
53
|
+
<div>
|
|
54
|
+
<label for="search" id="search-label" style="display: none">Search</label>
|
|
55
|
+
<table>
|
|
56
|
+
<tr><td>
|
|
57
|
+
<input type="Search" placeholder="Search" autosave="searchdoc" results="10" id="search" autocomplete="off"/>
|
|
58
|
+
</td></tr>
|
|
59
|
+
</table></div>
|
|
60
|
+
</div>
|
|
61
|
+
<div class="tree">
|
|
62
|
+
<ul>
|
|
63
|
+
</ul>
|
|
64
|
+
</div>
|
|
65
|
+
<div class="result">
|
|
66
|
+
<ul>
|
|
67
|
+
</ul>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</body>
|
|
71
|
+
</html>
|
data/lib/sdoc/github.rb
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module SDoc::GitHub
|
|
2
|
+
def github_url(path)
|
|
3
|
+
unless @github_url_cache.has_key? path
|
|
4
|
+
@github_url_cache[path] = false
|
|
5
|
+
file = RDoc::TopLevel.find_file_named(path)
|
|
6
|
+
if file
|
|
7
|
+
base_url = repository_url(path)
|
|
8
|
+
if base_url
|
|
9
|
+
sha1 = commit_sha1(path)
|
|
10
|
+
if sha1
|
|
11
|
+
relative_url = path_relative_to_repository(path)
|
|
12
|
+
@github_url_cache[path] = "#{base_url}#{sha1}#{relative_url}"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
@github_url_cache[path]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
protected
|
|
21
|
+
|
|
22
|
+
def have_git?
|
|
23
|
+
@have_git = system('git --version > /dev/null 2>&1') if @have_git.nil?
|
|
24
|
+
@have_git
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def commit_sha1(path)
|
|
28
|
+
return false unless have_git?
|
|
29
|
+
name = File.basename(path)
|
|
30
|
+
s = Dir.chdir(File.join(basedir, File.dirname(path))) do
|
|
31
|
+
`git log -1 --pretty=format:"commit %H" #{name}`
|
|
32
|
+
end
|
|
33
|
+
m = s.match(/commit\s+(\S+)/)
|
|
34
|
+
m ? m[1] : false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def repository_url(path)
|
|
38
|
+
return false unless have_git?
|
|
39
|
+
s = Dir.chdir(File.join(basedir, File.dirname(path))) do
|
|
40
|
+
`git config --get remote.origin.url`
|
|
41
|
+
end
|
|
42
|
+
m = s.match(%r{github.com[/:](.*)\.git$})
|
|
43
|
+
m ? "http://github.com/#{m[1]}/blob/" : false
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def path_relative_to_repository(path)
|
|
47
|
+
absolute_path = File.join(basedir, path)
|
|
48
|
+
root = path_to_git_dir(File.dirname(absolute_path))
|
|
49
|
+
absolute_path[root.size..absolute_path.size]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def path_to_git_dir(path)
|
|
53
|
+
while !path.empty? && path != '.'
|
|
54
|
+
if (File.exists? File.join(path, '.git'))
|
|
55
|
+
return path
|
|
56
|
+
end
|
|
57
|
+
path = File.dirname(path)
|
|
58
|
+
end
|
|
59
|
+
''
|
|
60
|
+
end
|
|
61
|
+
end
|
data/lib/sdoc/helpers.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module SDoc::Helpers
|
|
2
|
+
def each_letter_group(methods, &block)
|
|
3
|
+
group = {:name => '', :methods => []}
|
|
4
|
+
methods.sort{ |a, b| a.name <=> b.name }.each do |method|
|
|
5
|
+
gname = group_name method.name
|
|
6
|
+
if gname != group[:name]
|
|
7
|
+
yield group unless group[:methods].size == 0
|
|
8
|
+
group = {
|
|
9
|
+
:name => gname,
|
|
10
|
+
:methods => []
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
group[:methods].push(method)
|
|
14
|
+
end
|
|
15
|
+
yield group unless group[:methods].size == 0
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
def group_name name
|
|
20
|
+
if match = name.match(/^([a-z])/i)
|
|
21
|
+
match[1].upcase
|
|
22
|
+
else
|
|
23
|
+
'#'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
## undefined method `to_json' for Array :(
|
|
4
|
+
# if Gem.available? "yajl-ruby"
|
|
5
|
+
# gem "yajl-ruby", ">= 0.7.6"
|
|
6
|
+
# require "yajl"
|
|
7
|
+
# warn "yajl"
|
|
8
|
+
# else
|
|
9
|
+
if Gem.available? "json"
|
|
10
|
+
gem "json", ">= 1.1.3"
|
|
11
|
+
else
|
|
12
|
+
gem "json_pure", ">= 1.1.3"
|
|
13
|
+
end
|
|
14
|
+
require "json"
|
|
15
|
+
# end
|
data/lib/sdoc/merge.rb
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
require 'pathname'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
require 'sdoc/json_backend'
|
|
6
|
+
require 'sdoc/templatable'
|
|
7
|
+
|
|
8
|
+
class SDoc::Merge
|
|
9
|
+
include SDoc::Templatable
|
|
10
|
+
|
|
11
|
+
FLAG_FILE = "created.rid"
|
|
12
|
+
|
|
13
|
+
def initialize()
|
|
14
|
+
@names = []
|
|
15
|
+
@urls = []
|
|
16
|
+
@op_dir = 'doc'
|
|
17
|
+
@title = ''
|
|
18
|
+
@directories = []
|
|
19
|
+
template_dir = RDoc::Generator::SHtml.template_dir('merge')
|
|
20
|
+
@template_dir = Pathname.new File.expand_path(template_dir)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def merge(options)
|
|
24
|
+
parse_options options
|
|
25
|
+
|
|
26
|
+
@outputdir = Pathname.new( @op_dir )
|
|
27
|
+
|
|
28
|
+
check_directories
|
|
29
|
+
setup_output_dir
|
|
30
|
+
setup_names
|
|
31
|
+
copy_files
|
|
32
|
+
copy_docs if @urls.empty?
|
|
33
|
+
merge_search_index
|
|
34
|
+
merge_tree
|
|
35
|
+
generate_index_file
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def parse_options(options)
|
|
39
|
+
opts = OptionParser.new do |opt|
|
|
40
|
+
opt.banner = "Usage: sdoc-merge [options] directories"
|
|
41
|
+
|
|
42
|
+
opt.on("-n", "--names [NAMES]", "Names of merged repositories. Comma separated") do |v|
|
|
43
|
+
@names = v.split(',').map{|name| name.strip }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
opt.on("-o", "--op [DIRECTORY]", "Set the output directory") do |v|
|
|
47
|
+
@op_dir = v
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
opt.on("-t", "--title [TITLE]", "Set the title of merged file") do |v|
|
|
51
|
+
@title = v
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
opt.on("-u", "--urls [URLS]", "Paths to merged docs. If you \n" +
|
|
55
|
+
"set this files and classes won't be actualy copied to merged build") do |v|
|
|
56
|
+
@urls = v.split(' ').map{|name| name.strip }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
opts.parse! options
|
|
60
|
+
@directories = options.dup
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def merge_tree
|
|
64
|
+
tree = []
|
|
65
|
+
@directories.each_with_index do |dir, i|
|
|
66
|
+
name = @names[i]
|
|
67
|
+
url = @urls.empty? ? name : @urls[i]
|
|
68
|
+
filename = File.join dir, RDoc::Generator::SHtml::TREE_FILE
|
|
69
|
+
data = open(filename).read.sub(/var tree =\s*/, '')
|
|
70
|
+
subtree = JSON.parse(data, :max_nesting => 0)
|
|
71
|
+
item = [
|
|
72
|
+
name,
|
|
73
|
+
url + '/' + extract_index_path(dir),
|
|
74
|
+
'',
|
|
75
|
+
append_path(subtree, url)
|
|
76
|
+
]
|
|
77
|
+
tree << item
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
dst = File.join @op_dir, RDoc::Generator::SHtml::TREE_FILE
|
|
81
|
+
FileUtils.mkdir_p File.dirname(dst)
|
|
82
|
+
File.open(dst, "w", 0644) do |f|
|
|
83
|
+
f.write('var tree = '); f.write(tree.to_json(:max_nesting => 0))
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def append_path subtree, path
|
|
88
|
+
subtree.map do |item|
|
|
89
|
+
item[1] = path + '/' + item[1] unless item[1].empty?
|
|
90
|
+
item[3] = append_path item[3], path
|
|
91
|
+
item
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def merge_search_index
|
|
96
|
+
items = []
|
|
97
|
+
@indexes = {}
|
|
98
|
+
@directories.each_with_index do |dir, i|
|
|
99
|
+
name = @names[i]
|
|
100
|
+
url = @urls.empty? ? name : @urls[i]
|
|
101
|
+
filename = File.join dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE
|
|
102
|
+
data = open(filename).read.sub(/var search_data =\s*/, '')
|
|
103
|
+
subindex = JSON.parse(data, :max_nesting => 0)
|
|
104
|
+
@indexes[name] = subindex
|
|
105
|
+
|
|
106
|
+
searchIndex = subindex["index"]["searchIndex"]
|
|
107
|
+
longSearchIndex = subindex["index"]["longSearchIndex"]
|
|
108
|
+
subindex["index"]["info"].each_with_index do |info, j|
|
|
109
|
+
info[2] = url + '/' + info[2]
|
|
110
|
+
info[6] = i
|
|
111
|
+
items << {
|
|
112
|
+
:info => info,
|
|
113
|
+
:searchIndex => searchIndex[j],
|
|
114
|
+
:longSearchIndex => name + ' ' + longSearchIndex[j]
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
items.sort! do |a, b|
|
|
119
|
+
# type (class/method/file) or name or doc part or namespace
|
|
120
|
+
[a[:info][5], a[:info][0], a[:info][6], a[:info][1]] <=> [b[:info][5], b[:info][0], b[:info][6], b[:info][1]]
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
index = {
|
|
124
|
+
:searchIndex => items.map{|item| item[:searchIndex]},
|
|
125
|
+
:longSearchIndex => items.map{|item| item[:longSearchIndex]},
|
|
126
|
+
:info => items.map{|item| item[:info]}
|
|
127
|
+
}
|
|
128
|
+
search_data = {
|
|
129
|
+
:index => index,
|
|
130
|
+
:badges => @names
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
dst = File.join @op_dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE
|
|
134
|
+
FileUtils.mkdir_p File.dirname(dst)
|
|
135
|
+
File.open(dst, "w", 0644) do |f|
|
|
136
|
+
f.write('var search_data = '); f.write(search_data.to_json(:max_nesting => 0))
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def extract_index_path dir
|
|
141
|
+
filename = File.join dir, 'index.html'
|
|
142
|
+
content = File.open(filename) { |f| f.read }
|
|
143
|
+
match = content.match(/<frame\s+src="([^"]+)"\s+name="docwin"/mi)
|
|
144
|
+
if match
|
|
145
|
+
match[1]
|
|
146
|
+
else
|
|
147
|
+
''
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def generate_index_file
|
|
152
|
+
templatefile = @template_dir + 'index.rhtml'
|
|
153
|
+
outfile = @outputdir + 'index.html'
|
|
154
|
+
url = @urls.empty? ? @names[0] : @urls[0]
|
|
155
|
+
index_path = url + '/' + extract_index_path(@directories[0])
|
|
156
|
+
|
|
157
|
+
render_template templatefile, binding(), outfile
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def setup_names
|
|
161
|
+
unless @names.size > 0
|
|
162
|
+
@directories.each do |dir|
|
|
163
|
+
name = File.basename dir
|
|
164
|
+
name = File.basename File.dirname(dir) if name == 'doc'
|
|
165
|
+
@names << name
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def copy_docs
|
|
171
|
+
@directories.each_with_index do |dir, i|
|
|
172
|
+
name = @names[i]
|
|
173
|
+
index_dir = File.dirname(RDoc::Generator::SHtml::TREE_FILE)
|
|
174
|
+
FileUtils.mkdir_p(File.join(@op_dir, name))
|
|
175
|
+
|
|
176
|
+
Dir.new(dir).each do |item|
|
|
177
|
+
if File.directory?(File.join(dir, item)) && item != '.' && item != '..' && item != index_dir
|
|
178
|
+
FileUtils.cp_r File.join(dir, item), File.join(@op_dir, name, item), :preserve => true
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def copy_files
|
|
185
|
+
dir = @directories.first
|
|
186
|
+
Dir.new(dir).each do |item|
|
|
187
|
+
if item != '.' && item != '..' && item != RDoc::Generator::SHtml::FILE_DIR && item != RDoc::Generator::SHtml::CLASS_DIR
|
|
188
|
+
FileUtils.cp_r File.join(dir, item), @op_dir, :preserve => true
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def setup_output_dir
|
|
194
|
+
if File.exists? @op_dir
|
|
195
|
+
error "#{@op_dir} allready exists"
|
|
196
|
+
end
|
|
197
|
+
FileUtils.mkdir_p @op_dir
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def check_directories
|
|
201
|
+
@directories.each do |dir|
|
|
202
|
+
unless File.exists?(File.join(dir, FLAG_FILE)) &&
|
|
203
|
+
File.exists?(File.join(dir, RDoc::Generator::SHtml::TREE_FILE)) &&
|
|
204
|
+
File.exists?(File.join(dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE))
|
|
205
|
+
error "#{dir} does not seem to be an sdoc directory"
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
##
|
|
211
|
+
# Report an error message and exit
|
|
212
|
+
|
|
213
|
+
def error(msg)
|
|
214
|
+
raise RDoc::Error, msg
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
end
|
data/lib/sdoc/options.rb
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
class RDoc::Options
|
|
2
|
+
##
|
|
3
|
+
# Should source be included?
|
|
4
|
+
attr_accessor :open_source
|
|
5
|
+
|
|
6
|
+
alias_method :rdoc_initialize, :initialize
|
|
7
|
+
|
|
8
|
+
def initialize # :nodoc:
|
|
9
|
+
rdoc_initialize
|
|
10
|
+
@open_source = false
|
|
11
|
+
@generator = RDoc::Generator::SHtml
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
##
|
|
15
|
+
# Parse command line options. (Copied from RDoc)
|
|
16
|
+
def parse(argv)
|
|
17
|
+
opts = OptionParser.new do |opt|
|
|
18
|
+
opt.program_name = File.basename $0
|
|
19
|
+
opt.version = RDoc::VERSION
|
|
20
|
+
opt.release = nil
|
|
21
|
+
opt.summary_indent = ' ' * 4
|
|
22
|
+
opt.banner = <<-EOF
|
|
23
|
+
Usage: #{opt.program_name} [options] [names...]
|
|
24
|
+
|
|
25
|
+
Files are parsed, and the information they contain collected, before any
|
|
26
|
+
output is produced. This allows cross references between all files to be
|
|
27
|
+
resolved. If a name is a directory, it is traversed. If no names are
|
|
28
|
+
specified, all Ruby files in the current directory (and subdirectories) are
|
|
29
|
+
processed.
|
|
30
|
+
|
|
31
|
+
How RDoc generates output depends on the output formatter being used, and on
|
|
32
|
+
the options you give.
|
|
33
|
+
|
|
34
|
+
- Darkfish creates frameless HTML output by Michael Granger.
|
|
35
|
+
|
|
36
|
+
- ri creates ri data files
|
|
37
|
+
EOF
|
|
38
|
+
|
|
39
|
+
opt.separator nil
|
|
40
|
+
opt.separator "Parsing Options:"
|
|
41
|
+
opt.separator nil
|
|
42
|
+
|
|
43
|
+
opt.on("--all", "-a",
|
|
44
|
+
"Include all methods (not just public) in",
|
|
45
|
+
"the output.") do |value|
|
|
46
|
+
@show_all = value
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
opt.separator nil
|
|
50
|
+
|
|
51
|
+
opt.on("--exclude=PATTERN", "-x", Regexp,
|
|
52
|
+
"Do not process files or directories",
|
|
53
|
+
"matching PATTERN.") do |value|
|
|
54
|
+
@exclude << value
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
opt.separator nil
|
|
58
|
+
|
|
59
|
+
opt.on("--extension=NEW=OLD", "-E",
|
|
60
|
+
"Treat files ending with .new as if they",
|
|
61
|
+
"ended with .old. Using '-E cgi=rb' will",
|
|
62
|
+
"cause xxx.cgi to be parsed as a Ruby file.") do |value|
|
|
63
|
+
new, old = value.split(/=/, 2)
|
|
64
|
+
|
|
65
|
+
unless new and old then
|
|
66
|
+
raise OptionParser::InvalidArgument, "Invalid parameter to '-E'"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
unless RDoc::ParserFactory.alias_extension old, new then
|
|
70
|
+
raise OptionParser::InvalidArgument, "Unknown extension .#{old} to -E"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
opt.separator nil
|
|
75
|
+
|
|
76
|
+
opt.on("--force-update", "-U",
|
|
77
|
+
"Forces rdoc to scan all sources even if",
|
|
78
|
+
"newer than the flag file.") do |value|
|
|
79
|
+
@force_update = value
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
opt.separator nil
|
|
83
|
+
|
|
84
|
+
opt.on("--pipe",
|
|
85
|
+
"Convert RDoc on stdin to HTML") do
|
|
86
|
+
@pipe = true
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
opt.separator nil
|
|
90
|
+
|
|
91
|
+
opt.on("--threads=THREADS", Integer,
|
|
92
|
+
"Number of threads to parse with.") do |threads|
|
|
93
|
+
@threads = threads
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
opt.separator nil
|
|
97
|
+
opt.separator "Generator Options:"
|
|
98
|
+
opt.separator nil
|
|
99
|
+
|
|
100
|
+
opt.on("--charset=CHARSET", "-c",
|
|
101
|
+
"Specifies the output HTML character-set.") do |value|
|
|
102
|
+
@charset = value
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
opt.separator nil
|
|
106
|
+
|
|
107
|
+
generator_text = @generators.keys.map { |name| " #{name}" }.sort
|
|
108
|
+
|
|
109
|
+
opt.on("--fmt=FORMAT", "--format=FORMAT", "-f", @generators.keys,
|
|
110
|
+
"Set the output formatter. One of:", *generator_text) do |value|
|
|
111
|
+
@generator_name = value.downcase
|
|
112
|
+
setup_generator
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
opt.separator nil
|
|
116
|
+
|
|
117
|
+
opt.on("--include=DIRECTORIES", "-i", Array,
|
|
118
|
+
"Set (or add to) the list of directories to",
|
|
119
|
+
"be searched when satisfying :include:",
|
|
120
|
+
"requests. Can be used more than once.") do |value|
|
|
121
|
+
@rdoc_include.concat value.map { |dir| dir.strip }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
opt.separator nil
|
|
125
|
+
|
|
126
|
+
opt.on("--line-numbers", "-N",
|
|
127
|
+
"Include line numbers in the source code.") do |value|
|
|
128
|
+
@include_line_numbers = value
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
opt.separator nil
|
|
132
|
+
|
|
133
|
+
opt.on("--main=NAME", "-m",
|
|
134
|
+
"NAME will be the initial page displayed.") do |value|
|
|
135
|
+
@main_page = value
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
opt.separator nil
|
|
139
|
+
|
|
140
|
+
opt.on("--output=DIR", "--op", "-o",
|
|
141
|
+
"Set the output directory.") do |value|
|
|
142
|
+
@op_dir = value
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
opt.separator nil
|
|
146
|
+
|
|
147
|
+
opt.on("--show-hash", "-H",
|
|
148
|
+
"A name of the form #name in a comment is a",
|
|
149
|
+
"possible hyperlink to an instance method",
|
|
150
|
+
"name. When displayed, the '#' is removed",
|
|
151
|
+
"unless this option is specified.") do |value|
|
|
152
|
+
@show_hash = value
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
opt.separator nil
|
|
156
|
+
|
|
157
|
+
opt.on("--open-source", "-s",
|
|
158
|
+
"Include source code to your documentation") do |value|
|
|
159
|
+
@open_source = value
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
opt.separator nil
|
|
163
|
+
|
|
164
|
+
opt.on("--tab-width=WIDTH", "-w", OptionParser::DecimalInteger,
|
|
165
|
+
"Set the width of tab characters.") do |value|
|
|
166
|
+
@tab_width = value
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
opt.separator nil
|
|
170
|
+
|
|
171
|
+
opt.on("--template=NAME", "-T",
|
|
172
|
+
"Set the template used when generating",
|
|
173
|
+
"output.") do |value|
|
|
174
|
+
@template = value
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
opt.separator nil
|
|
178
|
+
|
|
179
|
+
opt.on("--title=TITLE", "-t",
|
|
180
|
+
"Set TITLE as the title for HTML output.") do |value|
|
|
181
|
+
@title = value
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
opt.separator nil
|
|
185
|
+
|
|
186
|
+
opt.on("--webcvs=URL", "-W",
|
|
187
|
+
"Specify a URL for linking to a web frontend",
|
|
188
|
+
"to CVS. If the URL contains a '\%s', the",
|
|
189
|
+
"name of the current file will be",
|
|
190
|
+
"substituted; if the URL doesn't contain a",
|
|
191
|
+
"'\%s', the filename will be appended to it.") do |value|
|
|
192
|
+
@webcvs = value
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
opt.separator nil
|
|
196
|
+
opt.separator "Diagram Options:"
|
|
197
|
+
opt.separator nil
|
|
198
|
+
|
|
199
|
+
image_formats = %w[gif png jpg jpeg]
|
|
200
|
+
opt.on("--image-format=FORMAT", "-I", image_formats,
|
|
201
|
+
"Sets output image format for diagrams. Can",
|
|
202
|
+
"be #{image_formats.join ', '}. If this option",
|
|
203
|
+
"is omitted, png is used. Requires",
|
|
204
|
+
"diagrams.") do |value|
|
|
205
|
+
@image_format = value
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
opt.separator nil
|
|
209
|
+
|
|
210
|
+
opt.on("--diagram", "-d",
|
|
211
|
+
"Generate diagrams showing modules and",
|
|
212
|
+
"classes. You need dot V1.8.6 or later to",
|
|
213
|
+
"use the --diagram option correctly. Dot is",
|
|
214
|
+
"available from http://graphviz.org") do |value|
|
|
215
|
+
check_diagram
|
|
216
|
+
@diagram = true
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
opt.separator nil
|
|
220
|
+
|
|
221
|
+
opt.on("--fileboxes", "-F",
|
|
222
|
+
"Classes are put in boxes which represents",
|
|
223
|
+
"files, where these classes reside. Classes",
|
|
224
|
+
"shared between more than one file are",
|
|
225
|
+
"shown with list of files that are sharing",
|
|
226
|
+
"them. Silently discarded if --diagram is",
|
|
227
|
+
"not given.") do |value|
|
|
228
|
+
@fileboxes = value
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
opt.separator nil
|
|
232
|
+
opt.separator "ri Generator Options:"
|
|
233
|
+
opt.separator nil
|
|
234
|
+
|
|
235
|
+
opt.on("--ri", "-r",
|
|
236
|
+
"Generate output for use by `ri`. The files",
|
|
237
|
+
"are stored in the '.rdoc' directory under",
|
|
238
|
+
"your home directory unless overridden by a",
|
|
239
|
+
"subsequent --op parameter, so no special",
|
|
240
|
+
"privileges are needed.") do |value|
|
|
241
|
+
@generator_name = "ri"
|
|
242
|
+
@op_dir = RDoc::RI::Paths::HOMEDIR
|
|
243
|
+
setup_generator
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
opt.separator nil
|
|
247
|
+
|
|
248
|
+
opt.on("--ri-site", "-R",
|
|
249
|
+
"Generate output for use by `ri`. The files",
|
|
250
|
+
"are stored in a site-wide directory,",
|
|
251
|
+
"making them accessible to others, so",
|
|
252
|
+
"special privileges are needed.") do |value|
|
|
253
|
+
@generator_name = "ri"
|
|
254
|
+
@op_dir = RDoc::RI::Paths::SITEDIR
|
|
255
|
+
setup_generator
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
opt.separator nil
|
|
259
|
+
|
|
260
|
+
opt.on("--merge", "-M",
|
|
261
|
+
"When creating ri output, merge previously",
|
|
262
|
+
"processed classes into previously",
|
|
263
|
+
"documented classes of the same name.") do |value|
|
|
264
|
+
@merge = value
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
opt.separator nil
|
|
268
|
+
opt.separator "Generic Options:"
|
|
269
|
+
opt.separator nil
|
|
270
|
+
|
|
271
|
+
opt.on("--debug", "-D",
|
|
272
|
+
"Displays lots on internal stuff.") do |value|
|
|
273
|
+
$DEBUG_RDOC = value
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
opt.on("--quiet", "-q",
|
|
277
|
+
"Don't show progress as we parse.") do |value|
|
|
278
|
+
@verbosity = 0
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
opt.on("--verbose", "-v",
|
|
282
|
+
"Display extra progress as we parse.") do |value|
|
|
283
|
+
@verbosity = 2
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
opt.separator nil
|
|
287
|
+
opt.separator 'Deprecated options - these warn when set'
|
|
288
|
+
opt.separator nil
|
|
289
|
+
|
|
290
|
+
opt.on("--inline-source", "-S") do |value|
|
|
291
|
+
warn "--inline-source will be removed from RDoc on or after August 2009"
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
opt.on("--promiscuous", "-p") do |value|
|
|
295
|
+
warn "--promiscuous will be removed from RDoc on or after August 2009"
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
opt.separator nil
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
argv.insert(0, *ENV['RDOCOPT'].split) if ENV['RDOCOPT']
|
|
302
|
+
|
|
303
|
+
opts.parse! argv
|
|
304
|
+
|
|
305
|
+
@files = argv.dup
|
|
306
|
+
|
|
307
|
+
@rdoc_include << "." if @rdoc_include.empty?
|
|
308
|
+
|
|
309
|
+
if @exclude.empty? then
|
|
310
|
+
@exclude = nil
|
|
311
|
+
else
|
|
312
|
+
@exclude = Regexp.new(@exclude.join("|"))
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
check_files
|
|
316
|
+
|
|
317
|
+
# If no template was specified, use the default template for the output
|
|
318
|
+
# formatter
|
|
319
|
+
|
|
320
|
+
@template ||= @generator_name
|
|
321
|
+
|
|
322
|
+
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
|
|
323
|
+
puts opts
|
|
324
|
+
puts
|
|
325
|
+
puts e
|
|
326
|
+
exit 1
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
end
|