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