rdoc 3.12.2 → 4.0.0.preview2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rdoc might be problematic. Click here for more details.
- checksums.yaml +6 -6
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.autotest +3 -2
- data/DEVELOPERS.rdoc +53 -0
- data/History.rdoc +159 -25
- data/LEGAL.rdoc +12 -0
- data/Manifest.txt +56 -3
- data/README.rdoc +87 -19
- data/Rakefile +11 -2
- data/TODO.rdoc +20 -13
- data/bin/rdoc +4 -0
- data/lib/gauntlet_rdoc.rb +1 -1
- data/lib/rdoc.rb +32 -71
- data/lib/rdoc/any_method.rb +75 -21
- data/lib/rdoc/attr.rb +49 -10
- data/lib/rdoc/class_module.rb +182 -32
- data/lib/rdoc/code_object.rb +54 -12
- data/lib/rdoc/comment.rb +8 -1
- data/lib/rdoc/constant.rb +100 -6
- data/lib/rdoc/context.rb +93 -41
- data/lib/rdoc/context/section.rb +143 -28
- data/lib/rdoc/cross_reference.rb +58 -50
- data/lib/rdoc/encoding.rb +34 -29
- data/lib/rdoc/erb_partial.rb +18 -0
- data/lib/rdoc/extend.rb +117 -0
- data/lib/rdoc/generator.rb +11 -6
- data/lib/rdoc/generator/darkfish.rb +250 -62
- data/lib/rdoc/generator/json_index.rb +20 -12
- data/lib/rdoc/generator/markup.rb +10 -12
- data/lib/rdoc/generator/ri.rb +7 -60
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
- data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
- data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
- data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
- data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
- data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
- data/lib/rdoc/include.rb +12 -3
- data/lib/rdoc/markdown.kpeg +1186 -0
- data/lib/rdoc/markdown.rb +16336 -0
- data/lib/rdoc/markdown/entities.rb +2128 -0
- data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
- data/lib/rdoc/markdown/literals_1_8.rb +454 -0
- data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
- data/lib/rdoc/markdown/literals_1_9.rb +417 -0
- data/lib/rdoc/markup.rb +69 -10
- data/lib/rdoc/markup/attr_changer.rb +2 -5
- data/lib/rdoc/markup/attribute_manager.rb +23 -14
- data/lib/rdoc/markup/attributes.rb +70 -0
- data/lib/rdoc/markup/block_quote.rb +14 -0
- data/lib/rdoc/markup/document.rb +20 -4
- data/lib/rdoc/markup/formatter.rb +17 -6
- data/lib/rdoc/markup/formatter_test_case.rb +93 -24
- data/lib/rdoc/markup/hard_break.rb +31 -0
- data/lib/rdoc/markup/heading.rb +1 -1
- data/lib/rdoc/markup/indented_paragraph.rb +14 -0
- data/lib/rdoc/markup/list.rb +23 -4
- data/lib/rdoc/markup/list_item.rb +17 -4
- data/lib/rdoc/markup/paragraph.rb +14 -0
- data/lib/rdoc/markup/parser.rb +107 -60
- data/lib/rdoc/markup/raw.rb +4 -4
- data/lib/rdoc/markup/special.rb +3 -3
- data/lib/rdoc/markup/to_ansi.rb +7 -1
- data/lib/rdoc/markup/to_html.rb +42 -14
- data/lib/rdoc/markup/to_html_crossref.rb +10 -9
- data/lib/rdoc/markup/to_html_snippet.rb +20 -4
- data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
- data/lib/rdoc/markup/to_label.rb +20 -1
- data/lib/rdoc/markup/to_markdown.rb +134 -0
- data/lib/rdoc/markup/to_rdoc.rb +36 -5
- data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
- data/lib/rdoc/markup/to_tt_only.rb +11 -2
- data/lib/rdoc/markup/verbatim.rb +19 -0
- data/lib/rdoc/method_attr.rb +33 -19
- data/lib/rdoc/normal_class.rb +26 -7
- data/lib/rdoc/normal_module.rb +10 -5
- data/lib/rdoc/options.rb +95 -21
- data/lib/rdoc/parser.rb +6 -2
- data/lib/rdoc/parser/c.rb +212 -97
- data/lib/rdoc/parser/markdown.rb +23 -0
- data/lib/rdoc/parser/ruby.rb +115 -35
- data/lib/rdoc/parser/ruby_tools.rb +8 -3
- data/lib/rdoc/rd.rb +8 -4
- data/lib/rdoc/rd/block_parser.rb +1 -1
- data/lib/rdoc/rd/block_parser.ry +1 -1
- data/lib/rdoc/rdoc.rb +45 -21
- data/lib/rdoc/ri/driver.rb +322 -76
- data/lib/rdoc/ri/paths.rb +90 -31
- data/lib/rdoc/ri/store.rb +2 -353
- data/lib/rdoc/ruby_lex.rb +5 -21
- data/lib/rdoc/ruby_token.rb +2 -3
- data/lib/rdoc/rubygems_hook.rb +21 -9
- data/lib/rdoc/servlet.rb +302 -0
- data/lib/rdoc/stats.rb +28 -20
- data/lib/rdoc/store.rb +881 -0
- data/lib/rdoc/task.rb +2 -1
- data/lib/rdoc/test_case.rb +103 -1
- data/lib/rdoc/text.rb +5 -4
- data/lib/rdoc/tom_doc.rb +17 -16
- data/lib/rdoc/top_level.rb +43 -285
- data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
- data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
- data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
- data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
- data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
- data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
- data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
- data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
- data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
- data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
- data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
- data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
- data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
- data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
- data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
- data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
- data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
- data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
- data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
- data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
- data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
- data/test/test_attribute_manager.rb +7 -4
- data/test/test_rdoc_any_method.rb +84 -13
- data/test/test_rdoc_attr.rb +59 -9
- data/test/test_rdoc_class_module.rb +670 -73
- data/test/test_rdoc_code_object.rb +21 -1
- data/test/test_rdoc_comment.rb +1 -1
- data/test/test_rdoc_constant.rb +132 -0
- data/test/test_rdoc_context.rb +84 -18
- data/test/test_rdoc_context_section.rb +99 -15
- data/test/test_rdoc_cross_reference.rb +1 -1
- data/test/test_rdoc_encoding.rb +17 -1
- data/test/test_rdoc_extend.rb +94 -0
- data/test/test_rdoc_generator_darkfish.rb +45 -19
- data/test/test_rdoc_generator_json_index.rb +27 -7
- data/test/test_rdoc_generator_markup.rb +3 -3
- data/test/test_rdoc_generator_ri.rb +11 -9
- data/test/test_rdoc_include.rb +12 -0
- data/test/test_rdoc_markdown.rb +977 -0
- data/test/test_rdoc_markdown_test.rb +1891 -0
- data/test/test_rdoc_markup.rb +1 -1
- data/test/test_rdoc_markup_attribute_manager.rb +2 -2
- data/test/test_rdoc_markup_attributes.rb +39 -0
- data/test/test_rdoc_markup_document.rb +16 -1
- data/test/test_rdoc_markup_formatter.rb +7 -4
- data/test/test_rdoc_markup_hard_break.rb +31 -0
- data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
- data/test/test_rdoc_markup_paragraph.rb +15 -1
- data/test/test_rdoc_markup_parser.rb +152 -89
- data/test/test_rdoc_markup_to_ansi.rb +23 -2
- data/test/test_rdoc_markup_to_bs.rb +24 -0
- data/test/test_rdoc_markup_to_html.rb +50 -19
- data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
- data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
- data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
- data/test/test_rdoc_markup_to_label.rb +63 -1
- data/test/test_rdoc_markup_to_markdown.rb +352 -0
- data/test/test_rdoc_markup_to_rdoc.rb +22 -2
- data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
- data/test/test_rdoc_markup_to_tt_only.rb +20 -0
- data/test/test_rdoc_markup_verbatim.rb +13 -0
- data/test/test_rdoc_method_attr.rb +5 -0
- data/test/test_rdoc_normal_class.rb +24 -5
- data/test/test_rdoc_normal_module.rb +1 -1
- data/test/test_rdoc_options.rb +21 -6
- data/test/test_rdoc_parser.rb +24 -0
- data/test/test_rdoc_parser_c.rb +151 -26
- data/test/test_rdoc_parser_markdown.rb +55 -0
- data/test/test_rdoc_parser_rd.rb +2 -2
- data/test/test_rdoc_parser_ruby.rb +468 -109
- data/test/test_rdoc_parser_simple.rb +2 -2
- data/test/test_rdoc_rd_block_parser.rb +0 -4
- data/test/test_rdoc_rdoc.rb +110 -22
- data/test/test_rdoc_ri_driver.rb +415 -80
- data/test/test_rdoc_ri_paths.rb +122 -13
- data/test/test_rdoc_ruby_lex.rb +5 -61
- data/test/test_rdoc_ruby_token.rb +19 -0
- data/test/test_rdoc_rubygems_hook.rb +64 -43
- data/test/test_rdoc_servlet.rb +429 -0
- data/test/test_rdoc_stats.rb +83 -24
- data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
- data/test/test_rdoc_task.rb +2 -2
- data/test/test_rdoc_text.rb +37 -11
- data/test/test_rdoc_tom_doc.rb +59 -62
- data/test/test_rdoc_top_level.rb +71 -113
- data/test/xref_test_case.rb +7 -9
- metadata +122 -39
- metadata.gz.sig +0 -0
- data/CVE-2013-0256.rdoc +0 -49
- data/lib/rdoc/markup/attribute.rb +0 -51
data/lib/rdoc/ruby_lex.rb
CHANGED
@@ -857,7 +857,7 @@ class RDoc::RubyLex
|
|
857
857
|
end
|
858
858
|
|
859
859
|
IDENT_RE = if defined? Encoding then
|
860
|
-
|
860
|
+
/[\w\u0080-\uFFFF]/u
|
861
861
|
else
|
862
862
|
/[\w\x80-\xFF]/
|
863
863
|
end
|
@@ -982,13 +982,12 @@ class RDoc::RubyLex
|
|
982
982
|
indent = true
|
983
983
|
end
|
984
984
|
if /['"`]/ =~ ch
|
985
|
-
|
985
|
+
lt = ch
|
986
986
|
quoted = ""
|
987
987
|
while (c = getc) && c != lt
|
988
988
|
quoted.concat c
|
989
989
|
end
|
990
990
|
else
|
991
|
-
user_quote = nil
|
992
991
|
lt = '"'
|
993
992
|
quoted = ch.dup
|
994
993
|
while (c = getc) && c =~ /\w/
|
@@ -1008,17 +1007,8 @@ class RDoc::RubyLex
|
|
1008
1007
|
end
|
1009
1008
|
end
|
1010
1009
|
|
1011
|
-
output_heredoc = reserve.join =~ /\A\r?\n\z/
|
1012
|
-
|
1013
|
-
if output_heredoc then
|
1014
|
-
doc = '<<'
|
1015
|
-
doc << '-' if indent
|
1016
|
-
doc << "#{user_quote}#{quoted}#{user_quote}\n"
|
1017
|
-
else
|
1018
|
-
doc = '"'
|
1019
|
-
end
|
1020
|
-
|
1021
1010
|
@here_header = false
|
1011
|
+
doc = '"'
|
1022
1012
|
while l = gets
|
1023
1013
|
l = l.sub(/(:?\r)?\n\z/, "\n")
|
1024
1014
|
if (indent ? l.strip : l.chomp) == quoted
|
@@ -1026,12 +1016,7 @@ class RDoc::RubyLex
|
|
1026
1016
|
end
|
1027
1017
|
doc << l
|
1028
1018
|
end
|
1029
|
-
|
1030
|
-
if output_heredoc then
|
1031
|
-
doc << l.chomp
|
1032
|
-
else
|
1033
|
-
doc << '"'
|
1034
|
-
end
|
1019
|
+
doc << '"'
|
1035
1020
|
|
1036
1021
|
@here_header = true
|
1037
1022
|
@here_readed.concat reserve
|
@@ -1039,10 +1024,9 @@ class RDoc::RubyLex
|
|
1039
1024
|
ungetc ch
|
1040
1025
|
end
|
1041
1026
|
|
1042
|
-
token_class = output_heredoc ? RDoc::RubyLex::TkHEREDOC : Ltype2Token[lt]
|
1043
1027
|
@ltype = ltback
|
1044
1028
|
@lex_state = EXPR_END
|
1045
|
-
Token(
|
1029
|
+
Token(Ltype2Token[lt], doc)
|
1046
1030
|
end
|
1047
1031
|
|
1048
1032
|
def identify_quotation
|
data/lib/rdoc/ruby_token.rb
CHANGED
@@ -331,7 +331,6 @@ module RDoc::RubyToken
|
|
331
331
|
[:TkINTEGER, TkVal],
|
332
332
|
[:TkFLOAT, TkVal],
|
333
333
|
[:TkSTRING, TkVal],
|
334
|
-
[:TkHEREDOC, TkVal],
|
335
334
|
[:TkXSTRING, TkVal],
|
336
335
|
[:TkREGEXP, TkVal],
|
337
336
|
[:TkSYMBOL, TkVal],
|
@@ -371,13 +370,13 @@ module RDoc::RubyToken
|
|
371
370
|
[:TkfLPAREN, Token, "("], # func( #
|
372
371
|
[:TkfLBRACK, Token, "["], # func[ #
|
373
372
|
[:TkfLBRACE, Token, "{"], # func{ #
|
374
|
-
[:TkSTAR, Token, "*"], # *arg
|
375
|
-
[:TkAMPER, Token, "&"], # &arg #
|
376
373
|
[:TkSYMBEG, Token, ":"], # :SYMBOL
|
377
374
|
|
375
|
+
[:TkAMPER, TkOp, "&"],
|
378
376
|
[:TkGT, TkOp, ">"],
|
379
377
|
[:TkLT, TkOp, "<"],
|
380
378
|
[:TkPLUS, TkOp, "+"],
|
379
|
+
[:TkSTAR, TkOp, "*"],
|
381
380
|
[:TkMINUS, TkOp, "-"],
|
382
381
|
[:TkMULT, TkOp, "*"],
|
383
382
|
[:TkDIV, TkOp, "/"],
|
data/lib/rdoc/rubygems_hook.rb
CHANGED
@@ -73,7 +73,6 @@ class RDoc::RubygemsHook
|
|
73
73
|
|
74
74
|
def initialize spec, generate_rdoc = true, generate_ri = true
|
75
75
|
@doc_dir = spec.doc_dir
|
76
|
-
@file_info = nil
|
77
76
|
@force = false
|
78
77
|
@rdoc = nil
|
79
78
|
@spec = spec
|
@@ -104,23 +103,27 @@ class RDoc::RubygemsHook
|
|
104
103
|
# Documentation will be generated into +destination+
|
105
104
|
|
106
105
|
def document generator, options, destination
|
106
|
+
generator_name = generator
|
107
|
+
|
107
108
|
options = options.dup
|
108
109
|
options.exclude ||= [] # TODO maybe move to RDoc::Options#finish
|
109
110
|
options.setup_generator generator
|
110
111
|
options.op_dir = destination
|
111
112
|
options.finish
|
112
113
|
|
114
|
+
generator = options.generator.new @rdoc.store, options
|
115
|
+
|
113
116
|
@rdoc.options = options
|
114
|
-
@rdoc.generator =
|
117
|
+
@rdoc.generator = generator
|
115
118
|
|
116
|
-
say "Installing #{
|
119
|
+
say "Installing #{generator_name} documentation for #{@spec.full_name}"
|
117
120
|
|
118
121
|
FileUtils.mkdir_p options.op_dir
|
119
122
|
|
120
123
|
Dir.chdir options.op_dir do
|
121
124
|
begin
|
122
125
|
@rdoc.class.current = @rdoc
|
123
|
-
@rdoc.generator.generate
|
126
|
+
@rdoc.generator.generate
|
124
127
|
ensure
|
125
128
|
@rdoc.class.current = nil
|
126
129
|
end
|
@@ -131,17 +134,16 @@ class RDoc::RubygemsHook
|
|
131
134
|
# Generates RDoc and ri data
|
132
135
|
|
133
136
|
def generate
|
137
|
+
return if @spec.default_gem?
|
134
138
|
return unless @generate_ri or @generate_rdoc
|
135
139
|
|
136
140
|
setup
|
137
141
|
|
138
|
-
::RDoc::RDoc.reset
|
139
|
-
|
140
142
|
options = ::RDoc::Options.new
|
141
143
|
options.default_title = "#{@spec.full_name} Documentation"
|
142
144
|
options.files = []
|
143
|
-
options.files.
|
144
|
-
options.files.
|
145
|
+
options.files.concat @spec.require_paths
|
146
|
+
options.files.concat @spec.extra_rdoc_files
|
145
147
|
|
146
148
|
args = @spec.rdoc_options
|
147
149
|
|
@@ -159,8 +161,18 @@ class RDoc::RubygemsHook
|
|
159
161
|
@rdoc = new_rdoc
|
160
162
|
@rdoc.options = options
|
161
163
|
|
164
|
+
store = RDoc::Store.new
|
165
|
+
store.encoding = options.encoding if options.respond_to? :encoding
|
166
|
+
store.dry_run = options.dry_run
|
167
|
+
store.main = options.main_page
|
168
|
+
store.title = options.title
|
169
|
+
|
170
|
+
@rdoc.store = RDoc::Store.new
|
171
|
+
|
172
|
+
say "Parsing documentation for #{@spec.full_name}"
|
173
|
+
|
162
174
|
Dir.chdir @spec.full_gem_path do
|
163
|
-
@
|
175
|
+
@rdoc.parse_files options.files
|
164
176
|
end
|
165
177
|
|
166
178
|
document 'ri', options, @ri_dir if
|
data/lib/rdoc/servlet.rb
ADDED
@@ -0,0 +1,302 @@
|
|
1
|
+
require 'rdoc'
|
2
|
+
require 'time'
|
3
|
+
require 'webrick'
|
4
|
+
|
5
|
+
class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
6
|
+
|
7
|
+
@server_stores = Hash.new { |hash, server| hash[server] = {} }
|
8
|
+
@cache = Hash.new { |hash, store| hash[store] = {} }
|
9
|
+
|
10
|
+
attr_reader :asset_dirs
|
11
|
+
|
12
|
+
attr_reader :options
|
13
|
+
|
14
|
+
def self.get_instance server, *options
|
15
|
+
stores = @server_stores[server]
|
16
|
+
|
17
|
+
new server, stores, @cache, *options
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize server, stores, cache, mount_path = nil
|
21
|
+
super server
|
22
|
+
|
23
|
+
@cache = cache
|
24
|
+
@mount_path = mount_path
|
25
|
+
@stores = stores
|
26
|
+
|
27
|
+
@options = RDoc::Options.new
|
28
|
+
@options.op_dir = '.'
|
29
|
+
|
30
|
+
darkfish_dir = nil
|
31
|
+
|
32
|
+
# HACK dup
|
33
|
+
$LOAD_PATH.each do |path|
|
34
|
+
darkfish_dir = File.join path, 'rdoc/generator/template/darkfish/'
|
35
|
+
next unless File.directory? darkfish_dir
|
36
|
+
@options.template_dir = darkfish_dir
|
37
|
+
break
|
38
|
+
end
|
39
|
+
|
40
|
+
@asset_dirs = {
|
41
|
+
:darkfish => darkfish_dir,
|
42
|
+
:json_index =>
|
43
|
+
File.expand_path('../generator/template/json_index/', __FILE__),
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def asset generator_name, req, res
|
48
|
+
asset_dir = @asset_dirs[generator_name]
|
49
|
+
|
50
|
+
asset_path = File.join asset_dir, req.path
|
51
|
+
|
52
|
+
if_modified_since req, res, asset_path
|
53
|
+
|
54
|
+
res.body = File.read asset_path
|
55
|
+
|
56
|
+
res.content_type = case req.path
|
57
|
+
when /css$/ then 'text/css'
|
58
|
+
when /js$/ then 'application/javascript'
|
59
|
+
else 'application/octet-stream'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def do_GET req, res
|
64
|
+
req.path.sub!(/^#{Regexp.escape @mount_path}/o, '') if @mount_path
|
65
|
+
|
66
|
+
case req.path
|
67
|
+
when '/' then
|
68
|
+
root req, res
|
69
|
+
when '/rdoc.css', '/js/darkfish.js', '/js/jquery.js', '/js/search.js',
|
70
|
+
%r%^/images/% then
|
71
|
+
asset :darkfish, req, res
|
72
|
+
when '/js/navigation.js', '/js/searcher.js' then
|
73
|
+
asset :json_index, req, res
|
74
|
+
when '/js/search_index.js' then
|
75
|
+
root_search req, res
|
76
|
+
else
|
77
|
+
show_documentation req, res
|
78
|
+
end
|
79
|
+
rescue WEBrick::HTTPStatus::Status
|
80
|
+
raise
|
81
|
+
rescue => e
|
82
|
+
error e, req, res
|
83
|
+
end
|
84
|
+
|
85
|
+
def documentation_page store, generator, path, req, res
|
86
|
+
name = path.sub(/.html$/, '').gsub '/', '::'
|
87
|
+
|
88
|
+
if klass = store.find_class_or_module(name) then
|
89
|
+
res.body = generator.generate_class klass
|
90
|
+
elsif page = store.find_text_page(name.sub(/_([^_]*)$/, '.\1')) then
|
91
|
+
res.body = generator.generate_page page
|
92
|
+
else
|
93
|
+
not_found generator, req, res
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def documentation_search store, generator, req, res
|
98
|
+
json_index = @cache[store].fetch :json_index do
|
99
|
+
@cache[store][:json_index] =
|
100
|
+
JSON.dump generator.json_index.build_index
|
101
|
+
end
|
102
|
+
|
103
|
+
res.content_type = 'application/javascript'
|
104
|
+
res.body = "var search_data = #{json_index}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def documentation_source path
|
108
|
+
_, source_name, path = path.split '/', 3
|
109
|
+
|
110
|
+
store = @stores[source_name]
|
111
|
+
return store, path if store
|
112
|
+
|
113
|
+
store = store_for source_name
|
114
|
+
|
115
|
+
store.load_all
|
116
|
+
|
117
|
+
@stores[source_name] = store
|
118
|
+
|
119
|
+
return store, path
|
120
|
+
end
|
121
|
+
|
122
|
+
def error e, req, res
|
123
|
+
backtrace = e.backtrace.join "\n"
|
124
|
+
|
125
|
+
res.content_type = 'text/html'
|
126
|
+
res.status = 500
|
127
|
+
res.body = <<-BODY
|
128
|
+
<!DOCTYPE html>
|
129
|
+
<html>
|
130
|
+
<head>
|
131
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
132
|
+
|
133
|
+
<title>Error - #{ERB::Util.html_escape e.class}</title>
|
134
|
+
|
135
|
+
<link type="text/css" media="screen" href="#{@mount_path}/rdoc.css" rel="stylesheet">
|
136
|
+
</head>
|
137
|
+
<body>
|
138
|
+
<h1>Error</h1>
|
139
|
+
|
140
|
+
<p>While processing <code>#{ERB::Util.html_escape req.request_uri}</code> the
|
141
|
+
RDoc server has encountered a <code>#{ERB::Util.html_escape e.class}</code>
|
142
|
+
exception:
|
143
|
+
|
144
|
+
<pre>#{ERB::Util.html_escape e.message}</pre>
|
145
|
+
|
146
|
+
<p>Backtrace:
|
147
|
+
|
148
|
+
<pre>#{ERB::Util.html_escape backtrace}</pre>
|
149
|
+
|
150
|
+
</body>
|
151
|
+
</html>
|
152
|
+
BODY
|
153
|
+
end
|
154
|
+
|
155
|
+
def generator_for store
|
156
|
+
generator = RDoc::Generator::Darkfish.new store, @options
|
157
|
+
generator.file_output = false
|
158
|
+
generator.asset_rel_path = '..'
|
159
|
+
|
160
|
+
rdoc = RDoc::RDoc.new
|
161
|
+
rdoc.store = store
|
162
|
+
rdoc.generator = generator
|
163
|
+
rdoc.options = @options
|
164
|
+
|
165
|
+
@options.main_page = store.main
|
166
|
+
@options.title = store.title
|
167
|
+
|
168
|
+
generator
|
169
|
+
end
|
170
|
+
|
171
|
+
def if_modified_since req, res, path = nil
|
172
|
+
last_modified = File.stat(path).mtime if path
|
173
|
+
|
174
|
+
res['last-modified'] = last_modified.httpdate
|
175
|
+
|
176
|
+
return unless ims = req['if-modified-since']
|
177
|
+
|
178
|
+
ims = Time.parse ims
|
179
|
+
|
180
|
+
unless ims < last_modified then
|
181
|
+
res.body = ''
|
182
|
+
raise WEBrick::HTTPStatus::NotModified
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def installed_docs
|
187
|
+
ri_paths.map do |path, type|
|
188
|
+
store = RDoc::Store.new path, type
|
189
|
+
exists = File.exist? store.cache_path
|
190
|
+
|
191
|
+
case type
|
192
|
+
when :gem then
|
193
|
+
gem_path = path[%r%/([^/]*)/ri$%, 1]
|
194
|
+
[gem_path, "#{gem_path}/", exists, type, path]
|
195
|
+
when :system then
|
196
|
+
['Ruby Documentation', 'ruby/', exists, type, path]
|
197
|
+
when :site then
|
198
|
+
['Site Documentation', 'site/', exists, type, path]
|
199
|
+
when :home then
|
200
|
+
['Home Documentation', 'home/', exists, type, path]
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def not_found generator, req, res
|
206
|
+
res.body = generator.generate_servlet_not_found req.path
|
207
|
+
res.status = 404
|
208
|
+
end
|
209
|
+
|
210
|
+
def ri_paths &block
|
211
|
+
RDoc::RI::Paths.each true, true, true, :all, &block
|
212
|
+
end
|
213
|
+
|
214
|
+
def root req, res
|
215
|
+
generator = RDoc::Generator::Darkfish.new nil, @options
|
216
|
+
|
217
|
+
res.body = generator.generate_servlet_root installed_docs
|
218
|
+
|
219
|
+
res.content_type = 'text/html'
|
220
|
+
end
|
221
|
+
|
222
|
+
def root_search req, res
|
223
|
+
search_index = []
|
224
|
+
info = []
|
225
|
+
|
226
|
+
installed_docs.map do |name, href, exists, type, path|
|
227
|
+
next unless exists
|
228
|
+
|
229
|
+
search_index << name
|
230
|
+
|
231
|
+
comment = case type
|
232
|
+
when :gem
|
233
|
+
gemspec = path.gsub(%r%/doc/([^/]*?)/ri$%,
|
234
|
+
'/specifications/\1.gemspec')
|
235
|
+
|
236
|
+
spec = Gem::Specification.load gemspec
|
237
|
+
|
238
|
+
spec.summary
|
239
|
+
when :system then
|
240
|
+
'Documentation for the Ruby standard library'
|
241
|
+
when :site then
|
242
|
+
'Documentation for non-gem libraries'
|
243
|
+
when :home then
|
244
|
+
'Documentation from your home directory'
|
245
|
+
end
|
246
|
+
|
247
|
+
info << [name, '', path, '', comment]
|
248
|
+
end
|
249
|
+
|
250
|
+
index = {
|
251
|
+
:index => {
|
252
|
+
:searchIndex => search_index,
|
253
|
+
:longSearchIndex => search_index,
|
254
|
+
:info => info,
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
res.body = "var search_data = #{JSON.dump index};"
|
259
|
+
res.content_type = 'application/javascript'
|
260
|
+
end
|
261
|
+
|
262
|
+
def show_documentation req, res
|
263
|
+
store, path = documentation_source req.path
|
264
|
+
|
265
|
+
if_modified_since req, res, store.cache_path
|
266
|
+
|
267
|
+
generator = generator_for store
|
268
|
+
|
269
|
+
case path
|
270
|
+
when nil, '', 'index.html' then
|
271
|
+
res.body = generator.generate_index
|
272
|
+
when 'table_of_contents.html' then
|
273
|
+
res.body = generator.generate_table_of_contents
|
274
|
+
when 'js/search_index.js' then
|
275
|
+
documentation_search store, generator, req, res
|
276
|
+
else
|
277
|
+
documentation_page store, generator, path, req, res
|
278
|
+
end
|
279
|
+
ensure
|
280
|
+
res.content_type ||= 'text/html'
|
281
|
+
end
|
282
|
+
|
283
|
+
def store_for source_name
|
284
|
+
case source_name
|
285
|
+
when 'ruby' then
|
286
|
+
RDoc::Store.new RDoc::RI::Paths.system_dir, :system
|
287
|
+
else
|
288
|
+
ri_dir, type = ri_paths.find do |dir, dir_type|
|
289
|
+
next unless dir_type == :gem
|
290
|
+
|
291
|
+
source_name == dir[%r%/([^/]*)/ri$%, 1]
|
292
|
+
end
|
293
|
+
|
294
|
+
raise "could not find ri documentation for #{source_name}" unless
|
295
|
+
ri_dir
|
296
|
+
|
297
|
+
RDoc::Store.new ri_dir, type
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|