rdoc 6.8.1 → 6.13.1

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rdoc/code_object/alias.rb +2 -9
  3. data/lib/rdoc/code_object/any_method.rb +7 -12
  4. data/lib/rdoc/code_object/attr.rb +4 -7
  5. data/lib/rdoc/code_object/class_module.rb +53 -20
  6. data/lib/rdoc/code_object/constant.rb +1 -1
  7. data/lib/rdoc/code_object/context/section.rb +10 -68
  8. data/lib/rdoc/code_object/context.rb +4 -46
  9. data/lib/rdoc/code_object/method_attr.rb +16 -24
  10. data/lib/rdoc/code_object/require.rb +1 -1
  11. data/lib/rdoc/code_object/top_level.rb +6 -24
  12. data/lib/rdoc/code_object.rb +3 -35
  13. data/lib/rdoc/comment.rb +12 -5
  14. data/lib/rdoc/generator/darkfish.rb +92 -108
  15. data/lib/rdoc/generator/json_index.rb +1 -17
  16. data/lib/rdoc/generator/markup.rb +2 -2
  17. data/lib/rdoc/generator/pot/message_extractor.rb +2 -2
  18. data/lib/rdoc/generator/pot.rb +0 -5
  19. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -29
  20. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +1 -1
  21. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +1 -1
  22. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -0
  23. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +40 -21
  24. data/lib/rdoc/generator/template/darkfish/index.rhtml +4 -4
  25. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -1
  26. data/lib/rdoc/markdown.kpeg +7 -5
  27. data/lib/rdoc/markdown.rb +34 -21
  28. data/lib/rdoc/markup/formatter.rb +19 -12
  29. data/lib/rdoc/markup/heading.rb +7 -1
  30. data/lib/rdoc/markup/pre_process.rb +17 -0
  31. data/lib/rdoc/markup/to_html.rb +7 -2
  32. data/lib/rdoc/markup/to_html_crossref.rb +63 -12
  33. data/lib/rdoc/markup/to_rdoc.rb +1 -1
  34. data/lib/rdoc/options.rb +68 -7
  35. data/lib/rdoc/parser/c.rb +29 -8
  36. data/lib/rdoc/parser/changelog.rb +3 -2
  37. data/lib/rdoc/parser/prism_ruby.rb +1092 -0
  38. data/lib/rdoc/parser/ruby.rb +8 -11
  39. data/lib/rdoc/parser/simple.rb +1 -1
  40. data/lib/rdoc/parser.rb +3 -3
  41. data/lib/rdoc/rd/block_parser.rb +3 -3
  42. data/lib/rdoc/rd/inline_parser.rb +3 -3
  43. data/lib/rdoc/rdoc.rb +6 -19
  44. data/lib/rdoc/ri/driver.rb +75 -26
  45. data/lib/rdoc/rubygems_hook.rb +91 -15
  46. data/lib/rdoc/servlet.rb +8 -7
  47. data/lib/rdoc/stats.rb +2 -2
  48. data/lib/rdoc/store.rb +21 -13
  49. data/lib/rdoc/text.rb +2 -2
  50. data/lib/rdoc/version.rb +1 -1
  51. data/lib/rdoc.rb +0 -2
  52. data/lib/rubygems_plugin.rb +23 -0
  53. metadata +5 -10
  54. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
  57. data/lib/rdoc/generator/template/json_index/.document +0 -1
@@ -170,7 +170,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
170
170
  ##
171
171
  # Creates a new Ruby parser.
172
172
 
173
- def initialize(top_level, file_name, content, options, stats)
173
+ def initialize(top_level, content, options, stats)
174
174
  super
175
175
 
176
176
  content = handle_tab_width(content)
@@ -293,7 +293,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
293
293
  # Creates a new attribute in +container+ with +name+.
294
294
 
295
295
  def create_attr container, single, name, rw, comment # :nodoc:
296
- att = RDoc::Attr.new get_tkread, name, rw, comment, single == SINGLE
296
+ att = RDoc::Attr.new get_tkread, name, rw, comment, singleton: single == SINGLE
297
297
  record_location att
298
298
 
299
299
  container.add_attribute att
@@ -792,8 +792,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
792
792
  return
793
793
  end
794
794
 
795
- al = RDoc::Alias.new(get_tkread, old_name, new_name, comment,
796
- single == SINGLE)
795
+ al = RDoc::Alias.new(get_tkread, old_name, new_name, comment, singleton: single == SINGLE)
797
796
  record_location al
798
797
  al.line = line_no
799
798
 
@@ -1153,7 +1152,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1153
1152
  end
1154
1153
 
1155
1154
  comment.normalize
1156
- comment.extract_call_seq meth
1155
+ meth.call_seq = comment.extract_call_seq
1157
1156
 
1158
1157
  return unless meth.name
1159
1158
 
@@ -1358,10 +1357,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
1358
1357
 
1359
1358
  return unless name
1360
1359
 
1361
- meth = RDoc::MetaMethod.new get_tkread, name
1360
+ meth = RDoc::MetaMethod.new get_tkread, name, singleton: singleton
1362
1361
  record_location meth
1363
1362
  meth.line = line_no
1364
- meth.singleton = singleton
1365
1363
 
1366
1364
  remove_token_listener self
1367
1365
 
@@ -1417,7 +1415,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1417
1415
 
1418
1416
  look_for_directives_in meth, comment
1419
1417
  comment.normalize
1420
- comment.extract_call_seq meth
1418
+ meth.call_seq = comment.extract_call_seq
1421
1419
 
1422
1420
  container.add_method meth
1423
1421
 
@@ -1461,9 +1459,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
1461
1459
 
1462
1460
  return unless name
1463
1461
 
1464
- meth = RDoc::AnyMethod.new get_tkread, name
1462
+ meth = RDoc::AnyMethod.new get_tkread, name, singleton: single == SINGLE ? true : singleton
1465
1463
  look_for_directives_in meth, comment
1466
- meth.singleton = single == SINGLE ? true : singleton
1467
1464
  if singleton
1468
1465
  # `current_line_visibility' is useless because it works against
1469
1466
  # the normal method named as same as the singleton method, after
@@ -1485,7 +1482,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1485
1482
  parse_method_params_and_body container, single, meth, added_container
1486
1483
 
1487
1484
  comment.normalize
1488
- comment.extract_call_seq meth
1485
+ meth.call_seq = comment.extract_call_seq
1489
1486
 
1490
1487
  meth.comment = comment
1491
1488
 
@@ -14,7 +14,7 @@ class RDoc::Parser::Simple < RDoc::Parser
14
14
  ##
15
15
  # Prepare to parse a plain file
16
16
 
17
- def initialize(top_level, file_name, content, options, stats)
17
+ def initialize(top_level, content, options, stats)
18
18
  super
19
19
 
20
20
  preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
data/lib/rdoc/parser.rb CHANGED
@@ -191,7 +191,7 @@ class RDoc::Parser
191
191
 
192
192
  content = remove_modeline content
193
193
 
194
- parser.new top_level, file_name, content, options, stats
194
+ parser.new top_level, content, options, stats
195
195
  rescue SystemCallError
196
196
  nil
197
197
  end
@@ -252,12 +252,12 @@ class RDoc::Parser
252
252
  # RDoc::Markup::PreProcess object is created which allows processing of
253
253
  # directives.
254
254
 
255
- def initialize top_level, file_name, content, options, stats
255
+ def initialize top_level, content, options, stats
256
256
  @top_level = top_level
257
257
  @top_level.parser = self.class
258
258
  @store = @top_level.store
259
259
 
260
- @file_name = file_name
260
+ @file_name = top_level.absolute_name
261
261
  @content = content
262
262
  @options = options
263
263
  @stats = stats
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # DO NOT MODIFY!!!!
4
- # This file is automatically generated by Racc 1.8.0
4
+ # This file is automatically generated by Racc 1.8.1
5
5
  # from Racc grammar file "block_parser.ry".
6
6
  #
7
7
 
@@ -23,7 +23,7 @@ unless $".find {|p| p.end_with?('/racc/info.rb')}
23
23
  $".push "#{__dir__}/racc/info.rb"
24
24
 
25
25
  module Racc
26
- VERSION = '1.8.0'
26
+ VERSION = '1.8.1'
27
27
  Version = VERSION
28
28
  Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
29
29
  end
@@ -38,7 +38,7 @@ unless defined?(::ParseError)
38
38
  ParseError = Racc::ParseError # :nodoc:
39
39
  end
40
40
 
41
- # Racc is a LALR(1) parser generator.
41
+ # Racc is an LALR(1) parser generator.
42
42
  # It is written in Ruby itself, and generates Ruby programs.
43
43
  #
44
44
  # == Command-line Reference
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # DO NOT MODIFY!!!!
4
- # This file is automatically generated by Racc 1.8.0
4
+ # This file is automatically generated by Racc 1.8.1
5
5
  # from Racc grammar file "inline_parser.ry".
6
6
  #
7
7
 
@@ -23,7 +23,7 @@ unless $".find {|p| p.end_with?('/racc/info.rb')}
23
23
  $".push "#{__dir__}/racc/info.rb"
24
24
 
25
25
  module Racc
26
- VERSION = '1.8.0'
26
+ VERSION = '1.8.1'
27
27
  Version = VERSION
28
28
  Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
29
29
  end
@@ -38,7 +38,7 @@ unless defined?(::ParseError)
38
38
  ParseError = Racc::ParseError # :nodoc:
39
39
  end
40
40
 
41
- # Racc is a LALR(1) parser generator.
41
+ # Racc is an LALR(1) parser generator.
42
42
  # It is written in Ruby itself, and generates Ruby programs.
43
43
  #
44
44
  # == Command-line Reference
data/lib/rdoc/rdoc.rb CHANGED
@@ -69,7 +69,7 @@ class RDoc::RDoc
69
69
  ##
70
70
  # The current documentation store
71
71
 
72
- attr_reader :store
72
+ attr_accessor :store
73
73
 
74
74
  ##
75
75
  # Add +klass+ that can generate output after parsing
@@ -208,15 +208,6 @@ option)
208
208
  last
209
209
  end
210
210
 
211
- ##
212
- # Sets the current documentation tree to +store+ and sets the store's rdoc
213
- # driver to this instance.
214
-
215
- def store= store
216
- @store = store
217
- @store.rdoc = self
218
- end
219
-
220
211
  ##
221
212
  # Update the flag file in an output directory.
222
213
 
@@ -395,7 +386,6 @@ The internal error was:
395
386
  $stderr.puts e.backtrace.join("\n\t") if $DEBUG_RDOC
396
387
 
397
388
  raise e
398
- nil
399
389
  end
400
390
 
401
391
  ##
@@ -407,6 +397,7 @@ The internal error was:
407
397
 
408
398
  return [] if file_list.empty?
409
399
 
400
+ # This workaround can be removed after the :main: directive is removed
410
401
  original_options = @options.dup
411
402
  @stats.begin_adding
412
403
 
@@ -415,6 +406,8 @@ The internal error was:
415
406
  parse_file filename
416
407
  end.compact
417
408
 
409
+ @store.resolve_c_superclasses
410
+
418
411
  @stats.done_adding
419
412
  @options = original_options
420
413
 
@@ -448,8 +441,6 @@ The internal error was:
448
441
  # current directory, so make sure you're somewhere writable before invoking.
449
442
 
450
443
  def document options
451
- self.store = RDoc::Store.new
452
-
453
444
  if RDoc::Options === options then
454
445
  @options = options
455
446
  else
@@ -458,6 +449,8 @@ The internal error was:
458
449
  end
459
450
  @options.finish
460
451
 
452
+ @store = RDoc::Store.new(@options)
453
+
461
454
  if @options.pipe then
462
455
  handle_pipe
463
456
  exit
@@ -467,12 +460,6 @@ The internal error was:
467
460
  @last_modified = setup_output_dir @options.op_dir, @options.force_update
468
461
  end
469
462
 
470
- @store.encoding = @options.encoding
471
- @store.dry_run = @options.dry_run
472
- @store.main = @options.main_page
473
- @store.title = @options.title
474
- @store.path = @options.op_dir
475
-
476
463
  @start_time = Time.now
477
464
 
478
465
  @store.load_cache
@@ -79,6 +79,7 @@ class RDoc::RI::Driver
79
79
  options[:interactive] = false
80
80
  options[:profile] = false
81
81
  options[:show_all] = false
82
+ options[:expand_refs] = true
82
83
  options[:use_stdout] = !$stdout.tty?
83
84
  options[:width] = 72
84
85
 
@@ -245,6 +246,12 @@ or the PAGER environment variable.
245
246
 
246
247
  opt.separator nil
247
248
 
249
+ opt.on("--[no-]expand-refs", "Expand rdoc-refs at the end of output") do |value|
250
+ options[:expand_refs] = value
251
+ end
252
+
253
+ opt.separator nil
254
+
248
255
  opt.on("--help", "-h",
249
256
  "Show help and exit.") do
250
257
  puts opts
@@ -413,7 +420,7 @@ or the PAGER environment variable.
413
420
  *options[:extra_doc_dirs]) do |path, type|
414
421
  @doc_dirs << path
415
422
 
416
- store = RDoc::RI::Store.new path, type
423
+ store = RDoc::RI::Store.new(RDoc::Options.new, path: path, type: type)
417
424
  store.load_cache
418
425
  @stores << store
419
426
  end
@@ -425,6 +432,7 @@ or the PAGER environment variable.
425
432
  @use_stdout = options[:use_stdout]
426
433
  @show_all = options[:show_all]
427
434
  @width = options[:width]
435
+ @expand_refs = options[:expand_refs]
428
436
  end
429
437
 
430
438
  ##
@@ -510,7 +518,7 @@ or the PAGER environment variable.
510
518
  with.each do |incl|
511
519
  out << RDoc::Markup::Paragraph.new(incl.name)
512
520
  out << RDoc::Markup::BlankLine.new
513
- out << incl.comment
521
+ out << incl.comment.parse
514
522
  end
515
523
 
516
524
  unless wout.empty? then
@@ -534,7 +542,7 @@ or the PAGER environment variable.
534
542
 
535
543
  if include.comment then
536
544
  out << RDoc::Markup::BlankLine.new
537
- out << include.comment
545
+ out << include.comment.parse
538
546
  end
539
547
  end
540
548
 
@@ -549,11 +557,8 @@ or the PAGER environment variable.
549
557
  # Looks up the method +name+ and adds it to +out+
550
558
 
551
559
  def add_method out, name
552
- filtered = lookup_method name
553
-
554
- method_out = method_document name, filtered
555
-
556
- out.concat method_out.parts
560
+ filtered = lookup_method name
561
+ method_document out, name, filtered
557
562
  end
558
563
 
559
564
  ##
@@ -645,18 +650,19 @@ or the PAGER environment variable.
645
650
 
646
651
  add_also_in out, also_in
647
652
 
653
+ expand_rdoc_refs_at_the_bottom(out)
648
654
  out
649
655
  end
650
656
 
651
657
  ##
652
658
  # Adds the class +comment+ to +out+.
653
659
 
654
- def class_document_comment out, comment # :nodoc:
655
- unless comment.empty? then
660
+ def class_document_comment out, document # :nodoc:
661
+ unless document.empty? then
656
662
  out << RDoc::Markup::Rule.new(1)
657
663
 
658
- if comment.merged? then
659
- parts = comment.parts
664
+ if document.merged? then
665
+ parts = document.parts
660
666
  parts = parts.zip [RDoc::Markup::BlankLine.new] * parts.length
661
667
  parts.flatten!
662
668
  parts.pop
@@ -681,7 +687,7 @@ or the PAGER environment variable.
681
687
  constants = klass.constants.sort_by { |constant| constant.name }
682
688
 
683
689
  list.items.concat constants.map { |constant|
684
- parts = constant.comment.parts if constant.comment
690
+ parts = constant.comment.parse.parts
685
691
  parts << RDoc::Markup::Paragraph.new('[not documented]') if
686
692
  parts.empty?
687
693
 
@@ -748,7 +754,7 @@ or the PAGER environment variable.
748
754
  complete_klass name, klass, selector, method, completions
749
755
  complete_method name, klass, selector, completions
750
756
 
751
- completions.sort.uniq
757
+ completions.uniq.select {|s| s.start_with? name }.sort
752
758
  end
753
759
 
754
760
  def complete_klass name, klass, selector, method, completions # :nodoc:
@@ -783,7 +789,15 @@ or the PAGER environment variable.
783
789
  completions << "#{klass}#{selector}"
784
790
  end
785
791
 
786
- completions.concat methods
792
+ methods.each do |klass_sel_method|
793
+ match = klass_sel_method.match(/^(.+)(#|\.|::)([^#.:]+)$/)
794
+ # match[2] is `::` for class method and `#` for instance method.
795
+ # To be consistent with old completion that completes `['Foo#i', 'Foo::c']` for `Foo.`,
796
+ # `.` should be a wildcard for both `#` and `::` here.
797
+ if match && match[2] == selector || selector == '.'
798
+ completions << match[1] + selector + match[3]
799
+ end
800
+ end
787
801
  end
788
802
  end
789
803
 
@@ -824,6 +838,8 @@ or the PAGER environment variable.
824
838
 
825
839
  add_method out, name
826
840
 
841
+ expand_rdoc_refs_at_the_bottom(out)
842
+
827
843
  display out
828
844
  end
829
845
 
@@ -898,7 +914,7 @@ or the PAGER environment variable.
898
914
 
899
915
  page = store.load_page page_name
900
916
 
901
- display page.comment
917
+ display page.comment.parse
902
918
  end
903
919
 
904
920
  ##
@@ -1199,7 +1215,8 @@ or the PAGER environment variable.
1199
1215
 
1200
1216
  store.load_method klass, "#{type}#{method}"
1201
1217
  rescue RDoc::Store::MissingFileError => e
1202
- comment = RDoc::Comment.new("missing documentation at #{e.file}").parse
1218
+ comment = RDoc::Comment.new("missing documentation at #{e.file}")
1219
+ comment.parse
1203
1220
 
1204
1221
  method = RDoc::AnyMethod.new nil, name
1205
1222
  method.comment = comment
@@ -1255,9 +1272,7 @@ or the PAGER environment variable.
1255
1272
  ##
1256
1273
  # Builds a RDoc::Markup::Document from +found+, +klasses+ and +includes+
1257
1274
 
1258
- def method_document name, filtered
1259
- out = RDoc::Markup::Document.new
1260
-
1275
+ def method_document out, name, filtered
1261
1276
  out << RDoc::Markup::Heading.new(1, name)
1262
1277
  out << RDoc::Markup::BlankLine.new
1263
1278
 
@@ -1361,13 +1376,13 @@ or the PAGER environment variable.
1361
1376
  # documentable items the class is added to +also_in+ instead.
1362
1377
 
1363
1378
  def render_class out, store, klass, also_in # :nodoc:
1364
- comment = klass.comment
1379
+ document = klass.comment.parse
1365
1380
  # TODO the store's cache should always return an empty Array
1366
1381
  class_methods = store.class_methods[klass.full_name] || []
1367
1382
  instance_methods = store.instance_methods[klass.full_name] || []
1368
1383
  attributes = store.attributes[klass.full_name] || []
1369
1384
 
1370
- if comment.empty? and
1385
+ if document.empty? and
1371
1386
  instance_methods.empty? and class_methods.empty? then
1372
1387
  also_in << store
1373
1388
  return
@@ -1375,7 +1390,7 @@ or the PAGER environment variable.
1375
1390
 
1376
1391
  add_from out, store
1377
1392
 
1378
- class_document_comment out, comment
1393
+ class_document_comment out, document
1379
1394
 
1380
1395
  if class_methods or instance_methods or not klass.constants.empty? then
1381
1396
  out << RDoc::Markup::Rule.new(1)
@@ -1423,16 +1438,16 @@ or the PAGER environment variable.
1423
1438
  if alias_for
1424
1439
  unless method.comment.nil? or method.comment.empty?
1425
1440
  out << RDoc::Markup::BlankLine.new
1426
- out << method.comment
1441
+ out << method.comment.parse
1427
1442
  end
1428
1443
  out << RDoc::Markup::BlankLine.new
1429
1444
  out << RDoc::Markup::Paragraph.new("(This method is an alias for #{alias_for.full_name}.)")
1430
1445
  out << RDoc::Markup::BlankLine.new
1431
- out << alias_for.comment
1446
+ out << alias_for.comment.parse
1432
1447
  out << RDoc::Markup::BlankLine.new
1433
1448
  else
1434
1449
  out << RDoc::Markup::BlankLine.new
1435
- out << method.comment
1450
+ out << method.comment.parse
1436
1451
  out << RDoc::Markup::BlankLine.new
1437
1452
  end
1438
1453
  end
@@ -1514,4 +1529,38 @@ or the PAGER environment variable.
1514
1529
  server.start
1515
1530
  end
1516
1531
 
1532
+ RDOC_REFS_REGEXP = /\[rdoc-ref:([\w.]+)(@.*)?\]/
1533
+
1534
+ def expand_rdoc_refs_at_the_bottom(out)
1535
+ return unless @expand_refs
1536
+
1537
+ extracted_rdoc_refs = []
1538
+
1539
+ out.each do |part|
1540
+ content = if part.respond_to?(:text)
1541
+ part.text
1542
+ else
1543
+ next
1544
+ end
1545
+
1546
+ rdoc_refs = content.scan(RDOC_REFS_REGEXP).uniq.map do |file_name, _anchor|
1547
+ file_name
1548
+ end
1549
+
1550
+ extracted_rdoc_refs.concat(rdoc_refs)
1551
+ end
1552
+
1553
+ found_pages = extracted_rdoc_refs.map do |ref|
1554
+ begin
1555
+ @stores.first.load_page(ref)
1556
+ rescue RDoc::Store::MissingFileError
1557
+ end
1558
+ end.compact
1559
+
1560
+ found_pages.each do |page|
1561
+ out << RDoc::Markup::Heading.new(4, "Expanded from #{page.full_name}")
1562
+ out << RDoc::Markup::BlankLine.new
1563
+ out << page.comment.parse
1564
+ end
1565
+ end
1517
1566
  end
@@ -3,13 +3,19 @@ require 'rubygems/user_interaction'
3
3
  require 'fileutils'
4
4
  require_relative '../rdoc'
5
5
 
6
- ##
7
- # Gem::RDoc provides methods to generate RDoc and ri data for installed gems
8
- # upon gem installation.
6
+ # We define the following two similar name classes in this file:
9
7
  #
10
- # This file is automatically required by RubyGems 1.9 and newer.
8
+ # - RDoc::RubyGemsHook
9
+ # - RDoc::RubygemsHook
10
+ #
11
+ # RDoc::RubyGemsHook is the main class that has real logic.
12
+ #
13
+ # RDoc::RubygemsHook is a class that is only for
14
+ # compatibility. RDoc::RubygemsHook is used by RubyGems directly. We
15
+ # can remove this when all maintained RubyGems remove
16
+ # `rubygems/rdoc.rb`.
11
17
 
12
- class RDoc::RubygemsHook
18
+ class RDoc::RubyGemsHook
13
19
 
14
20
  include Gem::UserInteraction
15
21
  extend Gem::UserInteraction
@@ -45,7 +51,7 @@ class RDoc::RubygemsHook
45
51
  # Post installs hook that generates documentation for each specification in
46
52
  # +specs+
47
53
 
48
- def self.generation_hook installer, specs
54
+ def self.generate installer, specs
49
55
  start = Time.now
50
56
  types = installer.document
51
57
 
@@ -64,6 +70,10 @@ class RDoc::RubygemsHook
64
70
  say "Done installing documentation for #{names} after #{duration} seconds"
65
71
  end
66
72
 
73
+ def self.remove uninstaller
74
+ new(uninstaller.spec).remove
75
+ end
76
+
67
77
  ##
68
78
  # Loads the RDoc generator
69
79
 
@@ -171,20 +181,14 @@ class RDoc::RubygemsHook
171
181
  options = ::RDoc::Options.new
172
182
  options.default_title = "#{@spec.full_name} Documentation"
173
183
  options.parse args
184
+ options.quiet = !Gem.configuration.really_verbose
185
+ options.finish
174
186
  end
175
187
 
176
- options.quiet = !Gem.configuration.really_verbose
177
-
178
188
  @rdoc = new_rdoc
179
189
  @rdoc.options = options
180
190
 
181
- store = RDoc::Store.new
182
- store.encoding = options.encoding
183
- store.dry_run = options.dry_run
184
- store.main = options.main_page
185
- store.title = options.title
186
-
187
- @rdoc.store = store
191
+ @rdoc.store = RDoc::Store.new(options)
188
192
 
189
193
  say "Parsing documentation for #{@spec.full_name}"
190
194
 
@@ -246,3 +250,75 @@ class RDoc::RubygemsHook
246
250
  end
247
251
 
248
252
  end
253
+
254
+ # This class is referenced by RubyGems to create documents.
255
+ # All implementations are moved to the above RubyGemsHook.
256
+ #
257
+ # This class does nothing when this RDoc is installed as a normal gem
258
+ # or a bundled gem.
259
+ #
260
+ # This class does generate/remove documents for compatibility when
261
+ # this RDoc is installed as a default gem.
262
+ #
263
+ # We can remove this when all maintained RubyGems remove
264
+ # `rubygems/rdoc.rb`.
265
+ module RDoc
266
+ class RubygemsHook
267
+
268
+ attr_accessor :generate_rdoc, :generate_ri, :force
269
+
270
+ def self.default_gem?
271
+ !File.exist?(File.join(__dir__, "..", "rubygems_plugin.rb"))
272
+ end
273
+
274
+ def initialize(spec, generate_rdoc = false, generate_ri = true)
275
+ @spec = spec
276
+ @generate_rdoc = generate_rdoc
277
+ @generate_ri = generate_ri
278
+ @force = false
279
+ end
280
+
281
+ def generate
282
+ # Do nothing if this is NOT a default gem.
283
+ return unless self.class.default_gem?
284
+
285
+ # Generate document for compatibility if this is a default gem.
286
+ hook = RubyGemsHook.new(@spec, @generate_rdoc, @generate_ri)
287
+ hook.force = @force
288
+ hook.generate
289
+ end
290
+
291
+ def remove
292
+ # Do nothing if this is NOT a default gem.
293
+ return unless self.class.default_gem?
294
+
295
+ # Remove generated document for compatibility if this is a
296
+ # default gem.
297
+ RubyGemsHook.new(@spec).remove
298
+ end
299
+
300
+ def self.generation_hook installer, specs
301
+ # Do nothing if this is NOT a default gem.
302
+ return unless default_gem?
303
+
304
+ # Generate document for compatibility if this is a default gem.
305
+ RubyGemsHook.generate(installer, specs)
306
+ end
307
+
308
+ def self.load_rdoc
309
+ RubyGemsHook.load_rdoc
310
+ end
311
+
312
+ def self.rdoc_version
313
+ RubyGemsHook.rdoc_version
314
+ end
315
+
316
+ def rdoc_installed?
317
+ RubyGemsHook.new(@spec).rdoc_installed?
318
+ end
319
+
320
+ def ri_installed?
321
+ RubyGemsHook.new(@spec).ri_installed?
322
+ end
323
+ end
324
+ end
data/lib/rdoc/servlet.rb CHANGED
@@ -133,7 +133,7 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
133
133
  show_documentation req, res
134
134
  end
135
135
  rescue WEBrick::HTTPStatus::NotFound => e
136
- generator = generator_for RDoc::Store.new
136
+ generator = generator_for RDoc::Store.new(@options)
137
137
 
138
138
  not_found generator, req, res, e.message
139
139
  rescue WEBrick::HTTPStatus::Status
@@ -247,6 +247,7 @@ version. If you're viewing Ruby's documentation, include the version of ruby.
247
247
  generator = RDoc::Generator::Darkfish.new store, @options
248
248
  generator.file_output = false
249
249
  generator.asset_rel_path = '..'
250
+ generator.setup
250
251
 
251
252
  rdoc = RDoc::RDoc.new
252
253
  rdoc.store = store
@@ -290,7 +291,7 @@ version. If you're viewing Ruby's documentation, include the version of ruby.
290
291
  def installed_docs
291
292
  extra_counter = 0
292
293
  ri_paths.map do |path, type|
293
- store = RDoc::Store.new path, type
294
+ store = RDoc::Store.new(@options, path: path, type: type)
294
295
  exists = File.exist? store.cache_path
295
296
 
296
297
  case type
@@ -419,15 +420,15 @@ version. If you're viewing Ruby's documentation, include the version of ruby.
419
420
  def store_for source_name
420
421
  case source_name
421
422
  when 'home' then
422
- RDoc::Store.new RDoc::RI::Paths.home_dir, :home
423
+ RDoc::Store.new(@options, path: RDoc::RI::Paths.home_dir, type: :home)
423
424
  when 'ruby' then
424
- RDoc::Store.new RDoc::RI::Paths.system_dir, :system
425
+ RDoc::Store.new(@options, path: RDoc::RI::Paths.system_dir, type: :system)
425
426
  when 'site' then
426
- RDoc::Store.new RDoc::RI::Paths.site_dir, :site
427
+ RDoc::Store.new(@options, path: RDoc::RI::Paths.site_dir, type: :site)
427
428
  when /\Aextra-(\d+)\z/ then
428
429
  index = $1.to_i - 1
429
430
  ri_dir = installed_docs[index][4]
430
- RDoc::Store.new ri_dir, :extra
431
+ RDoc::Store.new(@options, path: ri_dir, type: :extra)
431
432
  else
432
433
  ri_dir, type = ri_paths.find do |dir, dir_type|
433
434
  next unless dir_type == :gem
@@ -438,7 +439,7 @@ version. If you're viewing Ruby's documentation, include the version of ruby.
438
439
  raise WEBrick::HTTPStatus::NotFound,
439
440
  "Could not find gem \"#{ERB::Util.html_escape(source_name)}\". Are you sure you installed it?" unless ri_dir
440
441
 
441
- store = RDoc::Store.new ri_dir, type
442
+ store = RDoc::Store.new(@options, path: ri_dir, type: type)
442
443
 
443
444
  return store if File.exist? store.cache_path
444
445