rdoc 6.14.2 → 7.0.3

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +196 -0
  3. data/History.rdoc +1 -1
  4. data/LEGAL.rdoc +6 -0
  5. data/README.md +129 -0
  6. data/RI.md +1 -1
  7. data/lib/rdoc/code_object/any_method.rb +15 -7
  8. data/lib/rdoc/code_object/class_module.rb +38 -8
  9. data/lib/rdoc/code_object/constant.rb +9 -0
  10. data/lib/rdoc/code_object/method_attr.rb +13 -1
  11. data/lib/rdoc/code_object/top_level.rb +31 -26
  12. data/lib/rdoc/comment.rb +190 -8
  13. data/lib/rdoc/cross_reference.rb +1 -1
  14. data/lib/rdoc/generator/aliki.rb +183 -0
  15. data/lib/rdoc/generator/darkfish.rb +8 -2
  16. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
  17. data/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
  18. data/lib/rdoc/generator/template/aliki/_head.rhtml +158 -0
  19. data/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
  20. data/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
  21. data/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
  22. data/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
  23. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +25 -0
  24. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +25 -0
  25. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
  26. data/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
  27. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
  28. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
  29. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
  30. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
  31. data/lib/rdoc/generator/template/aliki/class.rhtml +218 -0
  32. data/lib/rdoc/generator/template/aliki/css/rdoc.css +1943 -0
  33. data/lib/rdoc/generator/template/aliki/index.rhtml +22 -0
  34. data/lib/rdoc/generator/template/aliki/js/aliki.js +505 -0
  35. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
  36. data/lib/rdoc/generator/template/aliki/js/search_controller.js +129 -0
  37. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  38. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  39. data/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
  40. data/lib/rdoc/generator/template/aliki/page.rhtml +18 -0
  41. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
  42. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +3 -3
  44. data/lib/rdoc/generator/template/darkfish/_head.rhtml +14 -19
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -8
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -8
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +7 -6
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +6 -6
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +18 -18
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +2 -2
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +1 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +3 -3
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +14 -14
  54. data/lib/rdoc/generator/template/darkfish/class.rhtml +68 -68
  55. data/lib/rdoc/generator/template/darkfish/index.rhtml +4 -3
  56. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +21 -1
  57. data/lib/rdoc/generator/template/darkfish/js/search.js +11 -1
  58. data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -1
  59. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +2 -1
  60. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +19 -19
  61. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +19 -17
  62. data/lib/rdoc/generator/template/json_index/js/searcher.js +48 -6
  63. data/lib/rdoc/generator.rb +1 -0
  64. data/lib/rdoc/markdown.kpeg +28 -17
  65. data/lib/rdoc/markdown.rb +365 -544
  66. data/lib/rdoc/markup/blank_line.rb +25 -23
  67. data/lib/rdoc/markup/element.rb +21 -0
  68. data/lib/rdoc/markup/hard_break.rb +30 -27
  69. data/lib/rdoc/markup/heading.rb +96 -79
  70. data/lib/rdoc/markup/pre_process.rb +34 -10
  71. data/lib/rdoc/markup/raw.rb +52 -55
  72. data/lib/rdoc/markup/table.rb +48 -40
  73. data/lib/rdoc/markup/to_ansi.rb +4 -0
  74. data/lib/rdoc/markup/to_bs.rb +4 -0
  75. data/lib/rdoc/markup/to_html.rb +162 -14
  76. data/lib/rdoc/markup/to_html_crossref.rb +53 -23
  77. data/lib/rdoc/markup/to_rdoc.rb +11 -3
  78. data/lib/rdoc/markup.rb +1 -0
  79. data/lib/rdoc/options.rb +22 -11
  80. data/lib/rdoc/parser/c.rb +15 -46
  81. data/lib/rdoc/parser/prism_ruby.rb +121 -113
  82. data/lib/rdoc/parser/ruby.rb +8 -8
  83. data/lib/rdoc/parser/ruby_tools.rb +5 -7
  84. data/lib/rdoc/parser/simple.rb +4 -21
  85. data/lib/rdoc/rdoc.rb +1 -0
  86. data/lib/rdoc/ri/task.rb +2 -2
  87. data/lib/rdoc/rubygems_hook.rb +3 -3
  88. data/lib/rdoc/store.rb +2 -2
  89. data/lib/rdoc/task.rb +4 -4
  90. data/lib/rdoc/text.rb +1 -1
  91. data/lib/rdoc/token_stream.rb +13 -1
  92. data/lib/rdoc/tom_doc.rb +1 -1
  93. data/lib/rdoc/version.rb +1 -1
  94. data/rdoc.gemspec +4 -3
  95. metadata +51 -8
  96. data/CONTRIBUTING.rdoc +0 -219
  97. data/README.rdoc +0 -144
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff34d02bfaa6b5e36bd3ab29b6fdfc10e41a50ba0fbef3841aed3e59d22e8d29
4
- data.tar.gz: bee9f682708babef768b5fe0b5b68a505ad09ba255c20c00fdefb52cd5135566
3
+ metadata.gz: e115c57c1541a612613ea80a869ce964b13aee43badba6c75bae66aa70495e29
4
+ data.tar.gz: 5a0dfd61dc9a5116612d939f3d94197fe687667cd8185d00983afb3fea38aade
5
5
  SHA512:
6
- metadata.gz: 10729c09826000d5ac6d4137fdba80b36dd7da96c66475ee03fcfe527dd159a74f41ec8c1a5cb588373c4007ea02a18cd9ca5e09e1766125daab7e84ca17a6ae
7
- data.tar.gz: 785c69b91032d0e72810f91c56271d100d03439355bda96f808faaea60ec2768caab376a8420bbbb72e7bbeb6c50a06ed5a002c668342aa80444ee7d0b1c2a6f
6
+ metadata.gz: fc7d789798d547865d5205eafbb6b8db9b5b16bc422c5fba3658952a8568248eda44aba606c1c1cac335af38babdf18bf4a2aa56f1c7189fe894858e154c9353
7
+ data.tar.gz: da731f564307246734edefbc271577d434b3d4527d865cd2c6575db5dce5d36caab97925204bacbb1a2063aff4109a55db5c269829df32e5ac29163b366b8c7d
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,196 @@
1
+ # Contributing to RDoc
2
+
3
+ Thank you for your interest in contributing to RDoc! This document provides guidelines and instructions for contributing.
4
+
5
+ ## Reporting Bugs
6
+
7
+ If you think you found a bug, open an issue on the [issue tracker](https://github.com/ruby/rdoc/issues) on GitHub.
8
+
9
+ When reporting a bug:
10
+
11
+ - Include a sample file that illustrates the problem, or link to the repository/gem associated with the bug
12
+ - Include steps to reproduce the issue
13
+
14
+ ## Development Setup
15
+
16
+ RDoc uses Bundler for development. To get started:
17
+
18
+ ```bash
19
+ bundle install
20
+ bundle exec rake
21
+ ```
22
+
23
+ This will install dependencies and run the tests.
24
+
25
+ If you're working on CSS or templates, you'll also want Node dependencies for the CSS linter:
26
+
27
+ ```bash
28
+ npm install
29
+ ```
30
+
31
+ If tests don't pass on the first run, check the [GitHub Actions page](https://github.com/ruby/rdoc/actions) to see if there are any known failures.
32
+
33
+ **Note:** Generated parser files are committed to the repository. If you delete them (for example via `bundle exec rake clean`) or you change any `.ry`/`.kpeg` parser sources, run `bundle exec rake generate` before running tests.
34
+
35
+ ## Running Tests
36
+
37
+ ```bash
38
+ # Run all tests (default task)
39
+ bundle exec rake
40
+
41
+ # Run unit tests only (excludes RubyGems integration)
42
+ bundle exec rake normal_test
43
+
44
+ # Run RubyGems integration tests only
45
+ bundle exec rake rubygems_test
46
+
47
+ # Verify generated parser files are current (CI check)
48
+ bundle exec rake verify_generated
49
+ ```
50
+
51
+ - **Test Framework:** [`test-unit`](https://github.com/test-unit/test-unit)
52
+ - **Test Location:** `test/` directory
53
+ - **Test Helper:** `test/lib/helper.rb`
54
+
55
+ ## Linting
56
+
57
+ ### RuboCop (Ruby Code)
58
+
59
+ ```bash
60
+ # Check Ruby code style
61
+ bundle exec rubocop
62
+
63
+ # Auto-fix style issues
64
+ bundle exec rubocop -A
65
+ ```
66
+
67
+ ### Herb Linter (ERB/RHTML Templates)
68
+
69
+ ```bash
70
+ # Lint ERB template files
71
+ npx @herb-tools/linter "**/*.rhtml"
72
+
73
+ # Lint specific directory
74
+ npx @herb-tools/linter "lib/**/*.rhtml"
75
+ ```
76
+
77
+ **Template Location:** `lib/rdoc/generator/template/**/*.rhtml`
78
+
79
+ ### Stylelint (CSS Files)
80
+
81
+ ```bash
82
+ # Lint CSS files
83
+ npm run lint:css
84
+
85
+ # Auto-fix style issues
86
+ npm run lint:css -- --fix
87
+ ```
88
+
89
+ ## Type annotations
90
+
91
+ RDoc is currently not a typed codebase. Despite not running a type checker, contributors have been
92
+ adding some comment annotations to make the codebase easier to navigate and understand.
93
+
94
+ These annotations use [Sorbet flavored RBS](https://sorbet.org/docs/rbs-support) annotations,
95
+ so that we can tag definitions as abstract and override. For more information on RBS syntax,
96
+ see the [documentation](https://github.com/ruby/rbs/blob/master/docs/syntax.md).
97
+
98
+ ## Parser Generation
99
+
100
+ RDoc uses generated parsers for Markdown and RD formats.
101
+
102
+ ```bash
103
+ # Generate all parser files from sources
104
+ bundle exec rake generate
105
+
106
+ # Remove generated parser files
107
+ bundle exec rake clean
108
+
109
+ # Verify generated files are in sync with sources (CI check)
110
+ bundle exec rake verify_generated
111
+ ```
112
+
113
+ **Source Files** (edit these):
114
+
115
+ - `lib/rdoc/rd/block_parser.ry` → generates `block_parser.rb` via racc
116
+ - `lib/rdoc/rd/inline_parser.ry` → generates `inline_parser.rb` via racc
117
+ - `lib/rdoc/markdown.kpeg` → generates `markdown.rb` via kpeg
118
+ - `lib/rdoc/markdown/literals.kpeg` → generates `literals.rb` via kpeg
119
+
120
+ **Important:**
121
+
122
+ - Generated parser files **should be committed** to the repository
123
+ - Do not edit generated `.rb` parser files directly
124
+ - After modifying `.ry` or `.kpeg` source files, run `bundle exec rake generate`
125
+ - CI runs `rake verify_generated` to ensure generated files are in sync with their sources
126
+
127
+ ## Documentation Generation
128
+
129
+ ```bash
130
+ # Generate documentation (creates _site directory)
131
+ bundle exec rake rdoc
132
+
133
+ # Force regenerate documentation
134
+ bundle exec rake rerdoc
135
+
136
+ # Show documentation coverage
137
+ bundle exec rake rdoc:coverage
138
+ bundle exec rake coverage
139
+ ```
140
+
141
+ - **Output Directory:** `_site/` (GitHub Pages compatible)
142
+ - **Configuration:** `.rdoc_options` and `.document`
143
+
144
+ ## Themes
145
+
146
+ RDoc ships with two HTML themes:
147
+
148
+ - **Aliki** (default) - Modern theme with improved styling and navigation
149
+ - **Darkfish** (deprecated) - Classic theme, will be removed in v8.0
150
+
151
+ New feature development should focus on the Aliki theme. Darkfish will continue to receive bug fixes but no new features.
152
+
153
+ Theme templates are located at `lib/rdoc/generator/template/<theme>/`.
154
+
155
+ ## Project Structure
156
+
157
+ ```
158
+ lib/rdoc/
159
+ ├── rdoc.rb # Main entry point (RDoc::RDoc class)
160
+ ├── version.rb # Version constant
161
+ ├── task.rb # Rake task integration
162
+ ├── parser/ # Source code parsers
163
+ │ ├── ruby.rb # Ruby code parser
164
+ │ ├── c.rb # C extension parser
165
+ │ ├── prism_ruby.rb # Prism-based Ruby parser
166
+ │ └── ...
167
+ ├── generator/ # Documentation generators
168
+ │ ├── aliki.rb # HTML generator (default theme)
169
+ │ ├── darkfish.rb # HTML generator (deprecated, will be removed in v8.0)
170
+ │ ├── markup.rb # Markup format generator
171
+ │ ├── ri.rb # RI command generator
172
+ │ └── template/ # ERB templates
173
+ │ ├── aliki/ # Aliki theme (default)
174
+ │ └── darkfish/ # Darkfish theme (deprecated)
175
+ ├── markup/ # Markup parsing and formatting
176
+ ├── code_object/ # AST objects for documented items
177
+ ├── markdown.kpeg # Parser source (edit this)
178
+ ├── markdown.rb # Generated parser (do not edit)
179
+ ├── markdown/ # Markdown parsing
180
+ │ ├── literals.kpeg # Parser source (edit this)
181
+ │ └── literals.rb # Generated parser (do not edit)
182
+ ├── rd/ # RD format parsing
183
+ │ ├── block_parser.ry # Parser source (edit this)
184
+ │ ├── block_parser.rb # Generated parser (do not edit)
185
+ │ ├── inline_parser.ry # Parser source (edit this)
186
+ │ └── inline_parser.rb # Generated parser (do not edit)
187
+ └── ri/ # RI (Ruby Info) tool
188
+
189
+ test/ # Test files
190
+ ├── lib/helper.rb # Test helpers
191
+ └── rdoc/ # Main test directory
192
+ ```
193
+
194
+ ## Code of Conduct
195
+
196
+ Please be respectful and constructive in all interactions. We're all here to make RDoc better!
data/History.rdoc CHANGED
@@ -163,7 +163,7 @@
163
163
  * Moved old DEVELOPERS file to CONTRIBUTING to match github conventions.
164
164
  * TomDoc output now has a "Returns" heading. Issue #234 by Brian Henderson
165
165
  * Metaprogrammed methods can now use the :args: directive in addition to the
166
- :call-seq: directive. Issue #236 by Mike Moore.
166
+ \:call-seq: directive. Issue #236 by Mike Moore.
167
167
  * Sections can be linked to using "@" like labels. If a section and a label
168
168
  have the same name the section will be preferred. Issue #233 by Brian
169
169
  Henderson.
data/LEGAL.rdoc CHANGED
@@ -4,6 +4,12 @@
4
4
 
5
5
  The files in this distribution are covered by the Ruby license (see LICENSE) except the features mentioned below:
6
6
 
7
+ Aliki::
8
+ Aliki was written by Stan Lo and is included under the MIT license.
9
+
10
+ * lib/rdoc/generator/aliki.rb
11
+ * lib/rdoc/generator/template/aliki/*
12
+
7
13
  Darkfish::
8
14
  Darkfish was written by Michael Granger and is included under the BSD 3-Clause
9
15
  license. Darkfish contains images from the Silk Icons set by Mark James.
data/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # RDoc - Ruby Documentation System
2
+
3
+ - GitHub: [https://github.com/ruby/rdoc](https://github.com/ruby/rdoc)
4
+ - Issues: [https://github.com/ruby/rdoc/issues](https://github.com/ruby/rdoc/issues)
5
+
6
+ ## Description
7
+
8
+ RDoc produces HTML and command-line documentation for Ruby projects. RDoc includes the `rdoc` and `ri` tools for generating and displaying documentation from the command-line.
9
+
10
+ ## Generating Documentation
11
+
12
+ Once installed, you can create documentation using the `rdoc` command
13
+
14
+ ```shell
15
+ rdoc [options] [names...]
16
+ ```
17
+
18
+ For an up-to-date option summary, type
19
+
20
+ ```shell
21
+ rdoc --help
22
+ ```
23
+
24
+ A typical use might be to generate documentation for a package of Ruby source (such as RDoc itself).
25
+
26
+ ```shell
27
+ rdoc
28
+ ```
29
+
30
+ This command generates documentation for all the Ruby and C source files in and below the current directory. These will be stored in a documentation tree starting in the subdirectory `doc`.
31
+
32
+ You can make this slightly more useful for your readers by having the index page contain the documentation for the primary file. In our case, we could type
33
+
34
+ ```shell
35
+ rdoc --main README.md
36
+ ```
37
+
38
+ You'll find information on the various formatting tricks you can use in comment blocks in the documentation this generates.
39
+
40
+ RDoc uses file extensions to determine how to process each file. File names ending `.rb` and `.rbw` are assumed to be Ruby source. Files ending `.c` are parsed as C files. All other files are assumed to contain just Markup-style markup (with or without leading `#` comment markers). If directory names are passed to RDoc, they are scanned recursively for C and Ruby source files only.
41
+
42
+ To generate documentation using `rake` see [RDoc::Task](https://ruby.github.io/rdoc/RDoc/Task.html).
43
+
44
+ To generate documentation programmatically:
45
+
46
+ ```rb
47
+ require 'rdoc/rdoc'
48
+
49
+ options = RDoc::Options.new
50
+ options.files = ['a.rb', 'b.rb']
51
+ options.setup_generator 'aliki'
52
+ # see RDoc::Options
53
+
54
+ rdoc = RDoc::RDoc.new
55
+ rdoc.document options
56
+ # see RDoc::RDoc
57
+ ```
58
+
59
+ You can specify the target files for document generation with `.document` file in the project root directory. `.document` file contains a list of file and directory names including comment lines starting with `#`. See [https://github.com/ruby/rdoc/blob/master/.document](https://github.com/ruby/rdoc/blob/master/.document) as an example.
60
+
61
+ ## Writing Documentation
62
+
63
+ To write documentation for RDoc place a comment above the class, module, method, constant, or attribute you want documented:
64
+
65
+ ```rb
66
+ ##
67
+ # This class represents an arbitrary shape by a series of points.
68
+ class Shape
69
+ ##
70
+ # Creates a new shape described by a +polyline+.
71
+ #
72
+ # If the +polyline+ does not end at the same point it started at the
73
+ # first pointed is copied and placed at the end of the line.
74
+ #
75
+ # An ArgumentError is raised if the line crosses itself, but shapes may
76
+ # be concave.
77
+ def initialize polyline
78
+ # ...
79
+ end
80
+ end
81
+ ```
82
+
83
+ The default comment markup format is the RDoc::Markup format. TomDoc, Markdown and RD format comments are also supported. You can set the default comment format for your entire project by creating a `.rdoc_options` file. See RDoc::Options@Saved+Options for instructions on creating one. You can also set the comment format for a single file through the `:markup:` directive, but this is only recommended if you wish to switch markup formats. See RDoc::Markup@Other+directives.
84
+
85
+ Comments can contain directives that tell RDoc information that it cannot otherwise discover through parsing. See RDoc::Markup@Directives to control what is or is not documented, to define method arguments or to break up methods in a class by topic. See RDoc::Parser::Ruby for directives used to teach RDoc about metaprogrammed methods.
86
+
87
+ See RDoc::Parser::C for documenting C extensions with RDoc.
88
+
89
+ To determine how well your project is documented run `rdoc -C lib` to get a documentation coverage report. `rdoc -C1 lib` includes parameter names in the documentation coverage report.
90
+
91
+ ## Theme Options
92
+
93
+ RDoc ships with two built-in themes:
94
+
95
+ - **Aliki** (default) - A modern, clean theme with improved navigation and search
96
+ - **Darkfish** (deprecated) - The classic theme, will be removed in v8.0
97
+
98
+ To use the Darkfish theme instead of the default Aliki theme:
99
+
100
+ ```shell
101
+ rdoc --format darkfish
102
+ ```
103
+
104
+ Or in your `.rdoc_options` file:
105
+
106
+ ```yaml
107
+ generator_name: darkfish
108
+ ```
109
+
110
+ There are also a few community-maintained themes for RDoc:
111
+
112
+ - [rorvswild-theme-rdoc](https://github.com/BaseSecrete/rorvswild-theme-rdoc)
113
+ - [hanna](https://github.com/jeremyevans/hanna) (a fork maintained by [Jeremy Evans](https://github.com/jeremyevans))
114
+
115
+ Please follow the theme's README for usage instructions.
116
+
117
+ ## Bugs
118
+
119
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for information on filing a bug report. It's OK to file a bug report for anything you're having a problem with. If you can't figure out how to make RDoc produce the output you like that is probably a documentation bug.
120
+
121
+ ## License
122
+
123
+ RDoc is Copyright (c) 2001-2003 Dave Thomas, The Pragmatic Programmers. Portions (c) 2007-2011 Eric Hodel. Portions copyright others, see individual files and LEGAL.rdoc for details.
124
+
125
+ RDoc is free software, and may be redistributed under the terms specified in LICENSE.rdoc.
126
+
127
+ ## Warranty
128
+
129
+ This software is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
data/RI.md CHANGED
@@ -48,7 +48,7 @@ the [Ruby online documentation](https://docs.ruby-lang.org/en/master):
48
48
  - If you are working in a terminal window, typing `ri _whatever_` (or just `ri`)
49
49
  may be faster than navigating to a browser window and searching for documentation.
50
50
  - If you are working in an
51
- [irb \(interactive Ruby\)](https://docs.ruby-lang.org/en/master/IRB.html)
51
+ [irb \(interactive Ruby\)](https://ruby.github.io/irb/index.html)
52
52
  session, you _already_ have immediate access to `ri`:
53
53
  just type `'show_doc'`.
54
54
 
@@ -351,7 +351,6 @@ class RDoc::AnyMethod < RDoc::MethodAttr
351
351
  return call_seq unless is_alias_for || !aliases.empty?
352
352
 
353
353
  method_name = self.name
354
- method_name = method_name[0, 1] if method_name =~ /\A\[/
355
354
 
356
355
  entries = call_seq.split "\n"
357
356
 
@@ -360,15 +359,24 @@ class RDoc::AnyMethod < RDoc::MethodAttr
360
359
  ignore << is_alias_for.name
361
360
  ignore.concat is_alias_for.aliases.map(&:name)
362
361
  end
363
- ignore.map! { |n| n =~ /\A\[/ ? /\[.*\]/ : n}
362
+
364
363
  ignore.delete(method_name)
365
- ignore = Regexp.union(ignore)
364
+ ignore_bracket_methods, ignore_other_methods = ignore.partition {|i| i.start_with?('[') }
366
365
 
367
- matching = entries.reject do |entry|
368
- entry =~ /^\w*\.?#{ignore}[$\(\s]/ or
369
- entry =~ /\s#{ignore}\s/
366
+ if ignore_other_methods.any?
367
+ ignore_union = Regexp.union(ignore_other_methods)
368
+ entries.reject! do |entry|
369
+ /\A(?:\w*\.)?#{ignore_union}(?:[(\s]|\z)/.match?(entry) ||
370
+ /\s#{ignore_union}\s/.match?(entry)
371
+ end
372
+ end
373
+ if ignore_bracket_methods.any?
374
+ entries.reject! do |entry|
375
+ # Ignore `receiver[arg] -> return_type` `[](arg)` `[]`
376
+ /\A\w*\[.*?\](?:[(\s]|\z)/.match?(entry)
377
+ end
370
378
  end
371
379
 
372
- matching.empty? ? nil : matching.join("\n")
380
+ entries.empty? ? nil : entries.join("\n")
373
381
  end
374
382
  end
@@ -30,7 +30,22 @@ class RDoc::ClassModule < RDoc::Context
30
30
  attr_accessor :constant_aliases
31
31
 
32
32
  ##
33
- # Comment and the location it came from. Use #add_comment to add comments
33
+ # An array of `[comment, location]` pairs documenting this class/module.
34
+ # Use #add_comment to add comments.
35
+ #
36
+ # Before marshalling:
37
+ # - +comment+ is a String
38
+ # - +location+ is an RDoc::TopLevel
39
+ #
40
+ # After unmarshalling:
41
+ # - +comment+ is an RDoc::Markup::Document
42
+ # - +location+ is a filename String
43
+ #
44
+ # These type changes are acceptable (for now) because:
45
+ # - +comment+: Both String and Document respond to #empty?, and #parse
46
+ # returns Document as-is (see RDoc::Text#parse)
47
+ # - +location+: Only used by #parse to set Document#file, which accepts
48
+ # both TopLevel (extracts relative_name) and String
34
49
 
35
50
  attr_accessor :comment_location
36
51
 
@@ -110,7 +125,7 @@ class RDoc::ClassModule < RDoc::Context
110
125
  @is_alias_for = nil
111
126
  @name = name
112
127
  @superclass = superclass
113
- @comment_location = [] # [[comment, location]]
128
+ @comment_location = [] # Array of [comment, location] pairs
114
129
 
115
130
  super()
116
131
  end
@@ -379,10 +394,10 @@ class RDoc::ClassModule < RDoc::Context
379
394
 
380
395
  @comment = RDoc::Comment.from_document document
381
396
 
382
- @comment_location = if RDoc::Markup::Document === document.parts.first then
383
- document
397
+ @comment_location = if document.parts.first.is_a?(RDoc::Markup::Document)
398
+ document.parts.map { |doc| [doc, doc.file] }
384
399
  else
385
- RDoc::Markup::Document.new document
400
+ [[document, document.file]]
386
401
  end
387
402
 
388
403
  array[5].each do |name, rw, visibility, singleton, file|
@@ -689,6 +704,9 @@ class RDoc::ClassModule < RDoc::Context
689
704
 
690
705
  ##
691
706
  # Search record used by RDoc::Generator::JsonIndex
707
+ #
708
+ # TODO: Remove this method after dropping the darkfish theme and JsonIndex generator.
709
+ # Use #search_snippet instead for getting documentation snippets.
692
710
 
693
711
  def search_record
694
712
  [
@@ -702,6 +720,16 @@ class RDoc::ClassModule < RDoc::Context
702
720
  ]
703
721
  end
704
722
 
723
+ ##
724
+ # Returns an HTML snippet of the first comment for search results.
725
+
726
+ def search_snippet
727
+ first_comment = @comment_location.first&.first
728
+ return '' unless first_comment && !first_comment.empty?
729
+
730
+ snippet(first_comment)
731
+ end
732
+
705
733
  ##
706
734
  # Sets the store for this class or module and its contained code objects.
707
735
 
@@ -794,11 +822,13 @@ class RDoc::ClassModule < RDoc::Context
794
822
  cm_alias = cm.dup
795
823
  cm_alias.name = const.name
796
824
 
797
- # Don't move top-level aliases under Object, they look ugly there
798
- unless RDoc::TopLevel === cm_alias.parent then
825
+ if full_name == 'Object'
826
+ # Don't move top-level aliases under Object, they look ugly there
827
+ cm_alias.parent = top_level
828
+ else
799
829
  cm_alias.parent = self
800
- cm_alias.full_name = nil # force update for new parent
801
830
  end
831
+ cm_alias.full_name = nil # force update for new parent
802
832
 
803
833
  cm_alias.aliases.clear
804
834
  cm_alias.is_alias_for = cm
@@ -154,6 +154,15 @@ class RDoc::Constant < RDoc::CodeObject
154
154
  "#{@parent.path}##{@name}"
155
155
  end
156
156
 
157
+ ##
158
+ # Returns an HTML snippet of the comment for search results.
159
+
160
+ def search_snippet
161
+ return '' if comment.empty?
162
+
163
+ snippet(comment)
164
+ end
165
+
157
166
  def pretty_print(q) # :nodoc:
158
167
  q.group 2, "[#{self.class.name} #{full_name}", "]" do
159
168
  unless comment.empty? then
@@ -375,6 +375,9 @@ class RDoc::MethodAttr < RDoc::CodeObject
375
375
  ##
376
376
  # Used by RDoc::Generator::JsonIndex to create a record for the search
377
377
  # engine.
378
+ #
379
+ # TODO: Remove this method after dropping the darkfish theme and JsonIndex generator.
380
+ # Use #search_snippet instead for getting documentation snippets.
378
381
 
379
382
  def search_record
380
383
  [
@@ -384,10 +387,19 @@ class RDoc::MethodAttr < RDoc::CodeObject
384
387
  @parent.full_name,
385
388
  path,
386
389
  params,
387
- snippet(@comment),
390
+ search_snippet,
388
391
  ]
389
392
  end
390
393
 
394
+ ##
395
+ # Returns an HTML snippet of the comment for search results.
396
+
397
+ def search_snippet
398
+ return '' if @comment.empty?
399
+
400
+ snippet(@comment)
401
+ end
402
+
391
403
  def to_s # :nodoc:
392
404
  if @is_alias_for
393
405
  "#{self.class.name}: #{full_name} -> #{is_alias_for}"
@@ -16,6 +16,16 @@ class RDoc::TopLevel < RDoc::Context
16
16
 
17
17
  attr_accessor :absolute_name
18
18
 
19
+ ##
20
+ # Base name of this file
21
+
22
+ attr_reader :base_name
23
+
24
+ ##
25
+ # Base name of this file without the extension
26
+
27
+ attr_reader :page_name
28
+
19
29
  ##
20
30
  # All the classes or modules that were declared in
21
31
  # this file. These are assigned to either +#classes_hash+
@@ -40,6 +50,14 @@ class RDoc::TopLevel < RDoc::Context
40
50
  @relative_name = relative_name
41
51
  @parser = nil
42
52
 
53
+ if relative_name
54
+ @base_name = File.basename(relative_name)
55
+ @page_name = @base_name.sub(/\.(rb|rdoc|txt|md)\z/i, '')
56
+ else
57
+ @base_name = nil
58
+ @page_name = nil
59
+ end
60
+
43
61
  @classes_or_modules = []
44
62
  end
45
63
 
@@ -105,23 +123,8 @@ class RDoc::TopLevel < RDoc::Context
105
123
  @classes_or_modules << mod
106
124
  end
107
125
 
108
- ##
109
- # Base name of this file
110
-
111
- def base_name
112
- File.basename @relative_name
113
- end
114
-
115
126
  alias name base_name
116
127
 
117
- ##
118
- # Only a TopLevel that contains text file) will be displayed. See also
119
- # RDoc::CodeObject#display?
120
-
121
- def display?
122
- text? and super
123
- end
124
-
125
128
  ##
126
129
  # See RDoc::TopLevel::find_class_or_module
127
130
  #--
@@ -212,16 +215,6 @@ class RDoc::TopLevel < RDoc::Context
212
215
  end
213
216
  end
214
217
 
215
- ##
216
- # Base name of this file without the extension
217
-
218
- def page_name
219
- basename = File.basename @relative_name
220
- basename =~ /\.(rb|rdoc|txt|md)$/i
221
-
222
- $` || basename
223
- end
224
-
225
218
  ##
226
219
  # Path to this file for use with HTML generator output.
227
220
 
@@ -244,6 +237,9 @@ class RDoc::TopLevel < RDoc::Context
244
237
 
245
238
  ##
246
239
  # Search record used by RDoc::Generator::JsonIndex
240
+ #
241
+ # TODO: Remove this method after dropping the darkfish theme and JsonIndex generator.
242
+ # Use #search_snippet instead for getting documentation snippets.
247
243
 
248
244
  def search_record
249
245
  return unless @parser < RDoc::Parser::Text
@@ -255,10 +251,19 @@ class RDoc::TopLevel < RDoc::Context
255
251
  '',
256
252
  path,
257
253
  '',
258
- snippet(@comment),
254
+ search_snippet,
259
255
  ]
260
256
  end
261
257
 
258
+ ##
259
+ # Returns an HTML snippet of the comment for search results.
260
+
261
+ def search_snippet
262
+ return '' if @comment.empty?
263
+
264
+ snippet(@comment)
265
+ end
266
+
262
267
  ##
263
268
  # Is this TopLevel from a text file instead of a source code file?
264
269