rdoc 6.17.0 → 8.1.0

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.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +193 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/LICENSE.rdoc +4 -0
  5. data/README.md +132 -8
  6. data/RI.md +75 -75
  7. data/doc/markup_reference/markdown.md +659 -0
  8. data/doc/markup_reference/rdoc.rdoc +1169 -0
  9. data/exe/rdoc +2 -2
  10. data/lib/rdoc/code_object/alias.rb +70 -74
  11. data/lib/rdoc/code_object/any_method.rb +308 -293
  12. data/lib/rdoc/code_object/attr.rb +150 -142
  13. data/lib/rdoc/code_object/class_module.rb +802 -715
  14. data/lib/rdoc/code_object/constant.rb +181 -144
  15. data/lib/rdoc/code_object/context/section.rb +140 -130
  16. data/lib/rdoc/code_object/context.rb +925 -941
  17. data/lib/rdoc/code_object/extend.rb +7 -5
  18. data/lib/rdoc/code_object/include.rb +7 -5
  19. data/lib/rdoc/code_object/method_attr.rb +328 -315
  20. data/lib/rdoc/code_object/mixin.rb +97 -92
  21. data/lib/rdoc/code_object/normal_class.rb +77 -78
  22. data/lib/rdoc/code_object/normal_module.rb +61 -59
  23. data/lib/rdoc/code_object/require.rb +23 -39
  24. data/lib/rdoc/code_object/single_class.rb +21 -19
  25. data/lib/rdoc/code_object/top_level.rb +215 -202
  26. data/lib/rdoc/code_object.rb +305 -305
  27. data/lib/rdoc/comment.rb +274 -337
  28. data/lib/rdoc/cross_reference.rb +195 -206
  29. data/lib/rdoc/encoding.rb +105 -103
  30. data/lib/rdoc/erb_partial.rb +13 -11
  31. data/lib/rdoc/erbio.rb +29 -27
  32. data/lib/rdoc/generator/aliki.rb +196 -30
  33. data/lib/rdoc/generator/darkfish.rb +647 -629
  34. data/lib/rdoc/generator/json_index.rb +233 -229
  35. data/lib/rdoc/generator/markup.rb +165 -122
  36. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  37. data/lib/rdoc/generator/pot/po.rb +52 -51
  38. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  39. data/lib/rdoc/generator/pot.rb +85 -81
  40. data/lib/rdoc/generator/ri.rb +23 -19
  41. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  42. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  43. data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
  44. data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
  45. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  46. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  47. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  48. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  49. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
  50. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  51. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  52. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  53. data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
  54. data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
  55. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
  57. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  58. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  59. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  60. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  61. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  62. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  63. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  64. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  65. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  66. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  67. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  68. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  69. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
  70. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  71. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  72. data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
  73. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
  74. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  75. data/lib/rdoc/generator.rb +48 -46
  76. data/lib/rdoc/i18n/locale.rb +99 -95
  77. data/lib/rdoc/i18n/text.rb +109 -105
  78. data/lib/rdoc/i18n.rb +7 -5
  79. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  80. data/lib/rdoc/markdown.kpeg +52 -33
  81. data/lib/rdoc/markdown.rb +365 -177
  82. data/lib/rdoc/markup/blank_line.rb +25 -23
  83. data/lib/rdoc/markup/block_quote.rb +12 -8
  84. data/lib/rdoc/markup/document.rb +127 -123
  85. data/lib/rdoc/markup/element.rb +21 -0
  86. data/lib/rdoc/markup/formatter.rb +220 -203
  87. data/lib/rdoc/markup/hard_break.rb +30 -27
  88. data/lib/rdoc/markup/heading.rb +163 -77
  89. data/lib/rdoc/markup/include.rb +33 -29
  90. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  91. data/lib/rdoc/markup/inline_parser.rb +316 -0
  92. data/lib/rdoc/markup/list.rb +80 -88
  93. data/lib/rdoc/markup/list_item.rb +73 -85
  94. data/lib/rdoc/markup/paragraph.rb +23 -19
  95. data/lib/rdoc/markup/parser.rb +501 -497
  96. data/lib/rdoc/markup/pre_process.rb +284 -305
  97. data/lib/rdoc/markup/raw.rb +52 -55
  98. data/lib/rdoc/markup/rule.rb +16 -12
  99. data/lib/rdoc/markup/table.rb +48 -40
  100. data/lib/rdoc/markup/to_ansi.rb +143 -92
  101. data/lib/rdoc/markup/to_bs.rb +86 -102
  102. data/lib/rdoc/markup/to_html.rb +608 -506
  103. data/lib/rdoc/markup/to_html_crossref.rb +219 -210
  104. data/lib/rdoc/markup/to_html_snippet.rb +210 -205
  105. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  106. data/lib/rdoc/markup/to_label.rb +64 -51
  107. data/lib/rdoc/markup/to_markdown.rb +212 -184
  108. data/lib/rdoc/markup/to_rdoc.rb +341 -277
  109. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  110. data/lib/rdoc/markup/to_test.rb +62 -50
  111. data/lib/rdoc/markup/to_tt_only.rb +83 -92
  112. data/lib/rdoc/markup/verbatim.rb +62 -58
  113. data/lib/rdoc/markup.rb +196 -215
  114. data/lib/rdoc/options.rb +1063 -1076
  115. data/lib/rdoc/parser/c.rb +1039 -1036
  116. data/lib/rdoc/parser/changelog.rb +320 -287
  117. data/lib/rdoc/parser/markdown.rb +17 -13
  118. data/lib/rdoc/parser/rbs.rb +279 -0
  119. data/lib/rdoc/parser/rd.rb +17 -13
  120. data/lib/rdoc/parser/ruby.rb +1231 -2222
  121. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  122. data/lib/rdoc/parser/simple.rb +31 -27
  123. data/lib/rdoc/parser/text.rb +12 -8
  124. data/lib/rdoc/parser.rb +230 -221
  125. data/lib/rdoc/rbs_helper.rb +186 -0
  126. data/lib/rdoc/rd/inline.rb +57 -53
  127. data/lib/rdoc/rd.rb +90 -88
  128. data/lib/rdoc/rdoc.rb +547 -366
  129. data/lib/rdoc/ri/driver.rb +1141 -1130
  130. data/lib/rdoc/ri/formatter.rb +7 -3
  131. data/lib/rdoc/ri/paths.rb +140 -136
  132. data/lib/rdoc/ri/servlet.rb +456 -0
  133. data/lib/rdoc/ri/store.rb +4 -2
  134. data/lib/rdoc/ri/task.rb +55 -51
  135. data/lib/rdoc/ri.rb +14 -11
  136. data/lib/rdoc/rubygems_hook.rb +194 -192
  137. data/lib/rdoc/server.rb +462 -0
  138. data/lib/rdoc/stats/normal.rb +46 -42
  139. data/lib/rdoc/stats/quiet.rb +39 -35
  140. data/lib/rdoc/stats/verbose.rb +35 -31
  141. data/lib/rdoc/stats.rb +363 -338
  142. data/lib/rdoc/store.rb +919 -725
  143. data/lib/rdoc/task.rb +260 -255
  144. data/lib/rdoc/text.rb +164 -240
  145. data/lib/rdoc/token_stream.rb +88 -106
  146. data/lib/rdoc/tom_doc.rb +203 -201
  147. data/lib/rdoc/version.rb +1 -1
  148. data/lib/rdoc.rb +35 -7
  149. data/lib/rubygems_plugin.rb +2 -11
  150. data/rdoc-logo.svg +43 -0
  151. data/rdoc.gemspec +9 -7
  152. metadata +46 -32
  153. data/CONTRIBUTING.rdoc +0 -219
  154. data/ExampleMarkdown.md +0 -39
  155. data/ExampleRDoc.rdoc +0 -210
  156. data/lib/rdoc/code_object/anon_class.rb +0 -10
  157. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  158. data/lib/rdoc/code_object/meta_method.rb +0 -6
  159. data/lib/rdoc/markdown/literals.kpeg +0 -21
  160. data/lib/rdoc/markdown/literals.rb +0 -454
  161. data/lib/rdoc/markup/attr_changer.rb +0 -22
  162. data/lib/rdoc/markup/attr_span.rb +0 -35
  163. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  164. data/lib/rdoc/markup/attributes.rb +0 -70
  165. data/lib/rdoc/markup/regexp_handling.rb +0 -40
  166. data/lib/rdoc/parser/prism_ruby.rb +0 -1100
  167. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  168. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  169. data/lib/rdoc/servlet.rb +0 -452
data/lib/rdoc/servlet.rb DELETED
@@ -1,452 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative '../rdoc'
3
- require 'erb'
4
- require 'time'
5
- require 'json'
6
-
7
- begin
8
- require 'webrick'
9
- rescue LoadError
10
- abort "webrick is not found. You may need to `gem install webrick` to install webrick."
11
- end
12
-
13
- ##
14
- # This is a WEBrick servlet that allows you to browse ri documentation.
15
- #
16
- # You can show documentation through either `ri --server` or, with RubyGems
17
- # 2.0 or newer, `gem server`. For ri, the server runs on port 8214 by
18
- # default. For RubyGems the server runs on port 8808 by default.
19
- #
20
- # You can use this servlet in your own project by mounting it on a WEBrick
21
- # server:
22
- #
23
- # require 'webrick'
24
- #
25
- # server = WEBrick::HTTPServer.new Port: 8000
26
- #
27
- # server.mount '/', RDoc::Servlet
28
- #
29
- # If you want to mount the servlet some other place than the root, provide the
30
- # base path when mounting:
31
- #
32
- # server.mount '/rdoc', RDoc::Servlet, '/rdoc'
33
-
34
- class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
35
-
36
- @server_stores = Hash.new { |hash, server| hash[server] = {} }
37
- @cache = Hash.new { |hash, store| hash[store] = {} }
38
-
39
- ##
40
- # Maps an asset type to its path on the filesystem
41
-
42
- attr_reader :asset_dirs
43
-
44
- ##
45
- # An RDoc::Options instance used for rendering options
46
-
47
- attr_reader :options
48
-
49
- ##
50
- # Creates an instance of this servlet that shares cached data between
51
- # requests.
52
-
53
- def self.get_instance server, *options # :nodoc:
54
- stores = @server_stores[server]
55
-
56
- new server, stores, @cache, *options
57
- end
58
-
59
- ##
60
- # Creates a new WEBrick servlet.
61
- #
62
- # Use +mount_path+ when mounting the servlet somewhere other than /.
63
- #
64
- # Use +extra_doc_dirs+ for additional documentation directories.
65
- #
66
- # +server+ is provided automatically by WEBrick when mounting. +stores+ and
67
- # +cache+ are provided automatically by the servlet.
68
-
69
- def initialize(server, stores, cache, mount_path = nil, extra_doc_dirs = [])
70
- super server
71
-
72
- @cache = cache
73
- @mount_path = mount_path
74
- @extra_doc_dirs = extra_doc_dirs
75
- @stores = stores
76
-
77
- @options = RDoc::Options.new
78
- @options.op_dir = '.'
79
-
80
- darkfish_dir = nil
81
-
82
- # HACK dup
83
- $LOAD_PATH.each do |path|
84
- darkfish_dir = File.join path, 'rdoc/generator/template/darkfish/'
85
- next unless File.directory? darkfish_dir
86
- @options.template_dir = darkfish_dir
87
- break
88
- end
89
-
90
- @asset_dirs = {
91
- :darkfish => darkfish_dir,
92
- :json_index =>
93
- File.expand_path('../generator/template/json_index/', __FILE__),
94
- }
95
- end
96
-
97
- ##
98
- # Serves the asset at the path in +req+ for +generator_name+ via +res+.
99
-
100
- def asset(generator_name, req, res)
101
- asset_dir = @asset_dirs[generator_name]
102
-
103
- asset_path = File.join asset_dir, req.path
104
-
105
- if_modified_since req, res, asset_path
106
-
107
- res.body = File.read asset_path
108
-
109
- res.content_type = case req.path
110
- when /\.css\z/ then 'text/css'
111
- when /\.js\z/ then 'application/javascript'
112
- else 'application/octet-stream'
113
- end
114
- end
115
-
116
- ##
117
- # GET request entry point. Fills in +res+ for the path, etc. in +req+.
118
-
119
- def do_GET(req, res)
120
- req.path.sub!(/\A#{Regexp.escape @mount_path}/, '') if @mount_path
121
-
122
- case req.path
123
- when '/' then
124
- root req, res
125
- when '/js/darkfish.js', '/js/jquery.js', '/js/search.js',
126
- %r%^/css/%, %r%^/images/%, %r%^/fonts/% then
127
- asset :darkfish, req, res
128
- when '/js/navigation.js', '/js/searcher.js' then
129
- asset :json_index, req, res
130
- when '/js/search_index.js' then
131
- root_search req, res
132
- else
133
- show_documentation req, res
134
- end
135
- rescue WEBrick::HTTPStatus::NotFound => e
136
- generator = generator_for RDoc::Store.new(@options)
137
-
138
- not_found generator, req, res, e.message
139
- rescue WEBrick::HTTPStatus::Status
140
- raise
141
- rescue => e
142
- error e, req, res
143
- end
144
-
145
- ##
146
- # Fills in +res+ with the class, module or page for +req+ from +store+.
147
- #
148
- # +path+ is relative to the mount_path and is used to determine the class,
149
- # module or page name (/RDoc/Servlet.html becomes RDoc::Servlet).
150
- # +generator+ is used to create the page.
151
-
152
- def documentation_page(store, generator, path, req, res)
153
- text_name = path.chomp '.html'
154
- name = text_name.gsub '/', '::'
155
-
156
- if klass = store.find_class_or_module(name) then
157
- res.body = generator.generate_class klass
158
- elsif page = store.find_text_page(name.sub(/_([^_]*)\z/, '.\1')) then
159
- res.body = generator.generate_page page
160
- elsif page = store.find_text_page(text_name.sub(/_([^_]*)\z/, '.\1')) then
161
- res.body = generator.generate_page page
162
- else
163
- not_found generator, req, res
164
- end
165
- end
166
-
167
- ##
168
- # Creates the JSON search index on +res+ for the given +store+. +generator+
169
- # must respond to \#json_index to build. +req+ is ignored.
170
-
171
- def documentation_search(store, generator, req, res)
172
- json_index = @cache[store].fetch :json_index do
173
- @cache[store][:json_index] =
174
- JSON.dump generator.json_index.build_index
175
- end
176
-
177
- res.content_type = 'application/javascript'
178
- res.body = "var search_data = #{json_index}"
179
- end
180
-
181
- ##
182
- # Returns the RDoc::Store and path relative to +mount_path+ for
183
- # documentation at +path+.
184
-
185
- def documentation_source(path)
186
- _, source_name, path = path.split '/', 3
187
-
188
- store = @stores[source_name]
189
- return store, path if store
190
-
191
- store = store_for source_name
192
-
193
- store.load_all
194
-
195
- @stores[source_name] = store
196
-
197
- return store, path
198
- end
199
-
200
- ##
201
- # Generates an error page for the +exception+ while handling +req+ on +res+.
202
-
203
- def error(exception, req, res)
204
- backtrace = exception.backtrace.join "\n"
205
-
206
- res.content_type = 'text/html'
207
- res.status = 500
208
- res.body = <<-BODY
209
- <!DOCTYPE html>
210
- <html>
211
- <head>
212
- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
213
-
214
- <title>Error - #{ERB::Util.html_escape exception.class}</title>
215
-
216
- <link type="text/css" media="screen" href="#{@mount_path}/css/rdoc.css" rel="stylesheet">
217
- </head>
218
- <body>
219
- <h1>Error</h1>
220
-
221
- <p>While processing <code>#{ERB::Util.html_escape req.request_uri}</code> the
222
- RDoc (#{ERB::Util.html_escape RDoc::VERSION}) server has encountered a
223
- <code>#{ERB::Util.html_escape exception.class}</code>
224
- exception:
225
-
226
- <pre>#{ERB::Util.html_escape exception.message}</pre>
227
-
228
- <p>Please report this to the
229
- <a href="https://github.com/ruby/rdoc/issues">RDoc issues tracker</a>. Please
230
- include the RDoc version, the URI above and exception class, message and
231
- backtrace. If you're viewing a gem's documentation, include the gem name and
232
- version. If you're viewing Ruby's documentation, include the version of ruby.
233
-
234
- <p>Backtrace:
235
-
236
- <pre>#{ERB::Util.html_escape backtrace}</pre>
237
-
238
- </body>
239
- </html>
240
- BODY
241
- end
242
-
243
- ##
244
- # Instantiates a Darkfish generator for +store+
245
-
246
- def generator_for(store)
247
- generator = RDoc::Generator::Darkfish.new store, @options
248
- generator.file_output = false
249
- generator.asset_rel_path = '..'
250
- generator.setup
251
-
252
- rdoc = RDoc::RDoc.new
253
- rdoc.store = store
254
- rdoc.generator = generator
255
- rdoc.options = @options
256
-
257
- @options.main_page = store.main
258
- @options.title = store.title
259
-
260
- generator
261
- end
262
-
263
- ##
264
- # Handles the If-Modified-Since HTTP header on +req+ for +path+. If the
265
- # file has not been modified a Not Modified response is returned. If the
266
- # file has been modified a Last-Modified header is added to +res+.
267
-
268
- def if_modified_since(req, res, path = nil)
269
- last_modified = File.stat(path).mtime if path
270
-
271
- res['last-modified'] = last_modified.httpdate
272
-
273
- return unless ims = req['if-modified-since']
274
-
275
- ims = Time.parse ims
276
-
277
- unless ims < last_modified then
278
- res.body = ''
279
- raise WEBrick::HTTPStatus::NotModified
280
- end
281
- end
282
-
283
- ##
284
- # Returns an Array of installed documentation.
285
- #
286
- # Each entry contains the documentation name (gem name, 'Ruby
287
- # Documentation', etc.), the path relative to the mount point, whether the
288
- # documentation exists, the type of documentation (See RDoc::RI::Paths#each)
289
- # and the filesystem to the RDoc::Store for the documentation.
290
-
291
- def installed_docs
292
- extra_counter = 0
293
- ri_paths.map do |path, type|
294
- store = RDoc::Store.new(@options, path: path, type: type)
295
- exists = File.exist? store.cache_path
296
-
297
- case type
298
- when :gem then
299
- gem_path = path[%r%/([^/]*)/ri$%, 1]
300
- [gem_path, "#{gem_path}/", exists, type, path]
301
- when :system then
302
- ['Ruby Documentation', 'ruby/', exists, type, path]
303
- when :site then
304
- ['Site Documentation', 'site/', exists, type, path]
305
- when :home then
306
- ['Home Documentation', 'home/', exists, type, path]
307
- when :extra then
308
- extra_counter += 1
309
- store.load_cache if exists
310
- title = store.title || "Extra Documentation"
311
- [title, "extra-#{extra_counter}/", exists, type, path]
312
- end
313
- end
314
- end
315
-
316
- ##
317
- # Returns a 404 page built by +generator+ for +req+ on +res+.
318
-
319
- def not_found(generator, req, res, message = nil)
320
- message ||= "The page <kbd>#{ERB::Util.h req.path}</kbd> was not found"
321
- res.body = generator.generate_servlet_not_found message
322
- res.status = 404
323
- end
324
-
325
- ##
326
- # Enumerates the ri paths. See RDoc::RI::Paths#each
327
-
328
- def ri_paths(&block)
329
- RDoc::RI::Paths.each true, true, true, :all, *@extra_doc_dirs, &block #TODO: pass extra_dirs
330
- end
331
-
332
- ##
333
- # Generates the root page on +res+. +req+ is ignored.
334
-
335
- def root(req, res)
336
- generator = RDoc::Generator::Darkfish.new nil, @options
337
-
338
- res.body = generator.generate_servlet_root installed_docs
339
-
340
- res.content_type = 'text/html'
341
- end
342
-
343
- ##
344
- # Generates a search index for the root page on +res+. +req+ is ignored.
345
-
346
- def root_search(req, res)
347
- search_index = []
348
- info = []
349
-
350
- installed_docs.map do |name, href, exists, type, path|
351
- next unless exists
352
-
353
- search_index << name
354
-
355
- case type
356
- when :gem
357
- gemspec = path.gsub(%r%/doc/([^/]*?)/ri$%,
358
- '/specifications/\1.gemspec')
359
-
360
- spec = Gem::Specification.load gemspec
361
-
362
- path = spec.full_name
363
- comment = spec.summary
364
- when :system then
365
- path = 'ruby'
366
- comment = 'Documentation for the Ruby standard library'
367
- when :site then
368
- path = 'site'
369
- comment = 'Documentation for non-gem libraries'
370
- when :home then
371
- path = 'home'
372
- comment = 'Documentation from your home directory'
373
- when :extra
374
- comment = name
375
- end
376
-
377
- info << [name, '', path, '', comment]
378
- end
379
-
380
- index = {
381
- :index => {
382
- :searchIndex => search_index,
383
- :longSearchIndex => search_index,
384
- :info => info,
385
- }
386
- }
387
-
388
- res.body = "var search_data = #{JSON.dump index};"
389
- res.content_type = 'application/javascript'
390
- end
391
-
392
- ##
393
- # Displays documentation for +req+ on +res+, whether that be HTML or some
394
- # asset.
395
-
396
- def show_documentation(req, res)
397
- store, path = documentation_source req.path
398
-
399
- if_modified_since req, res, store.cache_path
400
-
401
- generator = generator_for store
402
-
403
- case path
404
- when nil, '', 'index.html' then
405
- res.body = generator.generate_index
406
- when 'table_of_contents.html' then
407
- res.body = generator.generate_table_of_contents
408
- when 'js/search_index.js' then
409
- documentation_search store, generator, req, res
410
- else
411
- documentation_page store, generator, path, req, res
412
- end
413
- ensure
414
- res.content_type ||= 'text/html'
415
- end
416
-
417
- ##
418
- # Returns an RDoc::Store for the given +source_name+ ('ruby' or a gem name).
419
-
420
- def store_for(source_name)
421
- case source_name
422
- when 'home' then
423
- RDoc::Store.new(@options, path: RDoc::RI::Paths.home_dir, type: :home)
424
- when 'ruby' then
425
- RDoc::Store.new(@options, path: RDoc::RI::Paths.system_dir, type: :system)
426
- when 'site' then
427
- RDoc::Store.new(@options, path: RDoc::RI::Paths.site_dir, type: :site)
428
- when /\Aextra-(\d+)\z/ then
429
- index = $1.to_i - 1
430
- ri_dir = installed_docs[index][4]
431
- RDoc::Store.new(@options, path: ri_dir, type: :extra)
432
- else
433
- ri_dir, type = ri_paths.find do |dir, dir_type|
434
- next unless dir_type == :gem
435
-
436
- source_name == dir[%r%/([^/]*)/ri$%, 1]
437
- end
438
-
439
- raise WEBrick::HTTPStatus::NotFound,
440
- "Could not find gem \"#{ERB::Util.html_escape(source_name)}\". Are you sure you installed it?" unless ri_dir
441
-
442
- store = RDoc::Store.new(@options, path: ri_dir, type: type)
443
-
444
- return store if File.exist? store.cache_path
445
-
446
- raise WEBrick::HTTPStatus::NotFound,
447
- "Could not find documentation for \"#{ERB::Util.html_escape(source_name)}\". Please run `gem rdoc --ri gem_name`"
448
-
449
- end
450
- end
451
-
452
- end