rdoc 7.1.0 → 8.0.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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -4
  3. data/LICENSE.rdoc +4 -0
  4. data/README.md +43 -2
  5. data/doc/markup_reference/markdown.md +104 -3
  6. data/lib/rdoc/code_object/alias.rb +2 -8
  7. data/lib/rdoc/code_object/any_method.rb +11 -6
  8. data/lib/rdoc/code_object/attr.rb +12 -6
  9. data/lib/rdoc/code_object/class_module.rb +62 -32
  10. data/lib/rdoc/code_object/constant.rb +29 -3
  11. data/lib/rdoc/code_object/context/section.rb +30 -43
  12. data/lib/rdoc/code_object/context.rb +53 -37
  13. data/lib/rdoc/code_object/method_attr.rb +9 -15
  14. data/lib/rdoc/code_object/mixin.rb +3 -0
  15. data/lib/rdoc/code_object/top_level.rb +11 -3
  16. data/lib/rdoc/code_object.rb +2 -4
  17. data/lib/rdoc/comment.rb +1 -66
  18. data/lib/rdoc/cross_reference.rb +8 -30
  19. data/lib/rdoc/encoding.rb +3 -3
  20. data/lib/rdoc/generator/aliki.rb +17 -0
  21. data/lib/rdoc/generator/darkfish.rb +12 -6
  22. data/lib/rdoc/generator/json_index.rb +2 -2
  23. data/lib/rdoc/generator/markup.rb +56 -31
  24. data/lib/rdoc/generator/template/aliki/DESIGN.md +536 -0
  25. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  26. data/lib/rdoc/generator/template/aliki/_head.rhtml +6 -1
  27. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  28. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  29. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  30. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +2 -2
  31. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  32. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  33. data/lib/rdoc/generator/template/aliki/class.rhtml +61 -51
  34. data/lib/rdoc/generator/template/aliki/css/rdoc.css +365 -147
  35. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  36. data/lib/rdoc/generator/template/aliki/js/aliki.js +28 -20
  37. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  38. data/lib/rdoc/generator/template/aliki/js/search_controller.js +1 -1
  39. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  40. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  41. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  42. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  43. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  48. data/lib/rdoc/generator/template/darkfish/class.rhtml +18 -21
  49. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +0 -1
  50. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  51. data/lib/rdoc/i18n/text.rb +3 -3
  52. data/lib/rdoc/markdown.kpeg +36 -17
  53. data/lib/rdoc/markdown.rb +324 -125
  54. data/lib/rdoc/markup/document.rb +2 -2
  55. data/lib/rdoc/markup/formatter.rb +128 -115
  56. data/lib/rdoc/markup/heading.rb +3 -6
  57. data/lib/rdoc/markup/indented_paragraph.rb +1 -1
  58. data/lib/rdoc/markup/inline_parser.rb +312 -0
  59. data/lib/rdoc/markup/list.rb +2 -2
  60. data/lib/rdoc/markup/list_item.rb +2 -2
  61. data/lib/rdoc/markup/parser.rb +1 -1
  62. data/lib/rdoc/markup/pre_process.rb +0 -25
  63. data/lib/rdoc/markup/to_ansi.rb +52 -5
  64. data/lib/rdoc/markup/to_bs.rb +23 -43
  65. data/lib/rdoc/markup/to_html.rb +279 -226
  66. data/lib/rdoc/markup/to_html_crossref.rb +122 -136
  67. data/lib/rdoc/markup/to_html_snippet.rb +65 -65
  68. data/lib/rdoc/markup/to_joined_paragraph.rb +0 -5
  69. data/lib/rdoc/markup/to_label.rb +22 -23
  70. data/lib/rdoc/markup/to_markdown.rb +62 -38
  71. data/lib/rdoc/markup/to_rdoc.rb +88 -28
  72. data/lib/rdoc/markup/to_table_of_contents.rb +1 -1
  73. data/lib/rdoc/markup/to_test.rb +9 -1
  74. data/lib/rdoc/markup/to_tt_only.rb +10 -23
  75. data/lib/rdoc/markup/verbatim.rb +1 -1
  76. data/lib/rdoc/markup.rb +8 -30
  77. data/lib/rdoc/options.rb +36 -51
  78. data/lib/rdoc/parser/c.rb +7 -6
  79. data/lib/rdoc/parser/changelog.rb +21 -0
  80. data/lib/rdoc/parser/rbs.rb +275 -0
  81. data/lib/rdoc/parser/ruby.rb +955 -2067
  82. data/lib/rdoc/parser/ruby_colorizer.rb +253 -0
  83. data/lib/rdoc/parser.rb +3 -2
  84. data/lib/rdoc/rbs_helper.rb +186 -0
  85. data/lib/rdoc/rdoc.rb +196 -24
  86. data/lib/rdoc/ri/driver.rb +8 -2
  87. data/lib/rdoc/ri/paths.rb +1 -1
  88. data/lib/rdoc/{servlet.rb → ri/servlet.rb} +5 -5
  89. data/lib/rdoc/ri.rb +4 -3
  90. data/lib/rdoc/rubygems_hook.rb +11 -11
  91. data/lib/rdoc/server.rb +460 -0
  92. data/lib/rdoc/stats.rb +147 -124
  93. data/lib/rdoc/store.rb +212 -4
  94. data/lib/rdoc/task.rb +16 -15
  95. data/lib/rdoc/text.rb +24 -117
  96. data/lib/rdoc/token_stream.rb +11 -33
  97. data/lib/rdoc/version.rb +1 -1
  98. data/lib/rdoc.rb +35 -7
  99. data/lib/rubygems_plugin.rb +2 -11
  100. data/rdoc-logo.svg +43 -0
  101. data/rdoc.gemspec +6 -4
  102. metadata +37 -23
  103. data/lib/rdoc/code_object/anon_class.rb +0 -10
  104. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  105. data/lib/rdoc/code_object/meta_method.rb +0 -6
  106. data/lib/rdoc/markup/attr_changer.rb +0 -22
  107. data/lib/rdoc/markup/attr_span.rb +0 -35
  108. data/lib/rdoc/markup/attribute_manager.rb +0 -432
  109. data/lib/rdoc/markup/attributes.rb +0 -70
  110. data/lib/rdoc/markup/regexp_handling.rb +0 -40
  111. data/lib/rdoc/parser/prism_ruby.rb +0 -1100
  112. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  113. data/lib/rdoc/parser/ruby_tools.rb +0 -163
@@ -17,11 +17,6 @@ class RDoc::Context::Section
17
17
 
18
18
  MARSHAL_VERSION = 0 # :nodoc:
19
19
 
20
- ##
21
- # Section comment
22
-
23
- attr_reader :comment
24
-
25
20
  ##
26
21
  # Section comments
27
22
 
@@ -37,12 +32,18 @@ class RDoc::Context::Section
37
32
 
38
33
  attr_reader :title
39
34
 
35
+ ##
36
+ # The RDoc::Store for this object.
37
+
38
+ attr_reader :store
39
+
40
40
  ##
41
41
  # Creates a new section with +title+ and +comment+
42
42
 
43
- def initialize(parent, title, comment)
43
+ def initialize(parent, title, comment, store = nil)
44
44
  @parent = parent
45
45
  @title = title ? title.strip : title
46
+ @store = store
46
47
 
47
48
  @comments = []
48
49
 
@@ -62,10 +63,10 @@ class RDoc::Context::Section
62
63
  # Adds +comment+ to this section
63
64
 
64
65
  def add_comment(comment)
65
- comments = Array(comment)
66
- comments.each do |c|
67
- extracted_comment = extract_comment(c)
68
- @comments << extracted_comment unless extracted_comment.empty?
66
+ Array(comment).each do |c|
67
+ next if c.nil?
68
+ raise TypeError, "unknown comment #{c.inspect}" unless RDoc::Comment === c
69
+ @comments << c unless c.empty?
69
70
  end
70
71
  end
71
72
 
@@ -97,37 +98,6 @@ class RDoc::Context::Section
97
98
  CGI.escape(title).gsub('%', '-').sub(/^-/, '')
98
99
  end
99
100
 
100
- ##
101
- # Extracts the comment for this section from the original comment block.
102
- # If the first line contains :section:, strip it and use the rest.
103
- # Otherwise remove lines up to the line containing :section:, and look
104
- # for those lines again at the end and remove them. This lets us write
105
- #
106
- # # :section: The title
107
- # # The body
108
-
109
- def extract_comment(comment)
110
- case comment
111
- when nil
112
- RDoc::Comment.new ''
113
- when RDoc::Comment then
114
- if comment.text =~ /^#[ \t]*:section:.*\n/ then
115
- start = $`
116
- rest = $'
117
-
118
- comment.text = if start.empty? then
119
- rest
120
- else
121
- rest.sub(/#{start.chomp}\Z/, '')
122
- end
123
- end
124
-
125
- comment
126
- else
127
- raise TypeError, "unknown comment #{comment.inspect}"
128
- end
129
- end
130
-
131
101
  def inspect # :nodoc:
132
102
  "#<%s:0x%x %p>" % [self.class, object_id, title]
133
103
  end
@@ -151,7 +121,7 @@ class RDoc::Context::Section
151
121
  [
152
122
  MARSHAL_VERSION,
153
123
  @title,
154
- parse,
124
+ to_document,
155
125
  ]
156
126
  end
157
127
 
@@ -169,7 +139,7 @@ class RDoc::Context::Section
169
139
  # Parses +comment_location+ into an RDoc::Markup::Document composed of
170
140
  # multiple RDoc::Markup::Documents with their file set.
171
141
 
172
- def parse
142
+ def to_document
173
143
  RDoc::Markup::Document.new(*@comments.map(&:parse))
174
144
  end
175
145
 
@@ -182,6 +152,23 @@ class RDoc::Context::Section
182
152
  @title || 'Top Section'
183
153
  end
184
154
 
155
+ ##
156
+ # Section comment
157
+
158
+ def comment
159
+ return nil if @comments.empty?
160
+ RDoc::Comment.from_document(to_document)
161
+ end
162
+
163
+ def description
164
+ return '' if @comments.empty?
165
+ markup comment
166
+ end
167
+
168
+ def language
169
+ @comments.first&.language
170
+ end
171
+
185
172
  ##
186
173
  # Removes a comment from this section if it is from the same file as
187
174
  # +comment+
@@ -313,13 +313,7 @@ class RDoc::Context < RDoc::CodeObject
313
313
  @store.modules_hash[given_name]
314
314
  return enclosing if enclosing
315
315
  # not found: create the parent(s)
316
- names = ename.split('::')
317
- enclosing = self
318
- names.each do |n|
319
- enclosing = enclosing.classes_hash[n] ||
320
- enclosing.modules_hash[n] ||
321
- enclosing.add_module(RDoc::NormalModule, n)
322
- end
316
+ enclosing = find_or_create_namespace_path ename
323
317
  end
324
318
  else
325
319
  name = full_name
@@ -439,6 +433,7 @@ class RDoc::Context < RDoc::CodeObject
439
433
  known.value = constant.value if
440
434
  known.value.nil? or known.value.strip.empty?
441
435
 
436
+ constant.parent = self
442
437
  known.is_alias_for ||= constant.is_alias_for
443
438
  else
444
439
  @constants_hash[constant.name] = constant
@@ -499,11 +494,44 @@ class RDoc::Context < RDoc::CodeObject
499
494
  method
500
495
  end
501
496
 
497
+ ##
498
+ # Returns the owner context and local name for +constant_path+, creating
499
+ # missing namespace modules. A leading +::+ resolves from the top-level.
500
+ # This only resolves explicit context-tree paths; RDoc::Parser::Ruby has
501
+ # parser-local lexical helpers for Ruby's nesting-dependent lookup.
502
+
503
+ def find_or_create_constant_owner_for_path(constant_path) # :nodoc:
504
+ constant_path = constant_path.to_s
505
+ owner = constant_path.start_with?('::') ? top_level : self
506
+ constant_path = constant_path.delete_prefix('::')
507
+
508
+ owner_path, separator, name = constant_path.rpartition('::')
509
+ owner = owner.find_or_create_namespace_path owner_path unless separator.empty?
510
+
511
+ [owner, name]
512
+ end
513
+
514
+ ##
515
+ # Finds or creates the module namespace path under this context.
516
+
517
+ def find_or_create_namespace_path(path) # :nodoc:
518
+ path.to_s.split('::').inject(self) do |owner, name|
519
+ owner.classes_hash[name] ||
520
+ owner.modules_hash[name] ||
521
+ owner.add_module(RDoc::NormalModule, name)
522
+ end
523
+ end
524
+
502
525
  ##
503
526
  # Adds a module named +name+. If RDoc already knows +name+ is a class then
504
527
  # that class is returned instead. See also #add_class.
505
528
 
506
529
  def add_module(class_type, name)
530
+ if name.to_s.include?('::')
531
+ owner, name = find_or_create_constant_owner_for_path name
532
+ return owner.add_module class_type, name unless owner == self
533
+ end
534
+
507
535
  mod = @classes[name] || @modules[name]
508
536
  return mod if mod
509
537
 
@@ -543,6 +571,7 @@ class RDoc::Context < RDoc::CodeObject
543
571
  new_to = from.dup
544
572
  new_to.name = to.name
545
573
  new_to.full_name = nil
574
+ new_to.is_alias_for = from
546
575
 
547
576
  if new_to.module? then
548
577
  @store.modules_hash[to_full_name] = new_to
@@ -587,7 +616,7 @@ class RDoc::Context < RDoc::CodeObject
587
616
  if section = @sections[title] then
588
617
  section.add_comment comment if comment
589
618
  else
590
- section = Section.new self, title, comment
619
+ section = Section.new self, title, comment, @store
591
620
  @sections[title] = section
592
621
  end
593
622
 
@@ -639,18 +668,11 @@ class RDoc::Context < RDoc::CodeObject
639
668
  end
640
669
  end
641
670
 
642
- ##
643
- # Class attributes
644
-
645
- def class_attributes
646
- @class_attributes ||= attributes.select { |a| a.singleton }
647
- end
648
-
649
671
  ##
650
672
  # Class methods
651
673
 
652
674
  def class_method_list
653
- @class_method_list ||= method_list.select { |a| a.singleton }
675
+ method_list.select { |a| a.singleton }
654
676
  end
655
677
 
656
678
  ##
@@ -785,7 +807,10 @@ class RDoc::Context < RDoc::CodeObject
785
807
  end
786
808
 
787
809
  ##
788
- # Find a module at a higher scope
810
+ # Tries to find a module at a higher scope.
811
+ # But parent is not always a higher module nesting scope, so the result is not correct.
812
+ # Parent chain can only represent last-opened nesting, and may be broken in some cases.
813
+ # The Ruby parser does not represent module nesting with the parent chain.
789
814
 
790
815
  def find_enclosing_module_named(name)
791
816
  parent && parent.find_module_named(name)
@@ -860,15 +885,23 @@ class RDoc::Context < RDoc::CodeObject
860
885
  end
861
886
 
862
887
  ##
863
- # Find a module with +name+ using ruby's scoping rules
888
+ # Find a module with +name+ trying to using ruby's scoping rules.
889
+ # find_enclosing_module_named cannot use ruby's scoping so the result is not correct.
864
890
 
865
891
  def find_module_named(name)
866
- res = @modules[name] || @classes[name]
892
+ res = get_module_named(name)
867
893
  return res if res
868
894
  return self if self.name == name
869
895
  find_enclosing_module_named name
870
896
  end
871
897
 
898
+ # Get a module named +name+ in this context
899
+ # Don't look up for higher module nesting scopes. RDoc::Context doesn't have that information.
900
+
901
+ def get_module_named(name)
902
+ @modules[name] || @classes[name]
903
+ end
904
+
872
905
  ##
873
906
  # Look up +symbol+, first as a module, then as a local symbol.
874
907
 
@@ -939,28 +972,11 @@ class RDoc::Context < RDoc::CodeObject
939
972
  File.join(*path.compact) + '.html'
940
973
  end
941
974
 
942
- ##
943
- # Instance attributes
944
-
945
- def instance_attributes
946
- @instance_attributes ||= attributes.reject { |a| a.singleton }
947
- end
948
-
949
975
  ##
950
976
  # Instance methods
951
977
 
952
978
  def instance_methods
953
- @instance_methods ||= method_list.reject { |a| a.singleton }
954
- end
955
-
956
- ##
957
- # Instance methods
958
- #--
959
- # TODO remove this later
960
-
961
- def instance_method_list
962
- warn '#instance_method_list is obsoleted, please use #instance_methods'
963
- @instance_methods ||= method_list.reject { |a| a.singleton }
979
+ method_list.reject { |a| a.singleton }
964
980
  end
965
981
 
966
982
  ##
@@ -21,11 +21,6 @@ class RDoc::MethodAttr < RDoc::CodeObject
21
21
 
22
22
  attr_accessor :singleton
23
23
 
24
- ##
25
- # Source file token stream
26
-
27
- attr_reader :text
28
-
29
24
  ##
30
25
  # Array of other names for this method/attribute
31
26
 
@@ -58,21 +53,26 @@ class RDoc::MethodAttr < RDoc::CodeObject
58
53
 
59
54
  attr_accessor :call_seq
60
55
 
56
+ ##
57
+ # RBS type signature lines from inline annotations or loaded .rbs files.
58
+ # Each entry is one overload or type expression.
59
+
60
+ attr_accessor :type_signature_lines
61
+
61
62
  ##
62
63
  # The call_seq or the param_seq with method name, if there is no call_seq.
63
64
 
64
65
  attr_reader :arglists
65
66
 
66
67
  ##
67
- # Creates a new MethodAttr from token stream +text+ and method or attribute
68
+ # Creates a new MethodAttr with method or attribute
68
69
  # name +name+.
69
70
  #
70
71
  # Usually this is called by super from a subclass.
71
72
 
72
- def initialize(text, name, singleton: false)
73
+ def initialize(name, singleton: false)
73
74
  super()
74
75
 
75
- @text = text
76
76
  @name = name
77
77
 
78
78
  @aliases = []
@@ -86,6 +86,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
86
86
  @block_params = nil
87
87
  @call_seq = nil
88
88
  @params = nil
89
+ @type_signature_lines = nil
89
90
  end
90
91
 
91
92
  ##
@@ -356,13 +357,6 @@ class RDoc::MethodAttr < RDoc::CodeObject
356
357
  q.text alias_for
357
358
  end
358
359
 
359
- if text then
360
- q.breakable
361
- q.text "text:"
362
- q.breakable
363
- q.pp @text
364
- end
365
-
366
360
  unless comment.empty? then
367
361
  q.breakable
368
362
  q.text "comment:"
@@ -71,6 +71,9 @@ class RDoc::Mixin < RDoc::CodeObject
71
71
  # lookup behavior.
72
72
  #
73
73
  # As of the beginning of October, 2011, no gem includes nonexistent modules.
74
+ #
75
+ # The Ruby parser passes an already-resolved full-path +name+, so most of this
76
+ # logic only runs for the C parser, which passes the unresolved local name.
74
77
 
75
78
  def module
76
79
  return @module if @module
@@ -66,7 +66,7 @@ class RDoc::TopLevel < RDoc::Context
66
66
 
67
67
  def parser=(val)
68
68
  @parser = val
69
- @store.update_parser_of_file(absolute_name, val) if @store
69
+ @store&.cache_text_file(relative_name)
70
70
  @parser
71
71
  end
72
72
 
@@ -149,6 +149,8 @@ class RDoc::TopLevel < RDoc::Context
149
149
  find_class_or_module(name)
150
150
  end
151
151
 
152
+ alias get_module_named find_module_named
153
+
152
154
  ##
153
155
  # Returns the relative name of this file
154
156
 
@@ -219,9 +221,15 @@ class RDoc::TopLevel < RDoc::Context
219
221
  # Path to this file for use with HTML generator output.
220
222
 
221
223
  def path
224
+ base = if options.main_page == full_name
225
+ 'index.html'
226
+ else
227
+ http_url
228
+ end
229
+
222
230
  prefix = options.file_path_prefix
223
- return http_url unless prefix
224
- File.join(prefix, http_url)
231
+ return base unless prefix
232
+ File.join(prefix, base)
225
233
  end
226
234
 
227
235
  def pretty_print(q) # :nodoc:
@@ -10,15 +10,12 @@
10
10
  # * RDoc::Context
11
11
  # * RDoc::TopLevel
12
12
  # * RDoc::ClassModule
13
- # * RDoc::AnonClass (never used so far)
14
13
  # * RDoc::NormalClass
15
14
  # * RDoc::NormalModule
16
15
  # * RDoc::SingleClass
17
16
  # * RDoc::MethodAttr
18
17
  # * RDoc::Attr
19
18
  # * RDoc::AnyMethod
20
- # * RDoc::GhostMethod
21
- # * RDoc::MetaMethod
22
19
  # * RDoc::Alias
23
20
  # * RDoc::Constant
24
21
  # * RDoc::Require
@@ -277,7 +274,8 @@ class RDoc::CodeObject
277
274
  # The options instance from the store this CodeObject is attached to, or a
278
275
  # default options instance if the CodeObject is not attached.
279
276
  #
280
- # This is used by Text#snippet
277
+ # Used by: store= (visibility check), ClassModule#path, TopLevel#path,
278
+ # ClassModule#embed_mixins
281
279
 
282
280
  def options
283
281
  @store&.options || RDoc::Options.new
data/lib/rdoc/comment.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # Each comment may have a different markup format set by #format=. By default
7
7
  # 'rdoc' is used. The :markup: directive tells RDoc which format to use.
8
8
  #
9
- # See RDoc::MarkupReference@Directive+for+Specifying+RDoc+Source+Format.
9
+ # See {RDoc Markup Reference}[rdoc-ref:doc/markup_reference/rdoc.rdoc@Directive+for+Specifying+RDoc+Source+Format].
10
10
 
11
11
 
12
12
  class RDoc::Comment
@@ -76,49 +76,6 @@ class RDoc::Comment
76
76
  other.text == @text and other.location == @location
77
77
  end
78
78
 
79
- ##
80
- # Look for a 'call-seq' in the comment to override the normal parameter
81
- # handling. The :call-seq: is indented from the baseline. All lines of the
82
- # same indentation level and prefix are consumed.
83
- #
84
- # For example, all of the following will be used as the :call-seq:
85
- #
86
- # # :call-seq:
87
- # # ARGF.readlines(sep=$/) -> array
88
- # # ARGF.readlines(limit) -> array
89
- # # ARGF.readlines(sep, limit) -> array
90
- # #
91
- # # ARGF.to_a(sep=$/) -> array
92
- # # ARGF.to_a(limit) -> array
93
- # # ARGF.to_a(sep, limit) -> array
94
-
95
- def extract_call_seq
96
- # we must handle situations like the above followed by an unindented first
97
- # comment. The difficulty is to make sure not to match lines starting
98
- # with ARGF at the same indent, but that are after the first description
99
- # paragraph.
100
- if /^(?<S> ((?!\n)\s)*+ (?# whitespaces except newline))
101
- :?call-seq:
102
- (?<B> \g<S>(?<N>\n|\z) (?# trailing spaces))?
103
- (?<seq>
104
- (\g<S>(?!\w)\S.*\g<N>)*
105
- (?>
106
- (?<H> \g<S>\w+ (?# ' # ARGF' in the example above))
107
- .*\g<N>)?
108
- (\g<S>\S.*\g<N> (?# other non-blank line))*+
109
- (\g<B>+(\k<H>.*\g<N> (?# ARGF.to_a lines))++)*+
110
- )
111
- (?m:^\s*$|\z)
112
- /x =~ @text
113
- seq = $~[:seq]
114
-
115
- all_start, all_stop = $~.offset(0)
116
- @text.slice! all_start...all_stop
117
-
118
- seq.gsub!(/^\s*/, '')
119
- end
120
- end
121
-
122
79
  ##
123
80
  # A comment is empty if its text String is empty.
124
81
 
@@ -187,28 +144,6 @@ class RDoc::Comment
187
144
  @document
188
145
  end
189
146
 
190
- ##
191
- # Removes private sections from this comment. Private sections are flush to
192
- # the comment marker and start with <tt>--</tt> and end with <tt>++</tt>.
193
- # For C-style comments, a private marker may not start at the opening of the
194
- # comment.
195
- #
196
- # /*
197
- # *--
198
- # * private
199
- # *++
200
- # * public
201
- # */
202
-
203
- def remove_private
204
- # Workaround for gsub encoding for Ruby 1.9.2 and earlier
205
- empty = ''
206
- empty = RDoc::Encoding.change_encoding empty, @text.encoding
207
-
208
- @text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty)
209
- @text = @text.sub(%r%^\s*[#*]?--.*%m, '')
210
- end
211
-
212
147
  ##
213
148
  # Replaces this comment's text with +text+ and resets the parsed document.
214
149
  #
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'markup/attribute_manager' # for PROTECT_ATTR
4
-
5
3
  ##
6
4
  # RDoc::CrossReference is a reusable way to create cross references for names.
7
5
 
@@ -33,7 +31,7 @@ class RDoc::CrossReference
33
31
  # See CLASS_REGEXP_STR
34
32
 
35
33
  METHOD_REGEXP_STR = /(
36
- (?!\d)[\w#{RDoc::Markup::AttributeManager::PROTECT_ATTR}]+[!?=]?|
34
+ (?!\d)[\w]+[!?=]?|
37
35
  %|=(?:==?|~)|![=~]|\[\]=?|<(?:<|=>?)?|>[>=]?|[-+!]@?|\*\*?|[\/%\`|&^~]
38
36
  )#{METHOD_ARGS_REGEXP_STR}/.source.delete("\n ").freeze
39
37
 
@@ -192,19 +190,13 @@ class RDoc::CrossReference
192
190
  ##
193
191
  # Returns a reference to +name+.
194
192
  #
195
- # If the reference is found and +name+ is not documented +text+ will be
196
- # returned. If +name+ is escaped +name+ is returned. If +name+ is not
197
- # found +text+ is returned.
193
+ # If the reference is found and +name+ is not documented +nil+ will be
194
+ # returned. If +name+ is not found +nil+ is returned.
198
195
 
199
- def resolve(name, text)
196
+ def resolve(name)
200
197
  return @seen[name] if @seen.include? name
201
198
 
202
- ref = case name
203
- when /^\\(#{CLASS_REGEXP_STR})$/o then
204
- @context.find_symbol $1
205
- else
206
- @context.find_symbol name
207
- end
199
+ ref = @context.find_symbol name
208
200
 
209
201
  ref = resolve_local_symbol name unless ref
210
202
 
@@ -213,25 +205,11 @@ class RDoc::CrossReference
213
205
 
214
206
  ref = nil if RDoc::Alias === ref # external alias, can't link to it
215
207
 
216
- out = if name == '\\' then
217
- name
218
- elsif name =~ /^\\/ then
219
- # we remove the \ only in front of what we know:
220
- # other backslashes are treated later, only outside of <tt>
221
- ref ? $' : name
222
- elsif ref then
223
- if ref.display? then
224
- ref
225
- else
226
- text
227
- end
228
- else
229
- text
230
- end
208
+ ref = nil unless ref&.display?
231
209
 
232
- @seen[name] = out
210
+ @seen[name] = ref
233
211
 
234
- out
212
+ ref
235
213
  end
236
214
 
237
215
  end
data/lib/rdoc/encoding.rb CHANGED
@@ -7,13 +7,13 @@
7
7
 
8
8
  module RDoc::Encoding
9
9
 
10
- HEADER_REGEXP = /^
10
+ HEADER_REGEXP = /\A
11
11
  (?:
12
- \A\#!.*\n
12
+ \#!.*\n
13
13
  |
14
14
  ^\#\s+frozen[-_]string[-_]literal[=:].+\n
15
15
  |
16
- ^\#[^\n]+\b(?:en)?coding[=:]\s*(?<name>[^\s;]+).*\n
16
+ ^\#\s*(?:-\*-\s*(?:[^;\n]*;\s*)*)?(?:en)?coding[=:]\s*(?<name>[^:\s;]+).*\n
17
17
  |
18
18
  <\?xml[^?]*encoding=(?<quote>["'])(?<name>.*?)\k<quote>.*\n
19
19
  )+
@@ -9,6 +9,8 @@ require 'uri'
9
9
  #
10
10
 
11
11
  class RDoc::Generator::Aliki < RDoc::Generator::Darkfish
12
+ DESCRIPTION = 'HTML generator, written by Stan Lo'
13
+
12
14
  RDoc::RDoc.add_generator self
13
15
 
14
16
  def initialize(store, options)
@@ -117,6 +119,21 @@ class RDoc::Generator::Aliki < RDoc::Generator::Darkfish
117
119
  File.write search_index_path, "var search_data = #{JSON.generate(data)};"
118
120
  end
119
121
 
122
+ ##
123
+ # Returns the type signature of +method_attr+ as HTML with linked type names.
124
+ # Returns nil if no type signature is present.
125
+
126
+ def type_signature_html(method_attr, from_path)
127
+ lines = method_attr.type_signature_lines || @store.rbs_signature_for(method_attr)
128
+ return unless lines
129
+
130
+ RDoc::RbsHelper.signature_to_html(
131
+ lines,
132
+ lookup: @store.type_name_lookup,
133
+ from_path: from_path
134
+ )
135
+ end
136
+
120
137
  ##
121
138
  # Resolves a URL for use in templates. Absolute URLs are returned unchanged.
122
139
  # Relative URLs are prefixed with rel_prefix to ensure they resolve correctly from any page.
@@ -73,11 +73,6 @@ class RDoc::Generator::Darkfish
73
73
  css/rdoc.css
74
74
  ]
75
75
 
76
- ##
77
- # Release Version
78
-
79
- VERSION = '3'
80
-
81
76
  ##
82
77
  # Description of this generator
83
78
 
@@ -173,7 +168,7 @@ class RDoc::Generator::Darkfish
173
168
  ##
174
169
  # Output progress information if debugging is enabled
175
170
 
176
- def debug_msg *msg
171
+ def debug_msg(*msg)
177
172
  return unless $DEBUG_RDOC
178
173
  $stderr.puts(*msg)
179
174
  end
@@ -393,6 +388,8 @@ class RDoc::Generator::Darkfish
393
388
  @files.each do |file|
394
389
  current = file
395
390
 
391
+ next if file.text? && file.full_name == @options.main_page
392
+
396
393
  if file.text? and page_file.exist? then
397
394
  generate_page file
398
395
  next
@@ -580,6 +577,15 @@ class RDoc::Generator::Darkfish
580
577
 
581
578
  return unless @store
582
579
 
580
+ refresh_store_data
581
+ end
582
+
583
+ ##
584
+ # Refreshes the generator's data from the store. Called by #setup and
585
+ # can be called again after the store has been updated (e.g. in server
586
+ # mode after re-parsing changed files).
587
+
588
+ def refresh_store_data
583
589
  @classes = @store.all_classes_and_modules.sort
584
590
  @files = @store.all_files.sort
585
591
  @methods = @classes.flat_map { |m| m.method_list }.sort
@@ -118,7 +118,7 @@ class RDoc::Generator::JsonIndex
118
118
  ##
119
119
  # Output progress information if debugging is enabled
120
120
 
121
- def debug_msg *msg
121
+ def debug_msg(*msg)
122
122
  return unless $DEBUG_RDOC
123
123
  $stderr.puts(*msg)
124
124
  end
@@ -250,7 +250,7 @@ class RDoc::Generator::JsonIndex
250
250
  debug_msg " generating pages search index"
251
251
 
252
252
  pages = @files.select do |file|
253
- file.text?
253
+ file.text? && file.full_name != @options.main_page
254
254
  end
255
255
 
256
256
  pages.each do |page|