rdoc 6.15.1 → 6.16.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +1 -1
  3. data/lib/rdoc/code_object/top_level.rb +18 -17
  4. data/lib/rdoc/comment.rb +190 -8
  5. data/lib/rdoc/generator/aliki.rb +42 -0
  6. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
  7. data/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
  8. data/lib/rdoc/generator/template/aliki/_head.rhtml +91 -0
  9. data/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
  10. data/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +6 -0
  11. data/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +5 -0
  12. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +15 -0
  13. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +15 -0
  14. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
  15. data/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +21 -0
  16. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +37 -0
  17. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
  18. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +11 -0
  19. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
  20. data/lib/rdoc/generator/template/aliki/class.rhtml +219 -0
  21. data/lib/rdoc/generator/template/aliki/css/rdoc.css +1612 -0
  22. data/lib/rdoc/generator/template/aliki/index.rhtml +21 -0
  23. data/lib/rdoc/generator/template/aliki/js/aliki.js +483 -0
  24. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
  25. data/lib/rdoc/generator/template/aliki/js/search.js +120 -0
  26. data/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
  27. data/lib/rdoc/generator/template/aliki/page.rhtml +17 -0
  28. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
  29. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
  30. data/lib/rdoc/generator/template/darkfish/_head.rhtml +2 -7
  31. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +1 -0
  32. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +1 -1
  33. data/lib/rdoc/generator/template/json_index/js/searcher.js +5 -1
  34. data/lib/rdoc/generator.rb +1 -0
  35. data/lib/rdoc/markup/pre_process.rb +34 -10
  36. data/lib/rdoc/markup/to_html.rb +6 -4
  37. data/lib/rdoc/options.rb +21 -10
  38. data/lib/rdoc/parser/c.rb +15 -46
  39. data/lib/rdoc/parser/prism_ruby.rb +121 -113
  40. data/lib/rdoc/parser/ruby.rb +8 -8
  41. data/lib/rdoc/parser/ruby_tools.rb +5 -7
  42. data/lib/rdoc/parser/simple.rb +4 -21
  43. data/lib/rdoc/rdoc.rb +1 -0
  44. data/lib/rdoc/text.rb +1 -1
  45. data/lib/rdoc/token_stream.rb +13 -1
  46. data/lib/rdoc/tom_doc.rb +1 -1
  47. data/lib/rdoc/version.rb +1 -1
  48. metadata +27 -2
@@ -43,6 +43,7 @@ module RDoc::Generator
43
43
 
44
44
  autoload :Markup, "#{__dir__}/generator/markup"
45
45
 
46
+ autoload :Aliki, "#{__dir__}/generator/aliki"
46
47
  autoload :Darkfish, "#{__dir__}/generator/darkfish"
47
48
  autoload :JsonIndex, "#{__dir__}/generator/json_index"
48
49
  autoload :RI, "#{__dir__}/generator/ri"
@@ -97,18 +97,15 @@ class RDoc::Markup::PreProcess
97
97
  # RDoc::CodeObject#metadata for details.
98
98
 
99
99
  def handle(text, code_object = nil, &block)
100
- first_line = 1
101
100
  if RDoc::Comment === text then
102
101
  comment = text
103
102
  text = text.text
104
- first_line = comment.line || 1
105
103
  end
106
104
 
107
105
  # regexp helper (square brackets for optional)
108
106
  # $1 $2 $3 $4 $5
109
107
  # [prefix][\]:directive:[spaces][param]newline
110
- text = text.lines.map.with_index(first_line) do |line, num|
111
- next line unless line =~ /\A([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):([\w-]+):([ \t]*)(.+)?(\r?\n|$)/
108
+ text = text.gsub(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):([\w-]+):([ \t]*)(.+)?(\r?\n|$)/) do
112
109
  # skip something like ':toto::'
113
110
  next $& if $4.empty? and $5 and $5[0, 1] == ':'
114
111
 
@@ -122,9 +119,8 @@ class RDoc::Markup::PreProcess
122
119
  comment.format = $5.downcase
123
120
  next "#{$1.strip}\n"
124
121
  end
125
-
126
- handle_directive $1, $3, $5, code_object, text.encoding, num, &block
127
- end.join
122
+ handle_directive $1, $3, $5, code_object, text.encoding, &block
123
+ end
128
124
 
129
125
  if comment then
130
126
  comment.text = text
@@ -132,11 +128,39 @@ class RDoc::Markup::PreProcess
132
128
  comment = text
133
129
  end
134
130
 
131
+ run_post_processes(comment, code_object)
132
+
133
+ text
134
+ end
135
+
136
+ # Apply directives to a code object
137
+
138
+ def run_pre_processes(comment_text, code_object, start_line_no, type)
139
+ comment_text, directives = parse_comment(comment_text, start_line_no, type)
140
+ directives.each do |directive, (param, line_no)|
141
+ handle_directive('', directive, param, code_object)
142
+ end
143
+ if code_object.is_a?(RDoc::AnyMethod) && (call_seq, = directives['call-seq']) && call_seq
144
+ code_object.call_seq = call_seq.lines.map(&:chomp).reject(&:empty?).join("\n")
145
+ end
146
+ format, = directives['markup']
147
+ [comment_text, format]
148
+ end
149
+
150
+ # Perform post preocesses to a code object
151
+
152
+ def run_post_processes(comment, code_object)
135
153
  self.class.post_processors.each do |handler|
136
154
  handler.call comment, code_object
137
155
  end
156
+ end
138
157
 
139
- text
158
+ # Parse comment and return [normalized_comment_text, directives_hash]
159
+
160
+ def parse_comment(text, line_no, type)
161
+ RDoc::Comment.parse(text, @input_file_name, line_no, type) do |filename, prefix_indent|
162
+ include_file(filename, prefix_indent, text.encoding)
163
+ end
140
164
  end
141
165
 
142
166
  ##
@@ -151,7 +175,7 @@ class RDoc::Markup::PreProcess
151
175
  # When 1.8.7 support is ditched prefix can be defaulted to ''
152
176
 
153
177
  def handle_directive(prefix, directive, param, code_object = nil,
154
- encoding = nil, line = nil)
178
+ encoding = nil)
155
179
  blankline = "#{prefix.strip}\n"
156
180
  directive = directive.downcase
157
181
 
@@ -244,7 +268,7 @@ class RDoc::Markup::PreProcess
244
268
 
245
269
  blankline
246
270
  else
247
- result = yield directive, param, line if block_given?
271
+ result = yield directive, param if block_given?
248
272
 
249
273
  case result
250
274
  when nil then
@@ -312,11 +312,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
312
312
  else
313
313
  "\n<h#{level}>"
314
314
  end
315
- @res << to_html(heading.text)
316
- unless @options.pipe then
317
- @res << "<span><a href=\"##{label}\">&para;</a>"
318
- @res << " <a href=\"#top\">&uarr;</a></span>"
315
+
316
+ if @options.pipe
317
+ @res << to_html(heading.text)
318
+ else
319
+ @res << "<a href=\"##{label}\">#{to_html(heading.text)}</a>"
319
320
  end
321
+
320
322
  @res << "</h#{level}>\n"
321
323
  end
322
324
 
data/lib/rdoc/options.rb CHANGED
@@ -378,6 +378,21 @@ class RDoc::Options
378
378
 
379
379
  attr_accessor :canonical_root
380
380
 
381
+ ##
382
+ # Custom footer content configuration for themes that support it.
383
+ # Currently only supported by the Aliki theme.
384
+ #
385
+ # A hash where keys are column titles and values are hashes of link text => URL pairs.
386
+ # Each column will be displayed in the upper footer section.
387
+ #
388
+ # Example:
389
+ # {
390
+ # "DOCUMENTATION" => {"Home" => "/index.html", "Guide" => "/guide.html"},
391
+ # "RESOURCES" => {"RDoc" => "https://ruby.github.io/rdoc/", "GitHub" => "https://github.com/ruby/rdoc"}
392
+ # }
393
+
394
+ attr_accessor :footer_content
395
+
381
396
  def initialize(loaded_options = nil) # :nodoc:
382
397
  init_ivars
383
398
  override loaded_options if loaded_options
@@ -396,10 +411,9 @@ class RDoc::Options
396
411
  @files = nil
397
412
  @force_output = false
398
413
  @force_update = true
399
- @generator = nil
400
- @generator_name = nil
401
- @generator_options = []
414
+ @generator_name = "darkfish"
402
415
  @generators = RDoc::RDoc::GENERATORS
416
+ @generator_options = []
403
417
  @hyperlink_all = false
404
418
  @line_numbers = false
405
419
  @locale = nil
@@ -435,6 +449,7 @@ class RDoc::Options
435
449
  @class_module_path_prefix = nil
436
450
  @file_path_prefix = nil
437
451
  @canonical_root = nil
452
+ @footer_content = nil
438
453
  end
439
454
 
440
455
  def init_with(map) # :nodoc:
@@ -463,6 +478,7 @@ class RDoc::Options
463
478
 
464
479
  @apply_default_exclude = map['apply_default_exclude']
465
480
  @autolink_excluded_words = map['autolink_excluded_words']
481
+ @footer_content = map['footer_content']
466
482
 
467
483
  @rdoc_include = sanitize_path map['rdoc_include']
468
484
  @static_path = sanitize_path map['static_path']
@@ -499,6 +515,7 @@ class RDoc::Options
499
515
  @autolink_excluded_words = map['autolink_excluded_words'] if map.has_key?('autolink_excluded_words')
500
516
  @apply_default_exclude = map['apply_default_exclude'] if map.has_key?('apply_default_exclude')
501
517
  @canonical_root = map['canonical_root'] if map.has_key?('canonical_root')
518
+ @footer_content = map['footer_content'] if map.has_key?('footer_content')
502
519
 
503
520
  @warn_missing_rdoc_ref = map['warn_missing_rdoc_ref'] if map.has_key?('warn_missing_rdoc_ref')
504
521
 
@@ -1213,9 +1230,6 @@ Usage: #{opt.program_name} [options] [names...]
1213
1230
  opt.separator nil
1214
1231
  end
1215
1232
 
1216
- setup_generator 'darkfish' if
1217
- argv.grep(/\A(-f|--fmt|--format|-r|-R|--ri|--ri-site)\b/).empty?
1218
-
1219
1233
  deprecated = []
1220
1234
  invalid = []
1221
1235
 
@@ -1233,10 +1247,7 @@ Usage: #{opt.program_name} [options] [names...]
1233
1247
  retry
1234
1248
  end
1235
1249
 
1236
- unless @generator then
1237
- @generator = RDoc::Generator::Darkfish
1238
- @generator_name = 'darkfish'
1239
- end
1250
+ setup_generator unless @generator
1240
1251
 
1241
1252
  if @pipe and not argv.empty? then
1242
1253
  @pipe = false
data/lib/rdoc/parser/c.rb CHANGED
@@ -607,8 +607,6 @@ class RDoc::Parser::C < RDoc::Parser
607
607
  body = args[1]
608
608
  offset, = args[2]
609
609
 
610
- comment.remove_private if comment
611
-
612
610
  # try to find the whole body
613
611
  body = $& if /#{Regexp.escape body}[^(]*?\{.*?^\}/m =~ file_content
614
612
 
@@ -621,11 +619,10 @@ class RDoc::Parser::C < RDoc::Parser
621
619
  override_comment = find_override_comment class_name, meth_obj
622
620
  comment = override_comment if override_comment
623
621
 
624
- comment.normalize
625
622
  find_modifiers comment, meth_obj if comment
626
623
 
627
624
  #meth_obj.params = params
628
- meth_obj.start_collecting_tokens
625
+ meth_obj.start_collecting_tokens(:c)
629
626
  tk = { :line_no => 1, :char_no => 1, :text => body }
630
627
  meth_obj.add_token tk
631
628
  meth_obj.comment = comment
@@ -639,10 +636,9 @@ class RDoc::Parser::C < RDoc::Parser
639
636
 
640
637
  find_body class_name, args[3], meth_obj, file_content, true
641
638
 
642
- comment.normalize
643
639
  find_modifiers comment, meth_obj
644
640
 
645
- meth_obj.start_collecting_tokens
641
+ meth_obj.start_collecting_tokens(:c)
646
642
  tk = { :line_no => 1, :char_no => 1, :text => body }
647
643
  meth_obj.add_token tk
648
644
  meth_obj.comment = comment
@@ -663,7 +659,6 @@ class RDoc::Parser::C < RDoc::Parser
663
659
  comment = find_override_comment class_name, meth_obj
664
660
 
665
661
  if comment then
666
- comment.normalize
667
662
  find_modifiers comment, meth_obj
668
663
  meth_obj.comment = comment
669
664
 
@@ -742,7 +737,6 @@ class RDoc::Parser::C < RDoc::Parser
742
737
  end
743
738
 
744
739
  comment = new_comment comment, @top_level, :c
745
- comment.normalize
746
740
 
747
741
  look_for_directives_in class_mod, comment
748
742
 
@@ -807,9 +801,6 @@ class RDoc::Parser::C < RDoc::Parser
807
801
  # Handles modifiers in +comment+ and updates +meth_obj+ as appropriate.
808
802
 
809
803
  def find_modifiers(comment, meth_obj)
810
- comment.normalize
811
- meth_obj.call_seq = comment.extract_call_seq
812
-
813
804
  look_for_directives_in meth_obj, comment
814
805
  end
815
806
 
@@ -823,10 +814,10 @@ class RDoc::Parser::C < RDoc::Parser
823
814
  comment = if @content =~ %r%Document-method:
824
815
  \s+#{class_name}#{prefix}#{name}
825
816
  \s*?\n((?>.*?\*/))%xm then
826
- "/*#{$1}"
817
+ "/*\n#{$1}"
827
818
  elsif @content =~ %r%Document-method:
828
819
  \s#{name}\s*?\n((?>.*?\*/))%xm then
829
- "/*#{$1}"
820
+ "/*\n#{$1}"
830
821
  end
831
822
 
832
823
  return unless comment
@@ -1061,10 +1052,13 @@ class RDoc::Parser::C < RDoc::Parser
1061
1052
  # Registers a singleton class +sclass_var+ as a singleton of +class_var+
1062
1053
 
1063
1054
  def handle_singleton(sclass_var, class_var)
1064
- class_name = @known_classes[class_var]
1065
-
1066
- @known_classes[sclass_var] = class_name
1067
- @singleton_classes[sclass_var] = class_name
1055
+ if (klass = @classes[class_var])
1056
+ @classes[sclass_var] = klass
1057
+ end
1058
+ if (class_name = @known_classes[class_var])
1059
+ @known_classes[sclass_var] = class_name
1060
+ @singleton_classes[sclass_var] = class_name
1061
+ end
1068
1062
  end
1069
1063
 
1070
1064
  ##
@@ -1102,35 +1096,10 @@ class RDoc::Parser::C < RDoc::Parser
1102
1096
  # Both :main: and :title: directives are deprecated and will be removed in RDoc 7.
1103
1097
 
1104
1098
  def look_for_directives_in(context, comment)
1105
- @preprocess.handle comment, context do |directive, param|
1106
- case directive
1107
- when 'main' then
1108
- @options.main_page = param
1109
-
1110
- warn <<~MSG
1111
- The :main: directive is deprecated and will be removed in RDoc 7.
1112
-
1113
- You can use these options to specify the initial page displayed instead:
1114
- - `--main=#{param}` via the command line
1115
- - `rdoc.main = "#{param}"` if you use `RDoc::Task`
1116
- - `main_page: #{param}` in your `.rdoc_options` file
1117
- MSG
1118
- ''
1119
- when 'title' then
1120
- @options.default_title = param if @options.respond_to? :default_title=
1121
-
1122
- warn <<~MSG
1123
- The :title: directive is deprecated and will be removed in RDoc 7.
1124
-
1125
- You can use these options to specify the title displayed instead:
1126
- - `--title=#{param}` via the command line
1127
- - `rdoc.title = "#{param}"` if you use `RDoc::Task`
1128
- - `title: #{param}` in your `.rdoc_options` file
1129
- MSG
1130
- ''
1131
- end
1132
- end
1133
-
1099
+ comment.text, format = @preprocess.run_pre_processes(comment.text, context, comment.line || 1, :c)
1100
+ comment.format = format if format
1101
+ @preprocess.run_post_processes(comment, context)
1102
+ comment.normalized = true
1134
1103
  comment
1135
1104
  end
1136
1105