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
@@ -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