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.

Files changed (200) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +3 -2
  5. data/DEVELOPERS.rdoc +53 -0
  6. data/History.rdoc +159 -25
  7. data/LEGAL.rdoc +12 -0
  8. data/Manifest.txt +56 -3
  9. data/README.rdoc +87 -19
  10. data/Rakefile +11 -2
  11. data/TODO.rdoc +20 -13
  12. data/bin/rdoc +4 -0
  13. data/lib/gauntlet_rdoc.rb +1 -1
  14. data/lib/rdoc.rb +32 -71
  15. data/lib/rdoc/any_method.rb +75 -21
  16. data/lib/rdoc/attr.rb +49 -10
  17. data/lib/rdoc/class_module.rb +182 -32
  18. data/lib/rdoc/code_object.rb +54 -12
  19. data/lib/rdoc/comment.rb +8 -1
  20. data/lib/rdoc/constant.rb +100 -6
  21. data/lib/rdoc/context.rb +93 -41
  22. data/lib/rdoc/context/section.rb +143 -28
  23. data/lib/rdoc/cross_reference.rb +58 -50
  24. data/lib/rdoc/encoding.rb +34 -29
  25. data/lib/rdoc/erb_partial.rb +18 -0
  26. data/lib/rdoc/extend.rb +117 -0
  27. data/lib/rdoc/generator.rb +11 -6
  28. data/lib/rdoc/generator/darkfish.rb +250 -62
  29. data/lib/rdoc/generator/json_index.rb +20 -12
  30. data/lib/rdoc/generator/markup.rb +10 -12
  31. data/lib/rdoc/generator/ri.rb +7 -60
  32. data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
  39. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
  41. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
  42. data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
  43. data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
  44. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  45. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
  46. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  47. data/lib/rdoc/include.rb +12 -3
  48. data/lib/rdoc/markdown.kpeg +1186 -0
  49. data/lib/rdoc/markdown.rb +16336 -0
  50. data/lib/rdoc/markdown/entities.rb +2128 -0
  51. data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
  52. data/lib/rdoc/markdown/literals_1_8.rb +454 -0
  53. data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
  54. data/lib/rdoc/markdown/literals_1_9.rb +417 -0
  55. data/lib/rdoc/markup.rb +69 -10
  56. data/lib/rdoc/markup/attr_changer.rb +2 -5
  57. data/lib/rdoc/markup/attribute_manager.rb +23 -14
  58. data/lib/rdoc/markup/attributes.rb +70 -0
  59. data/lib/rdoc/markup/block_quote.rb +14 -0
  60. data/lib/rdoc/markup/document.rb +20 -4
  61. data/lib/rdoc/markup/formatter.rb +17 -6
  62. data/lib/rdoc/markup/formatter_test_case.rb +93 -24
  63. data/lib/rdoc/markup/hard_break.rb +31 -0
  64. data/lib/rdoc/markup/heading.rb +1 -1
  65. data/lib/rdoc/markup/indented_paragraph.rb +14 -0
  66. data/lib/rdoc/markup/list.rb +23 -4
  67. data/lib/rdoc/markup/list_item.rb +17 -4
  68. data/lib/rdoc/markup/paragraph.rb +14 -0
  69. data/lib/rdoc/markup/parser.rb +107 -60
  70. data/lib/rdoc/markup/raw.rb +4 -4
  71. data/lib/rdoc/markup/special.rb +3 -3
  72. data/lib/rdoc/markup/to_ansi.rb +7 -1
  73. data/lib/rdoc/markup/to_html.rb +42 -14
  74. data/lib/rdoc/markup/to_html_crossref.rb +10 -9
  75. data/lib/rdoc/markup/to_html_snippet.rb +20 -4
  76. data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
  77. data/lib/rdoc/markup/to_label.rb +20 -1
  78. data/lib/rdoc/markup/to_markdown.rb +134 -0
  79. data/lib/rdoc/markup/to_rdoc.rb +36 -5
  80. data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
  81. data/lib/rdoc/markup/to_tt_only.rb +11 -2
  82. data/lib/rdoc/markup/verbatim.rb +19 -0
  83. data/lib/rdoc/method_attr.rb +33 -19
  84. data/lib/rdoc/normal_class.rb +26 -7
  85. data/lib/rdoc/normal_module.rb +10 -5
  86. data/lib/rdoc/options.rb +95 -21
  87. data/lib/rdoc/parser.rb +6 -2
  88. data/lib/rdoc/parser/c.rb +212 -97
  89. data/lib/rdoc/parser/markdown.rb +23 -0
  90. data/lib/rdoc/parser/ruby.rb +115 -35
  91. data/lib/rdoc/parser/ruby_tools.rb +8 -3
  92. data/lib/rdoc/rd.rb +8 -4
  93. data/lib/rdoc/rd/block_parser.rb +1 -1
  94. data/lib/rdoc/rd/block_parser.ry +1 -1
  95. data/lib/rdoc/rdoc.rb +45 -21
  96. data/lib/rdoc/ri/driver.rb +322 -76
  97. data/lib/rdoc/ri/paths.rb +90 -31
  98. data/lib/rdoc/ri/store.rb +2 -353
  99. data/lib/rdoc/ruby_lex.rb +5 -21
  100. data/lib/rdoc/ruby_token.rb +2 -3
  101. data/lib/rdoc/rubygems_hook.rb +21 -9
  102. data/lib/rdoc/servlet.rb +302 -0
  103. data/lib/rdoc/stats.rb +28 -20
  104. data/lib/rdoc/store.rb +881 -0
  105. data/lib/rdoc/task.rb +2 -1
  106. data/lib/rdoc/test_case.rb +103 -1
  107. data/lib/rdoc/text.rb +5 -4
  108. data/lib/rdoc/tom_doc.rb +17 -16
  109. data/lib/rdoc/top_level.rb +43 -285
  110. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
  111. data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
  112. data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
  113. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
  114. data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
  115. data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
  116. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
  117. data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
  118. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
  119. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
  120. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
  121. data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
  122. data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
  123. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
  124. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
  125. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
  126. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
  127. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
  128. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
  129. data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
  130. data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
  131. data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
  132. data/test/test_attribute_manager.rb +7 -4
  133. data/test/test_rdoc_any_method.rb +84 -13
  134. data/test/test_rdoc_attr.rb +59 -9
  135. data/test/test_rdoc_class_module.rb +670 -73
  136. data/test/test_rdoc_code_object.rb +21 -1
  137. data/test/test_rdoc_comment.rb +1 -1
  138. data/test/test_rdoc_constant.rb +132 -0
  139. data/test/test_rdoc_context.rb +84 -18
  140. data/test/test_rdoc_context_section.rb +99 -15
  141. data/test/test_rdoc_cross_reference.rb +1 -1
  142. data/test/test_rdoc_encoding.rb +17 -1
  143. data/test/test_rdoc_extend.rb +94 -0
  144. data/test/test_rdoc_generator_darkfish.rb +45 -19
  145. data/test/test_rdoc_generator_json_index.rb +27 -7
  146. data/test/test_rdoc_generator_markup.rb +3 -3
  147. data/test/test_rdoc_generator_ri.rb +11 -9
  148. data/test/test_rdoc_include.rb +12 -0
  149. data/test/test_rdoc_markdown.rb +977 -0
  150. data/test/test_rdoc_markdown_test.rb +1891 -0
  151. data/test/test_rdoc_markup.rb +1 -1
  152. data/test/test_rdoc_markup_attribute_manager.rb +2 -2
  153. data/test/test_rdoc_markup_attributes.rb +39 -0
  154. data/test/test_rdoc_markup_document.rb +16 -1
  155. data/test/test_rdoc_markup_formatter.rb +7 -4
  156. data/test/test_rdoc_markup_hard_break.rb +31 -0
  157. data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
  158. data/test/test_rdoc_markup_paragraph.rb +15 -1
  159. data/test/test_rdoc_markup_parser.rb +152 -89
  160. data/test/test_rdoc_markup_to_ansi.rb +23 -2
  161. data/test/test_rdoc_markup_to_bs.rb +24 -0
  162. data/test/test_rdoc_markup_to_html.rb +50 -19
  163. data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
  164. data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
  165. data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
  166. data/test/test_rdoc_markup_to_label.rb +63 -1
  167. data/test/test_rdoc_markup_to_markdown.rb +352 -0
  168. data/test/test_rdoc_markup_to_rdoc.rb +22 -2
  169. data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
  170. data/test/test_rdoc_markup_to_tt_only.rb +20 -0
  171. data/test/test_rdoc_markup_verbatim.rb +13 -0
  172. data/test/test_rdoc_method_attr.rb +5 -0
  173. data/test/test_rdoc_normal_class.rb +24 -5
  174. data/test/test_rdoc_normal_module.rb +1 -1
  175. data/test/test_rdoc_options.rb +21 -6
  176. data/test/test_rdoc_parser.rb +24 -0
  177. data/test/test_rdoc_parser_c.rb +151 -26
  178. data/test/test_rdoc_parser_markdown.rb +55 -0
  179. data/test/test_rdoc_parser_rd.rb +2 -2
  180. data/test/test_rdoc_parser_ruby.rb +468 -109
  181. data/test/test_rdoc_parser_simple.rb +2 -2
  182. data/test/test_rdoc_rd_block_parser.rb +0 -4
  183. data/test/test_rdoc_rdoc.rb +110 -22
  184. data/test/test_rdoc_ri_driver.rb +415 -80
  185. data/test/test_rdoc_ri_paths.rb +122 -13
  186. data/test/test_rdoc_ruby_lex.rb +5 -61
  187. data/test/test_rdoc_ruby_token.rb +19 -0
  188. data/test/test_rdoc_rubygems_hook.rb +64 -43
  189. data/test/test_rdoc_servlet.rb +429 -0
  190. data/test/test_rdoc_stats.rb +83 -24
  191. data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
  192. data/test/test_rdoc_task.rb +2 -2
  193. data/test/test_rdoc_text.rb +37 -11
  194. data/test/test_rdoc_tom_doc.rb +59 -62
  195. data/test/test_rdoc_top_level.rb +71 -113
  196. data/test/xref_test_case.rb +7 -9
  197. metadata +122 -39
  198. metadata.gz.sig +0 -0
  199. data/CVE-2013-0256.rdoc +0 -49
  200. data/lib/rdoc/markup/attribute.rb +0 -51
@@ -857,7 +857,7 @@ class RDoc::RubyLex
857
857
  end
858
858
 
859
859
  IDENT_RE = if defined? Encoding then
860
- eval '/[\w\u{0080}-\u{FFFFF}]/u' # 1.8 can't parse \u{}
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
- user_quote = lt = ch
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(token_class, doc)
1029
+ Token(Ltype2Token[lt], doc)
1046
1030
  end
1047
1031
 
1048
1032
  def identify_quotation
@@ -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, "/"],
@@ -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 = options.generator.new options
117
+ @rdoc.generator = generator
115
118
 
116
- say "Installing #{generator} documentation for #{@spec.full_name}"
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 @file_info
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.push(*@spec.require_paths)
144
- options.files.push(*@spec.extra_rdoc_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
- @file_info = @rdoc.parse_files options.files
175
+ @rdoc.parse_files options.files
164
176
  end
165
177
 
166
178
  document 'ri', options, @ri_dir if
@@ -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
+