rdoc 7.2.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 (101) 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 +11 -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 +4 -35
  12. data/lib/rdoc/code_object/context.rb +39 -34
  13. data/lib/rdoc/code_object/method_attr.rb +9 -15
  14. data/lib/rdoc/code_object/mixin.rb +2 -2
  15. data/lib/rdoc/code_object/top_level.rb +9 -3
  16. data/lib/rdoc/code_object.rb +2 -4
  17. data/lib/rdoc/comment.rb +0 -65
  18. data/lib/rdoc/cross_reference.rb +7 -27
  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 +1 -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 +56 -46
  34. data/lib/rdoc/generator/template/aliki/css/rdoc.css +337 -111
  35. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  36. data/lib/rdoc/generator/template/aliki/js/aliki.js +20 -18
  37. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  38. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  39. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  41. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  42. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  43. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  46. data/lib/rdoc/generator/template/darkfish/class.rhtml +18 -21
  47. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +0 -1
  48. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  49. data/lib/rdoc/i18n/text.rb +3 -3
  50. data/lib/rdoc/markdown.kpeg +15 -10
  51. data/lib/rdoc/markdown.rb +289 -104
  52. data/lib/rdoc/markup/document.rb +2 -2
  53. data/lib/rdoc/markup/formatter.rb +24 -34
  54. data/lib/rdoc/markup/heading.rb +1 -4
  55. data/lib/rdoc/markup/indented_paragraph.rb +1 -1
  56. data/lib/rdoc/markup/list.rb +2 -2
  57. data/lib/rdoc/markup/list_item.rb +2 -2
  58. data/lib/rdoc/markup/pre_process.rb +0 -25
  59. data/lib/rdoc/markup/to_ansi.rb +1 -1
  60. data/lib/rdoc/markup/to_bs.rb +1 -1
  61. data/lib/rdoc/markup/to_html.rb +131 -53
  62. data/lib/rdoc/markup/to_html_crossref.rb +97 -71
  63. data/lib/rdoc/markup/to_html_snippet.rb +5 -5
  64. data/lib/rdoc/markup/to_joined_paragraph.rb +0 -5
  65. data/lib/rdoc/markup/to_label.rb +2 -2
  66. data/lib/rdoc/markup/to_markdown.rb +1 -1
  67. data/lib/rdoc/markup/to_rdoc.rb +2 -2
  68. data/lib/rdoc/markup/to_table_of_contents.rb +1 -1
  69. data/lib/rdoc/markup/to_tt_only.rb +0 -7
  70. data/lib/rdoc/markup/verbatim.rb +1 -1
  71. data/lib/rdoc/options.rb +36 -51
  72. data/lib/rdoc/parser/c.rb +7 -6
  73. data/lib/rdoc/parser/rbs.rb +275 -0
  74. data/lib/rdoc/parser/ruby.rb +954 -2066
  75. data/lib/rdoc/parser/ruby_colorizer.rb +253 -0
  76. data/lib/rdoc/parser.rb +3 -2
  77. data/lib/rdoc/rbs_helper.rb +186 -0
  78. data/lib/rdoc/rdoc.rb +196 -24
  79. data/lib/rdoc/ri/driver.rb +8 -2
  80. data/lib/rdoc/ri/paths.rb +1 -1
  81. data/lib/rdoc/{servlet.rb → ri/servlet.rb} +5 -5
  82. data/lib/rdoc/ri.rb +4 -3
  83. data/lib/rdoc/rubygems_hook.rb +11 -11
  84. data/lib/rdoc/server.rb +460 -0
  85. data/lib/rdoc/stats.rb +147 -124
  86. data/lib/rdoc/store.rb +212 -4
  87. data/lib/rdoc/task.rb +16 -15
  88. data/lib/rdoc/text.rb +1 -118
  89. data/lib/rdoc/token_stream.rb +11 -33
  90. data/lib/rdoc/version.rb +1 -1
  91. data/lib/rdoc.rb +35 -7
  92. data/lib/rubygems_plugin.rb +2 -11
  93. data/rdoc-logo.svg +43 -0
  94. data/rdoc.gemspec +6 -4
  95. metadata +35 -18
  96. data/lib/rdoc/code_object/anon_class.rb +0 -10
  97. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  98. data/lib/rdoc/code_object/meta_method.rb +0 -6
  99. data/lib/rdoc/parser/prism_ruby.rb +0 -1112
  100. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  101. data/lib/rdoc/parser/ruby_tools.rb +0 -163
@@ -63,10 +63,10 @@ class RDoc::Context::Section
63
63
  # Adds +comment+ to this section
64
64
 
65
65
  def add_comment(comment)
66
- comments = Array(comment)
67
- comments.each do |c|
68
- extracted_comment = extract_comment(c)
69
- @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?
70
70
  end
71
71
  end
72
72
 
@@ -98,37 +98,6 @@ class RDoc::Context::Section
98
98
  CGI.escape(title).gsub('%', '-').sub(/^-/, '')
99
99
  end
100
100
 
101
- ##
102
- # Extracts the comment for this section from the original comment block.
103
- # If the first line contains :section:, strip it and use the rest.
104
- # Otherwise remove lines up to the line containing :section:, and look
105
- # for those lines again at the end and remove them. This lets us write
106
- #
107
- # # :section: The title
108
- # # The body
109
-
110
- def extract_comment(comment)
111
- case comment
112
- when nil
113
- RDoc::Comment.new ''
114
- when RDoc::Comment then
115
- if comment.text =~ /^#[ \t]*:section:.*\n/ then
116
- start = $`
117
- rest = $'
118
-
119
- comment.text = if start.empty? then
120
- rest
121
- else
122
- rest.sub(/#{start.chomp}\Z/, '')
123
- end
124
- end
125
-
126
- comment
127
- else
128
- raise TypeError, "unknown comment #{comment.inspect}"
129
- end
130
- end
131
-
132
101
  def inspect # :nodoc:
133
102
  "#<%s:0x%x %p>" % [self.class, object_id, title]
134
103
  end
@@ -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
@@ -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
  ##
@@ -788,7 +810,7 @@ class RDoc::Context < RDoc::CodeObject
788
810
  # Tries to find a module at a higher scope.
789
811
  # But parent is not always a higher module nesting scope, so the result is not correct.
790
812
  # Parent chain can only represent last-opened nesting, and may be broken in some cases.
791
- # PrismRuby parser stopped representing module nesting with parent chain at all.
813
+ # The Ruby parser does not represent module nesting with the parent chain.
792
814
 
793
815
  def find_enclosing_module_named(name)
794
816
  parent && parent.find_module_named(name)
@@ -950,28 +972,11 @@ class RDoc::Context < RDoc::CodeObject
950
972
  File.join(*path.compact) + '.html'
951
973
  end
952
974
 
953
- ##
954
- # Instance attributes
955
-
956
- def instance_attributes
957
- @instance_attributes ||= attributes.reject { |a| a.singleton }
958
- end
959
-
960
975
  ##
961
976
  # Instance methods
962
977
 
963
978
  def instance_methods
964
- @instance_methods ||= method_list.reject { |a| a.singleton }
965
- end
966
-
967
- ##
968
- # Instance methods
969
- #--
970
- # TODO remove this later
971
-
972
- def instance_method_list
973
- warn '#instance_method_list is obsoleted, please use #instance_methods'
974
- @instance_methods ||= method_list.reject { |a| a.singleton }
979
+ method_list.reject { |a| a.singleton }
975
980
  end
976
981
 
977
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:"
@@ -72,8 +72,8 @@ class RDoc::Mixin < RDoc::CodeObject
72
72
  #
73
73
  # As of the beginning of October, 2011, no gem includes nonexistent modules.
74
74
  #
75
- # When mixin is created from RDoc::Parser::PrismRuby, module name is already a resolved full-path name.
76
- #
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.
77
77
 
78
78
  def module
79
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
 
@@ -221,9 +221,15 @@ class RDoc::TopLevel < RDoc::Context
221
221
  # Path to this file for use with HTML generator output.
222
222
 
223
223
  def path
224
+ base = if options.main_page == full_name
225
+ 'index.html'
226
+ else
227
+ http_url
228
+ end
229
+
224
230
  prefix = options.file_path_prefix
225
- return http_url unless prefix
226
- File.join(prefix, http_url)
231
+ return base unless prefix
232
+ File.join(prefix, base)
227
233
  end
228
234
 
229
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
@@ -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
  #
@@ -190,19 +190,13 @@ class RDoc::CrossReference
190
190
  ##
191
191
  # Returns a reference to +name+.
192
192
  #
193
- # If the reference is found and +name+ is not documented +text+ will be
194
- # returned. If +name+ is escaped +name+ is returned. If +name+ is not
195
- # 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.
196
195
 
197
- def resolve(name, text)
196
+ def resolve(name)
198
197
  return @seen[name] if @seen.include? name
199
198
 
200
- ref = case name
201
- when /^\\(#{CLASS_REGEXP_STR})$/o then
202
- @context.find_symbol $1
203
- else
204
- @context.find_symbol name
205
- end
199
+ ref = @context.find_symbol name
206
200
 
207
201
  ref = resolve_local_symbol name unless ref
208
202
 
@@ -211,25 +205,11 @@ class RDoc::CrossReference
211
205
 
212
206
  ref = nil if RDoc::Alias === ref # external alias, can't link to it
213
207
 
214
- out = if name == '\\' then
215
- name
216
- elsif name =~ /^\\/ then
217
- # we remove the \ only in front of what we know:
218
- # other backslashes are treated later, only outside of <tt>
219
- ref ? $' : name
220
- elsif ref then
221
- if ref.display? then
222
- ref
223
- else
224
- text
225
- end
226
- else
227
- text
228
- end
208
+ ref = nil unless ref&.display?
229
209
 
230
- @seen[name] = out
210
+ @seen[name] = ref
231
211
 
232
- out
212
+ ref
233
213
  end
234
214
 
235
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|
@@ -37,7 +37,15 @@ module RDoc::Generator::Markup
37
37
  options = @store.options
38
38
  this = RDoc::Context === self ? self : @parent
39
39
 
40
- @formatter = RDoc::Markup::ToHtmlCrossref.new options, this.path, this
40
+ @formatter = RDoc::Markup::ToHtmlCrossref.new(
41
+ this.path, this,
42
+ pipe: options.pipe,
43
+ output_decoration: options.output_decoration,
44
+ hyperlink_all: options.hyperlink_all,
45
+ show_hash: options.show_hash,
46
+ autolink_excluded_words: options.autolink_excluded_words || [],
47
+ warn_missing_rdoc_ref: options.warn_missing_rdoc_ref
48
+ )
41
49
  @formatter.code_object = self
42
50
  @formatter
43
51
  end
@@ -75,60 +83,77 @@ class RDoc::CodeObject
75
83
 
76
84
  end
77
85
 
86
+ class RDoc::AnyMethod
87
+
88
+ ##
89
+ # Creates an HTML link to the superclass method called by this method.
90
+
91
+ def superclass_method_link
92
+ target = superclass_method
93
+ return unless target
94
+
95
+ html_formatter = formatter
96
+ name = target.full_name
97
+
98
+ html_formatter.link name, html_formatter.convert_string(name)
99
+ end
100
+
101
+ end
102
+
78
103
  class RDoc::MethodAttr
79
104
 
80
105
  ##
81
- # Prepend +src+ with line numbers. Relies on the first line of a source
82
- # code listing having:
83
- #
84
- # # File xxxxx, line dddd
85
- #
86
- # If it has this comment then line numbers are added to +src+ and the <tt>,
87
- # line dddd</tt> portion of the comment is removed.
106
+ # Prepend +src+ with line numbers.
88
107
 
89
108
  def add_line_numbers(src)
90
- return unless src.sub!(/\A(.*)(, line (\d+))/, '\1')
91
- first = $3.to_i - 1
92
- last = first + src.count("\n")
93
- size = last.to_s.length
109
+ return if src.empty? || !line
110
+ start_line = line
111
+ end_line = start_line + src.count("\n")
112
+ number_digits = end_line.to_s.length
94
113
 
95
- line = first
114
+ current_line = start_line
96
115
  src.gsub!(/^/) do
97
- res = if line == first then
98
- " " * (size + 1)
99
- else
100
- "<span class=\"line-num\">%2$*1$d</span> " % [size, line]
101
- end
116
+ res = "<span class=\"line-num\">#{current_line.to_s.rjust(number_digits)}</span> "
102
117
 
103
- line += 1
118
+ current_line += 1
104
119
  res
105
120
  end
106
121
  end
107
122
 
123
+ ##
124
+ # Prepend +src+ with a comment that declares its location in the source.
125
+
126
+ def add_location_comment(src)
127
+ path = CGI.escapeHTML(file.relative_name)
128
+ if options.line_numbers && !src.empty?
129
+ src.prepend("<span class=\"ruby-comment\"># File #{path}</span>\n")
130
+ else
131
+ src.prepend("<span class=\"ruby-comment\"># File #{path}, line #{line}</span>\n")
132
+ end
133
+ end
134
+
108
135
  ##
109
136
  # Turns the method's token stream into HTML.
110
137
  #
111
138
  # Prepends line numbers if +options.line_numbers+ is true.
112
139
 
113
140
  def markup_code
114
- return '' unless @token_stream
141
+ return '' if !@token_stream
115
142
 
116
143
  src = RDoc::TokenStream.to_html @token_stream
117
144
 
118
145
  # dedent the source
119
- indent = src.length
120
- lines = src.lines.to_a
121
- lines.shift if src =~ /\A.*#\ *File/i # remove '# File' comment
122
- lines.each do |line|
123
- if line =~ /^ *(?=\S)/
124
- n = $~.end(0)
125
- indent = n if n < indent
126
- break if n == 0
127
- end
146
+ common_indent = src.length
147
+ src.scan(/^ *(?=\S)/) do |whitespace|
148
+ common_indent = whitespace.length if whitespace.length < common_indent
149
+ break if common_indent == 0
128
150
  end
129
- src.gsub!(/^#{' ' * indent}/, '') if indent > 0
151
+ src.gsub!(/^#{' ' * common_indent}/, '') if common_indent > 0
130
152
 
131
- add_line_numbers(src) if options.line_numbers
153
+ if source_language == 'ruby'
154
+ add_line_numbers(src) if options.line_numbers
155
+ add_location_comment(src)
156
+ end
132
157
 
133
158
  src
134
159
  end