rdoc 5.1.0 → 6.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CONTRIBUTING.rdoc +5 -6
- data/ExampleMarkdown.md +2 -0
- data/ExampleRDoc.rdoc +2 -0
- data/History.rdoc +68 -66
- data/LEGAL.rdoc +1 -1
- data/LICENSE.rdoc +2 -0
- data/README.rdoc +18 -6
- data/RI.md +842 -0
- data/TODO.rdoc +8 -7
- data/exe/rdoc +0 -1
- data/lib/rdoc/{alias.rb → code_object/alias.rb} +4 -12
- data/lib/rdoc/{anon_class.rb → code_object/anon_class.rb} +1 -2
- data/lib/rdoc/{any_method.rb → code_object/any_method.rb} +83 -26
- data/lib/rdoc/{attr.rb → code_object/attr.rb} +5 -9
- data/lib/rdoc/{class_module.rb → code_object/class_module.rb} +112 -24
- data/lib/rdoc/{constant.rb → code_object/constant.rb} +4 -5
- data/lib/rdoc/{context → code_object/context}/section.rb +13 -83
- data/lib/rdoc/{context.rb → code_object/context.rb} +69 -70
- data/lib/rdoc/{extend.rb → code_object/extend.rb} +1 -2
- data/lib/rdoc/{ghost_method.rb → code_object/ghost_method.rb} +1 -2
- data/lib/rdoc/{include.rb → code_object/include.rb} +1 -2
- data/lib/rdoc/{meta_method.rb → code_object/meta_method.rb} +1 -2
- data/lib/rdoc/{method_attr.rb → code_object/method_attr.rb} +22 -31
- data/lib/rdoc/{mixin.rb → code_object/mixin.rb} +1 -2
- data/lib/rdoc/{normal_class.rb → code_object/normal_class.rb} +4 -5
- data/lib/rdoc/{normal_module.rb → code_object/normal_module.rb} +2 -3
- data/lib/rdoc/{require.rb → code_object/require.rb} +2 -3
- data/lib/rdoc/{single_class.rb → code_object/single_class.rb} +6 -2
- data/lib/rdoc/{top_level.rb → code_object/top_level.rb} +22 -32
- data/lib/rdoc/code_object.rb +8 -41
- data/lib/rdoc/code_objects.rb +2 -3
- data/lib/rdoc/comment.rb +48 -41
- data/lib/rdoc/cross_reference.rb +77 -33
- data/lib/rdoc/encoding.rb +50 -38
- data/lib/rdoc/erb_partial.rb +2 -3
- data/lib/rdoc/erbio.rb +4 -5
- data/lib/rdoc/generator/darkfish.rb +178 -125
- data/lib/rdoc/generator/json_index.rb +9 -22
- data/lib/rdoc/generator/markup.rb +6 -17
- data/lib/rdoc/generator/pot/message_extractor.rb +4 -4
- data/lib/rdoc/generator/pot/po.rb +3 -3
- data/lib/rdoc/generator/pot/po_entry.rb +12 -12
- data/lib/rdoc/generator/pot.rb +4 -8
- data/lib/rdoc/generator/ri.rb +1 -2
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +35 -12
- data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -5
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +19 -10
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +26 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +4 -9
- data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +27 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
- data/lib/rdoc/generator/template/darkfish/class.rhtml +125 -78
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +430 -339
- data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +13 -13
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -92
- data/lib/rdoc/generator/template/darkfish/js/search.js +35 -34
- data/lib/rdoc/generator/template/darkfish/page.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +10 -8
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +20 -18
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +32 -20
- data/lib/rdoc/generator/template/json_index/js/navigation.js +12 -49
- data/lib/rdoc/generator/template/json_index/js/searcher.js +6 -6
- data/lib/rdoc/generator.rb +6 -6
- data/lib/rdoc/i18n/locale.rb +1 -1
- data/lib/rdoc/i18n/text.rb +5 -5
- data/lib/rdoc/i18n.rb +4 -4
- data/lib/rdoc/known_classes.rb +6 -5
- data/lib/rdoc/markdown/entities.rb +1 -2
- data/lib/rdoc/markdown/literals.kpeg +1 -2
- data/lib/rdoc/markdown/literals.rb +99 -50
- data/lib/rdoc/markdown.kpeg +115 -58
- data/lib/rdoc/markdown.rb +1584 -902
- data/lib/rdoc/markup/attr_changer.rb +1 -2
- data/lib/rdoc/markup/attr_span.rb +9 -4
- data/lib/rdoc/markup/attribute_manager.rb +118 -57
- data/lib/rdoc/markup/attributes.rb +7 -8
- data/lib/rdoc/markup/blank_line.rb +1 -2
- data/lib/rdoc/markup/block_quote.rb +1 -2
- data/lib/rdoc/markup/document.rb +1 -2
- data/lib/rdoc/markup/formatter.rb +44 -37
- data/lib/rdoc/markup/hard_break.rb +1 -2
- data/lib/rdoc/markup/heading.rb +11 -6
- data/lib/rdoc/markup/include.rb +1 -2
- data/lib/rdoc/markup/indented_paragraph.rb +1 -2
- data/lib/rdoc/markup/list.rb +1 -2
- data/lib/rdoc/markup/list_item.rb +1 -2
- data/lib/rdoc/markup/paragraph.rb +1 -2
- data/lib/rdoc/markup/parser.rb +90 -48
- data/lib/rdoc/markup/pre_process.rb +38 -11
- data/lib/rdoc/markup/raw.rb +1 -2
- data/lib/rdoc/markup/regexp_handling.rb +40 -0
- data/lib/rdoc/markup/rule.rb +1 -2
- data/lib/rdoc/markup/table.rb +56 -0
- data/lib/rdoc/markup/to_ansi.rb +1 -2
- data/lib/rdoc/markup/to_bs.rb +30 -5
- data/lib/rdoc/markup/to_html.rb +95 -40
- data/lib/rdoc/markup/to_html_crossref.rb +108 -43
- data/lib/rdoc/markup/to_html_snippet.rb +13 -11
- data/lib/rdoc/markup/to_joined_paragraph.rb +6 -32
- data/lib/rdoc/markup/to_label.rb +11 -12
- data/lib/rdoc/markup/to_markdown.rb +13 -14
- data/lib/rdoc/markup/to_rdoc.rb +49 -31
- data/lib/rdoc/markup/to_table_of_contents.rb +2 -2
- data/lib/rdoc/markup/to_test.rb +1 -2
- data/lib/rdoc/markup/to_tt_only.rb +3 -4
- data/lib/rdoc/markup/verbatim.rb +1 -2
- data/lib/rdoc/markup.rb +64 -694
- data/lib/rdoc/options.rb +226 -44
- data/lib/rdoc/parser/c.rb +231 -246
- data/lib/rdoc/parser/changelog.rb +169 -23
- data/lib/rdoc/parser/markdown.rb +1 -3
- data/lib/rdoc/parser/prism_ruby.rb +1092 -0
- data/lib/rdoc/parser/rd.rb +1 -2
- data/lib/rdoc/parser/ripper_state_lex.rb +302 -0
- data/lib/rdoc/parser/ruby.rb +695 -478
- data/lib/rdoc/parser/ruby_tools.rb +33 -36
- data/lib/rdoc/parser/simple.rb +4 -4
- data/lib/rdoc/parser/text.rb +1 -2
- data/lib/rdoc/parser.rb +37 -42
- data/lib/rdoc/rd/block_parser.rb +708 -57
- data/lib/rdoc/rd/block_parser.ry +15 -11
- data/lib/rdoc/rd/inline.rb +5 -6
- data/lib/rdoc/rd/inline_parser.rb +787 -140
- data/lib/rdoc/rd/inline_parser.ry +1 -1
- data/lib/rdoc/rd.rb +4 -5
- data/lib/rdoc/rdoc.rb +72 -87
- data/lib/rdoc/ri/driver.rb +236 -152
- data/lib/rdoc/ri/formatter.rb +1 -1
- data/lib/rdoc/ri/paths.rb +4 -18
- data/lib/rdoc/ri/store.rb +1 -2
- data/lib/rdoc/ri/task.rb +2 -2
- data/lib/rdoc/ri.rb +5 -6
- data/lib/rdoc/rubygems_hook.rb +98 -20
- data/lib/rdoc/servlet.rb +30 -20
- data/lib/rdoc/stats/normal.rb +24 -18
- data/lib/rdoc/stats/quiet.rb +1 -2
- data/lib/rdoc/stats/verbose.rb +1 -3
- data/lib/rdoc/stats.rb +6 -7
- data/lib/rdoc/store.rb +84 -55
- data/lib/rdoc/task.rb +35 -10
- data/lib/rdoc/text.rb +40 -27
- data/lib/rdoc/token_stream.rb +56 -34
- data/lib/rdoc/tom_doc.rb +18 -19
- data/lib/rdoc/version.rb +10 -0
- data/lib/rdoc.rb +80 -56
- data/lib/rubygems_plugin.rb +23 -0
- data/man/ri.1 +247 -0
- metadata +45 -99
- data/.document +0 -5
- data/.gitignore +0 -13
- data/.travis.yml +0 -24
- data/Gemfile +0 -3
- data/RI.rdoc +0 -57
- data/Rakefile +0 -133
- data/bin/console +0 -7
- data/bin/setup +0 -6
- data/lib/gauntlet_rdoc.rb +0 -82
- data/lib/rdoc/generator/template/darkfish/.document +0 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
- data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
- data/lib/rdoc/generator/template/json_index/.document +0 -1
- data/lib/rdoc/markup/formatter_test_case.rb +0 -764
- data/lib/rdoc/markup/inline.rb +0 -2
- data/lib/rdoc/markup/special.rb +0 -41
- data/lib/rdoc/markup/text_formatter_test_case.rb +0 -115
- data/lib/rdoc/ruby_lex.rb +0 -1367
- data/lib/rdoc/ruby_token.rb +0 -461
- data/lib/rdoc/test_case.rb +0 -204
- data/rdoc.gemspec +0 -57
data/lib/rdoc/ri/driver.rb
CHANGED
@@ -1,23 +1,10 @@
|
|
1
|
-
# frozen_string_literal:
|
2
|
-
require 'abbrev'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
require 'optparse'
|
4
3
|
|
5
|
-
|
6
|
-
require 'readline'
|
7
|
-
rescue LoadError
|
8
|
-
end
|
9
|
-
|
10
|
-
begin
|
11
|
-
require 'win32console'
|
12
|
-
rescue LoadError
|
13
|
-
end
|
14
|
-
|
15
|
-
require 'rdoc'
|
4
|
+
require_relative '../../rdoc'
|
16
5
|
|
17
|
-
|
18
|
-
#
|
19
|
-
|
20
|
-
require 'rdoc/ri/formatter'
|
6
|
+
require_relative 'formatter' # For RubyGems backwards compatibility
|
7
|
+
# TODO: Fix weird documentation with `require_relative`
|
21
8
|
|
22
9
|
##
|
23
10
|
# The RI driver implements the command-line ri tool.
|
@@ -47,13 +34,25 @@ class RDoc::RI::Driver
|
|
47
34
|
|
48
35
|
class NotFoundError < Error
|
49
36
|
|
37
|
+
def initialize(klass, suggestion_proc = nil) # :nodoc:
|
38
|
+
@klass = klass
|
39
|
+
@suggestion_proc = suggestion_proc
|
40
|
+
end
|
41
|
+
|
50
42
|
##
|
51
43
|
# Name that wasn't found
|
52
44
|
|
53
|
-
|
45
|
+
def name
|
46
|
+
@klass
|
47
|
+
end
|
54
48
|
|
55
49
|
def message # :nodoc:
|
56
|
-
"Nothing known about #{
|
50
|
+
str = "Nothing known about #{@klass}"
|
51
|
+
suggestions = @suggestion_proc&.call
|
52
|
+
if suggestions and !suggestions.empty?
|
53
|
+
str += "\nDid you mean? #{suggestions.join("\n ")}"
|
54
|
+
end
|
55
|
+
str
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
@@ -80,7 +79,7 @@ class RDoc::RI::Driver
|
|
80
79
|
options[:interactive] = false
|
81
80
|
options[:profile] = false
|
82
81
|
options[:show_all] = false
|
83
|
-
options[:
|
82
|
+
options[:expand_refs] = true
|
84
83
|
options[:use_stdout] = !$stdout.tty?
|
85
84
|
options[:width] = 72
|
86
85
|
|
@@ -100,7 +99,7 @@ class RDoc::RI::Driver
|
|
100
99
|
def self.dump data_path
|
101
100
|
require 'pp'
|
102
101
|
|
103
|
-
open data_path, 'rb' do |io|
|
102
|
+
File.open data_path, 'rb' do |io|
|
104
103
|
pp Marshal.load(io.read)
|
105
104
|
end
|
106
105
|
end
|
@@ -112,17 +111,13 @@ class RDoc::RI::Driver
|
|
112
111
|
options = default_options
|
113
112
|
|
114
113
|
opts = OptionParser.new do |opt|
|
115
|
-
opt.accept File do |file,|
|
116
|
-
File.readable?(file) and not File.directory?(file) and file
|
117
|
-
end
|
118
|
-
|
119
114
|
opt.program_name = File.basename $0
|
120
115
|
opt.version = RDoc::VERSION
|
121
116
|
opt.release = nil
|
122
117
|
opt.summary_indent = ' ' * 4
|
123
118
|
|
124
119
|
opt.banner = <<-EOT
|
125
|
-
Usage: #{opt.program_name} [options] [
|
120
|
+
Usage: #{opt.program_name} [options] [name ...]
|
126
121
|
|
127
122
|
Where name can be:
|
128
123
|
|
@@ -132,8 +127,10 @@ Where name can be:
|
|
132
127
|
|
133
128
|
gem_name: | gem_name:README | gem_name:History
|
134
129
|
|
135
|
-
|
136
|
-
|
130
|
+
ruby: | ruby:NEWS | ruby:globals
|
131
|
+
|
132
|
+
All class names may be abbreviated to their minimum unambiguous form.
|
133
|
+
If a name is ambiguous, all valid options will be listed.
|
137
134
|
|
138
135
|
A '.' matches either class or instance methods, while #method
|
139
136
|
matches only instance and ::method matches only class methods.
|
@@ -143,6 +140,10 @@ they're contained in. If the gem name is followed by a ':' all files in the
|
|
143
140
|
gem will be shown. The file name extension may be omitted where it is
|
144
141
|
unambiguous.
|
145
142
|
|
143
|
+
'ruby' can be used as a pseudo gem name to display files from the Ruby
|
144
|
+
core documentation. Use 'ruby:' by itself to get a list of all available
|
145
|
+
core documentation files.
|
146
|
+
|
146
147
|
For example:
|
147
148
|
|
148
149
|
#{opt.program_name} Fil
|
@@ -150,24 +151,25 @@ For example:
|
|
150
151
|
#{opt.program_name} File.new
|
151
152
|
#{opt.program_name} zip
|
152
153
|
#{opt.program_name} rdoc:README
|
154
|
+
#{opt.program_name} ruby:comments
|
153
155
|
|
154
|
-
Note that shell quoting or escaping may be required for method names
|
155
|
-
punctuation:
|
156
|
+
Note that shell quoting or escaping may be required for method names
|
157
|
+
containing punctuation:
|
156
158
|
|
157
159
|
#{opt.program_name} 'Array.[]'
|
158
160
|
#{opt.program_name} compact\\!
|
159
161
|
|
160
|
-
To see the default directories
|
162
|
+
To see the default directories #{opt.program_name} will search, run:
|
161
163
|
|
162
164
|
#{opt.program_name} --list-doc-dirs
|
163
165
|
|
164
|
-
Specifying the --system, --site, --home, --gems or --doc-dir options
|
165
|
-
limit ri to searching only the specified directories.
|
166
|
+
Specifying the --system, --site, --home, --gems, or --doc-dir options
|
167
|
+
will limit ri to searching only the specified directories.
|
166
168
|
|
167
|
-
ri options may be set in the
|
169
|
+
ri options may be set in the RI environment variable.
|
168
170
|
|
169
|
-
The ri pager can be set with the
|
170
|
-
|
171
|
+
The ri pager can be set with the RI_PAGER environment variable
|
172
|
+
or the PAGER environment variable.
|
171
173
|
EOT
|
172
174
|
|
173
175
|
opt.separator nil
|
@@ -199,15 +201,15 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
199
201
|
opt.separator nil
|
200
202
|
|
201
203
|
opt.on("--[no-]pager",
|
202
|
-
"Send output
|
203
|
-
"rather than to
|
204
|
+
"Send output to a pager,",
|
205
|
+
"rather than directly to stdout.") do |use_pager|
|
204
206
|
options[:use_stdout] = !use_pager
|
205
207
|
end
|
206
208
|
|
207
209
|
opt.separator nil
|
208
210
|
|
209
211
|
opt.on("-T",
|
210
|
-
"Synonym for --no-pager") do
|
212
|
+
"Synonym for --no-pager.") do
|
211
213
|
options[:use_stdout] = true
|
212
214
|
end
|
213
215
|
|
@@ -220,7 +222,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
220
222
|
|
221
223
|
opt.separator nil
|
222
224
|
|
223
|
-
opt.on("--server
|
225
|
+
opt.on("--server[=PORT]", Integer,
|
224
226
|
"Run RDoc server on the given port.",
|
225
227
|
"The default port is 8214.") do |port|
|
226
228
|
options[:server] = port || 8214
|
@@ -235,13 +237,35 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
235
237
|
formatters -= %w[html label test] # remove useless output formats
|
236
238
|
|
237
239
|
opt.on("--format=NAME", "-f",
|
238
|
-
"
|
240
|
+
"Use the selected formatter. The default",
|
239
241
|
"formatter is bs for paged output and ansi",
|
240
|
-
"otherwise.
|
241
|
-
formatters.join(' '), formatters) do |value|
|
242
|
+
"otherwise. Valid formatters are:",
|
243
|
+
"#{formatters.join(', ')}.", formatters) do |value|
|
242
244
|
options[:formatter] = RDoc::Markup.const_get "To#{value.capitalize}"
|
243
245
|
end
|
244
246
|
|
247
|
+
opt.separator nil
|
248
|
+
|
249
|
+
opt.on("--[no-]expand-refs", "Expand rdoc-refs at the end of output") do |value|
|
250
|
+
options[:expand_refs] = value
|
251
|
+
end
|
252
|
+
|
253
|
+
opt.separator nil
|
254
|
+
|
255
|
+
opt.on("--help", "-h",
|
256
|
+
"Show help and exit.") do
|
257
|
+
puts opts
|
258
|
+
exit
|
259
|
+
end
|
260
|
+
|
261
|
+
opt.separator nil
|
262
|
+
|
263
|
+
opt.on("--version", "-v",
|
264
|
+
"Output version information and exit.") do
|
265
|
+
puts "#{opts.program_name} #{opts.version}"
|
266
|
+
exit
|
267
|
+
end
|
268
|
+
|
245
269
|
opt.separator nil
|
246
270
|
opt.separator "Data source options:"
|
247
271
|
opt.separator nil
|
@@ -273,7 +297,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
273
297
|
"Do not include documentation from",
|
274
298
|
"the Ruby standard library, site_lib,",
|
275
299
|
"installed gems, or ~/.rdoc.",
|
276
|
-
"Use with --doc-dir") do
|
300
|
+
"Use with --doc-dir.") do
|
277
301
|
options[:use_system] = false
|
278
302
|
options[:use_site] = false
|
279
303
|
options[:use_gems] = false
|
@@ -283,8 +307,8 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
283
307
|
opt.separator nil
|
284
308
|
|
285
309
|
opt.on("--[no-]system",
|
286
|
-
"Include documentation from Ruby's
|
287
|
-
"library. Defaults to true.") do |value|
|
310
|
+
"Include documentation from Ruby's",
|
311
|
+
"standard library. Defaults to true.") do |value|
|
288
312
|
options[:use_system] = value
|
289
313
|
end
|
290
314
|
|
@@ -318,19 +342,27 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
318
342
|
opt.separator nil
|
319
343
|
|
320
344
|
opt.on("--[no-]profile",
|
321
|
-
"Run with the ruby profiler") do |value|
|
345
|
+
"Run with the ruby profiler.") do |value|
|
322
346
|
options[:profile] = value
|
323
347
|
end
|
324
348
|
|
325
349
|
opt.separator nil
|
326
350
|
|
327
|
-
opt.on("--dump=CACHE",
|
328
|
-
"
|
329
|
-
|
351
|
+
opt.on("--dump=CACHE",
|
352
|
+
"Dump data from an ri cache or data file.") do |value|
|
353
|
+
unless File.readable?(value)
|
354
|
+
abort "#{value.inspect} is not readable"
|
355
|
+
end
|
356
|
+
|
357
|
+
if File.directory?(value)
|
358
|
+
abort "#{value.inspect} is a directory"
|
359
|
+
end
|
360
|
+
|
361
|
+
options[:dump_path] = File.new(value)
|
330
362
|
end
|
331
363
|
end
|
332
364
|
|
333
|
-
argv = ENV['RI'].to_s.split.concat argv
|
365
|
+
argv = ENV['RI'].to_s.split(' ').concat argv
|
334
366
|
|
335
367
|
opts.parse! argv
|
336
368
|
|
@@ -388,7 +420,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
388
420
|
*options[:extra_doc_dirs]) do |path, type|
|
389
421
|
@doc_dirs << path
|
390
422
|
|
391
|
-
store = RDoc::RI::Store.new path, type
|
423
|
+
store = RDoc::RI::Store.new(RDoc::Options.new, path: path, type: type)
|
392
424
|
store.load_cache
|
393
425
|
@stores << store
|
394
426
|
end
|
@@ -399,9 +431,8 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
399
431
|
@server = options[:server]
|
400
432
|
@use_stdout = options[:use_stdout]
|
401
433
|
@show_all = options[:show_all]
|
402
|
-
|
403
|
-
|
404
|
-
@jruby_pager_process = nil
|
434
|
+
@width = options[:width]
|
435
|
+
@expand_refs = options[:expand_refs]
|
405
436
|
end
|
406
437
|
|
407
438
|
##
|
@@ -487,7 +518,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
487
518
|
with.each do |incl|
|
488
519
|
out << RDoc::Markup::Paragraph.new(incl.name)
|
489
520
|
out << RDoc::Markup::BlankLine.new
|
490
|
-
out << incl.comment
|
521
|
+
out << incl.comment.parse
|
491
522
|
end
|
492
523
|
|
493
524
|
unless wout.empty? then
|
@@ -511,7 +542,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
511
542
|
|
512
543
|
if include.comment then
|
513
544
|
out << RDoc::Markup::BlankLine.new
|
514
|
-
out << include.comment
|
545
|
+
out << include.comment.parse
|
515
546
|
end
|
516
547
|
end
|
517
548
|
|
@@ -526,11 +557,8 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
526
557
|
# Looks up the method +name+ and adds it to +out+
|
527
558
|
|
528
559
|
def add_method out, name
|
529
|
-
filtered
|
530
|
-
|
531
|
-
method_out = method_document name, filtered
|
532
|
-
|
533
|
-
out.concat method_out.parts
|
560
|
+
filtered = lookup_method name
|
561
|
+
method_document out, name, filtered
|
534
562
|
end
|
535
563
|
|
536
564
|
##
|
@@ -582,11 +610,11 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
582
610
|
|
583
611
|
stores = classes[current]
|
584
612
|
|
585
|
-
|
613
|
+
next unless stores and not stores.empty?
|
586
614
|
|
587
|
-
klasses = stores.
|
588
|
-
store.ancestors[current]
|
589
|
-
end.
|
615
|
+
klasses = stores.flat_map do |store|
|
616
|
+
store.ancestors[current] || []
|
617
|
+
end.uniq
|
590
618
|
|
591
619
|
klasses = klasses - seen
|
592
620
|
|
@@ -622,18 +650,19 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
622
650
|
|
623
651
|
add_also_in out, also_in
|
624
652
|
|
653
|
+
expand_rdoc_refs_at_the_bottom(out)
|
625
654
|
out
|
626
655
|
end
|
627
656
|
|
628
657
|
##
|
629
658
|
# Adds the class +comment+ to +out+.
|
630
659
|
|
631
|
-
def class_document_comment out,
|
632
|
-
unless
|
660
|
+
def class_document_comment out, document # :nodoc:
|
661
|
+
unless document.empty? then
|
633
662
|
out << RDoc::Markup::Rule.new(1)
|
634
663
|
|
635
|
-
if
|
636
|
-
parts =
|
664
|
+
if document.merged? then
|
665
|
+
parts = document.parts
|
637
666
|
parts = parts.zip [RDoc::Markup::BlankLine.new] * parts.length
|
638
667
|
parts.flatten!
|
639
668
|
parts.pop
|
@@ -658,7 +687,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
658
687
|
constants = klass.constants.sort_by { |constant| constant.name }
|
659
688
|
|
660
689
|
list.items.concat constants.map { |constant|
|
661
|
-
parts = constant.comment.parts
|
690
|
+
parts = constant.comment.parse.parts
|
662
691
|
parts << RDoc::Markup::Paragraph.new('[not documented]') if
|
663
692
|
parts.empty?
|
664
693
|
|
@@ -725,7 +754,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
725
754
|
complete_klass name, klass, selector, method, completions
|
726
755
|
complete_method name, klass, selector, completions
|
727
756
|
|
728
|
-
completions.sort
|
757
|
+
completions.uniq.select {|s| s.start_with? name }.sort
|
729
758
|
end
|
730
759
|
|
731
760
|
def complete_klass name, klass, selector, method, completions # :nodoc:
|
@@ -760,7 +789,15 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
760
789
|
completions << "#{klass}#{selector}"
|
761
790
|
end
|
762
791
|
|
763
|
-
|
792
|
+
methods.each do |klass_sel_method|
|
793
|
+
match = klass_sel_method.match(/^(.+)(#|\.|::)([^#.:]+)$/)
|
794
|
+
# match[2] is `::` for class method and `#` for instance method.
|
795
|
+
# To be consistent with old completion that completes `['Foo#i', 'Foo::c']` for `Foo.`,
|
796
|
+
# `.` should be a wildcard for both `#` and `::` here.
|
797
|
+
if match && match[2] == selector || selector == '.'
|
798
|
+
completions << match[1] + selector + match[3]
|
799
|
+
end
|
800
|
+
end
|
764
801
|
end
|
765
802
|
end
|
766
803
|
|
@@ -769,7 +806,9 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
769
806
|
|
770
807
|
def display document
|
771
808
|
page do |io|
|
772
|
-
|
809
|
+
f = formatter(io)
|
810
|
+
f.width = @width if @width and f.respond_to?(:width)
|
811
|
+
text = document.accept f
|
773
812
|
|
774
813
|
io.write text
|
775
814
|
end
|
@@ -799,6 +838,8 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
799
838
|
|
800
839
|
add_method out, name
|
801
840
|
|
841
|
+
expand_rdoc_refs_at_the_bottom(out)
|
842
|
+
|
802
843
|
display out
|
803
844
|
end
|
804
845
|
|
@@ -873,7 +914,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
873
914
|
|
874
915
|
page = store.load_page page_name
|
875
916
|
|
876
|
-
display page.comment
|
917
|
+
display page.comment.parse
|
877
918
|
end
|
878
919
|
|
879
920
|
##
|
@@ -902,13 +943,38 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
902
943
|
display out
|
903
944
|
end
|
904
945
|
|
946
|
+
def check_did_you_mean # :nodoc:
|
947
|
+
if defined? DidYouMean::SpellChecker
|
948
|
+
true
|
949
|
+
else
|
950
|
+
begin
|
951
|
+
require 'did_you_mean'
|
952
|
+
if defined? DidYouMean::SpellChecker
|
953
|
+
true
|
954
|
+
else
|
955
|
+
false
|
956
|
+
end
|
957
|
+
rescue LoadError
|
958
|
+
false
|
959
|
+
end
|
960
|
+
end
|
961
|
+
end
|
962
|
+
|
905
963
|
##
|
906
964
|
# Expands abbreviated klass +klass+ into a fully-qualified class. "Zl::Da"
|
907
965
|
# will be expanded to Zlib::DataError.
|
908
966
|
|
909
967
|
def expand_class klass
|
910
|
-
|
911
|
-
|
968
|
+
class_names = classes.keys
|
969
|
+
ary = class_names.grep(Regexp.new("\\A#{klass.gsub(/(?=::|\z)/, '[^:]*')}\\z"))
|
970
|
+
if ary.length != 1 && ary.first != klass
|
971
|
+
if check_did_you_mean
|
972
|
+
suggestion_proc = -> { DidYouMean::SpellChecker.new(dictionary: class_names).correct(klass) }
|
973
|
+
raise NotFoundError.new(klass, suggestion_proc)
|
974
|
+
else
|
975
|
+
raise NotFoundError, klass
|
976
|
+
end
|
977
|
+
end
|
912
978
|
ary.first
|
913
979
|
end
|
914
980
|
|
@@ -990,36 +1056,6 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
990
1056
|
self
|
991
1057
|
end
|
992
1058
|
|
993
|
-
##
|
994
|
-
# Finds the given +pager+ for jruby. Returns an IO if +pager+ was found.
|
995
|
-
#
|
996
|
-
# Returns false if +pager+ does not exist.
|
997
|
-
#
|
998
|
-
# Returns nil if the jruby JVM doesn't support ProcessBuilder redirection
|
999
|
-
# (1.6 and older).
|
1000
|
-
|
1001
|
-
def find_pager_jruby pager
|
1002
|
-
require 'java'
|
1003
|
-
require 'shellwords'
|
1004
|
-
|
1005
|
-
return nil unless java.lang.ProcessBuilder.constants.include? :Redirect
|
1006
|
-
|
1007
|
-
pager = Shellwords.split pager
|
1008
|
-
|
1009
|
-
pb = java.lang.ProcessBuilder.new(*pager)
|
1010
|
-
pb = pb.redirect_output java.lang.ProcessBuilder::Redirect::INHERIT
|
1011
|
-
|
1012
|
-
@jruby_pager_process = pb.start
|
1013
|
-
|
1014
|
-
input = @jruby_pager_process.output_stream
|
1015
|
-
|
1016
|
-
io = input.to_io
|
1017
|
-
io.sync = true
|
1018
|
-
io
|
1019
|
-
rescue java.io.IOException
|
1020
|
-
false
|
1021
|
-
end
|
1022
|
-
|
1023
1059
|
##
|
1024
1060
|
# Finds a store that matches +name+ which can be the name of a gem, "ruby",
|
1025
1061
|
# "home" or "site".
|
@@ -1059,6 +1095,10 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1059
1095
|
def interactive
|
1060
1096
|
puts "\nEnter the method name you want to look up."
|
1061
1097
|
|
1098
|
+
begin
|
1099
|
+
require 'readline'
|
1100
|
+
rescue LoadError
|
1101
|
+
end
|
1062
1102
|
if defined? Readline then
|
1063
1103
|
Readline.completion_proc = method :complete
|
1064
1104
|
puts "You can use tab to autocomplete."
|
@@ -1068,7 +1108,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1068
1108
|
|
1069
1109
|
loop do
|
1070
1110
|
name = if defined? Readline then
|
1071
|
-
Readline.readline ">> "
|
1111
|
+
Readline.readline ">> ", true
|
1072
1112
|
else
|
1073
1113
|
print ">> "
|
1074
1114
|
$stdin.gets
|
@@ -1087,17 +1127,6 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1087
1127
|
exit
|
1088
1128
|
end
|
1089
1129
|
|
1090
|
-
##
|
1091
|
-
# Is +file+ in ENV['PATH']?
|
1092
|
-
|
1093
|
-
def in_path? file
|
1094
|
-
return true if file =~ %r%\A/% and File.exist? file
|
1095
|
-
|
1096
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).any? do |path|
|
1097
|
-
File.exist? File.join(path, file)
|
1098
|
-
end
|
1099
|
-
end
|
1100
|
-
|
1101
1130
|
##
|
1102
1131
|
# Lists classes known to ri starting with +names+. If +names+ is empty all
|
1103
1132
|
# known classes are shown.
|
@@ -1174,7 +1203,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1174
1203
|
# +cache+ indicate if it is a class or instance method.
|
1175
1204
|
|
1176
1205
|
def load_method store, cache, klass, type, name
|
1177
|
-
methods = store.
|
1206
|
+
methods = store.public_send(cache)[klass]
|
1178
1207
|
|
1179
1208
|
return unless methods
|
1180
1209
|
|
@@ -1186,7 +1215,8 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1186
1215
|
|
1187
1216
|
store.load_method klass, "#{type}#{method}"
|
1188
1217
|
rescue RDoc::Store::MissingFileError => e
|
1189
|
-
comment = RDoc::Comment.new("missing documentation at #{e.file}")
|
1218
|
+
comment = RDoc::Comment.new("missing documentation at #{e.file}")
|
1219
|
+
comment.parse
|
1190
1220
|
|
1191
1221
|
method = RDoc::AnyMethod.new nil, name
|
1192
1222
|
method.comment = comment
|
@@ -1220,7 +1250,21 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1220
1250
|
def lookup_method name
|
1221
1251
|
found = load_methods_matching name
|
1222
1252
|
|
1223
|
-
|
1253
|
+
if found.empty?
|
1254
|
+
if check_did_you_mean
|
1255
|
+
methods = []
|
1256
|
+
_, _, method_name = parse_name name
|
1257
|
+
find_methods name do |store, klass, ancestor, types, method|
|
1258
|
+
methods.push(*store.class_methods[klass]) if [:class, :both].include? types
|
1259
|
+
methods.push(*store.instance_methods[klass]) if [:instance, :both].include? types
|
1260
|
+
end
|
1261
|
+
methods = methods.uniq
|
1262
|
+
suggestion_proc = -> { DidYouMean::SpellChecker.new(dictionary: methods).correct(method_name) }
|
1263
|
+
raise NotFoundError.new(name, suggestion_proc)
|
1264
|
+
else
|
1265
|
+
raise NotFoundError, name
|
1266
|
+
end
|
1267
|
+
end
|
1224
1268
|
|
1225
1269
|
filter_methods found, name
|
1226
1270
|
end
|
@@ -1228,9 +1272,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1228
1272
|
##
|
1229
1273
|
# Builds a RDoc::Markup::Document from +found+, +klasses+ and +includes+
|
1230
1274
|
|
1231
|
-
def method_document name, filtered
|
1232
|
-
out = RDoc::Markup::Document.new
|
1233
|
-
|
1275
|
+
def method_document out, name, filtered
|
1234
1276
|
out << RDoc::Markup::Heading.new(1, name)
|
1235
1277
|
out << RDoc::Markup::BlankLine.new
|
1236
1278
|
|
@@ -1278,7 +1320,6 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1278
1320
|
yield pager
|
1279
1321
|
ensure
|
1280
1322
|
pager.close
|
1281
|
-
@jruby_pager_process.wait_for if @jruby_pager_process
|
1282
1323
|
end
|
1283
1324
|
else
|
1284
1325
|
yield $stdout
|
@@ -1335,13 +1376,13 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1335
1376
|
# documentable items the class is added to +also_in+ instead.
|
1336
1377
|
|
1337
1378
|
def render_class out, store, klass, also_in # :nodoc:
|
1338
|
-
|
1379
|
+
document = klass.comment.parse
|
1339
1380
|
# TODO the store's cache should always return an empty Array
|
1340
1381
|
class_methods = store.class_methods[klass.full_name] || []
|
1341
1382
|
instance_methods = store.instance_methods[klass.full_name] || []
|
1342
1383
|
attributes = store.attributes[klass.full_name] || []
|
1343
1384
|
|
1344
|
-
if
|
1385
|
+
if document.empty? and
|
1345
1386
|
instance_methods.empty? and class_methods.empty? then
|
1346
1387
|
also_in << store
|
1347
1388
|
return
|
@@ -1349,7 +1390,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1349
1390
|
|
1350
1391
|
add_from out, store
|
1351
1392
|
|
1352
|
-
class_document_comment out,
|
1393
|
+
class_document_comment out, document
|
1353
1394
|
|
1354
1395
|
if class_methods or instance_methods or not klass.constants.empty? then
|
1355
1396
|
out << RDoc::Markup::Rule.new(1)
|
@@ -1375,7 +1416,13 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1375
1416
|
|
1376
1417
|
render_method_arguments out, method.arglists
|
1377
1418
|
render_method_superclass out, method
|
1378
|
-
|
1419
|
+
if method.is_alias_for
|
1420
|
+
al = method.is_alias_for
|
1421
|
+
alias_for = store.load_method al.parent_name, "#{al.name_prefix}#{al.name}"
|
1422
|
+
render_method_comment out, method, alias_for
|
1423
|
+
else
|
1424
|
+
render_method_comment out, method
|
1425
|
+
end
|
1379
1426
|
end
|
1380
1427
|
|
1381
1428
|
def render_method_arguments out, arglists # :nodoc:
|
@@ -1387,10 +1434,22 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1387
1434
|
out << RDoc::Markup::Rule.new(1)
|
1388
1435
|
end
|
1389
1436
|
|
1390
|
-
def render_method_comment out, method # :nodoc:
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1437
|
+
def render_method_comment out, method, alias_for = nil# :nodoc:
|
1438
|
+
if alias_for
|
1439
|
+
unless method.comment.nil? or method.comment.empty?
|
1440
|
+
out << RDoc::Markup::BlankLine.new
|
1441
|
+
out << method.comment.parse
|
1442
|
+
end
|
1443
|
+
out << RDoc::Markup::BlankLine.new
|
1444
|
+
out << RDoc::Markup::Paragraph.new("(This method is an alias for #{alias_for.full_name}.)")
|
1445
|
+
out << RDoc::Markup::BlankLine.new
|
1446
|
+
out << alias_for.comment.parse
|
1447
|
+
out << RDoc::Markup::BlankLine.new
|
1448
|
+
else
|
1449
|
+
out << RDoc::Markup::BlankLine.new
|
1450
|
+
out << method.comment.parse
|
1451
|
+
out << RDoc::Markup::BlankLine.new
|
1452
|
+
end
|
1394
1453
|
end
|
1395
1454
|
|
1396
1455
|
def render_method_superclass out, method # :nodoc:
|
@@ -1428,27 +1487,14 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1428
1487
|
def setup_pager
|
1429
1488
|
return if @use_stdout
|
1430
1489
|
|
1431
|
-
jruby = RUBY_ENGINE == 'jruby'
|
1432
|
-
|
1433
1490
|
pagers = [ENV['RI_PAGER'], ENV['PAGER'], 'pager', 'less', 'more']
|
1434
1491
|
|
1492
|
+
require 'shellwords'
|
1435
1493
|
pagers.compact.uniq.each do |pager|
|
1436
|
-
|
1437
|
-
|
1438
|
-
pager_cmd = pager.split.first
|
1439
|
-
|
1440
|
-
next unless in_path? pager_cmd
|
1441
|
-
|
1442
|
-
if jruby then
|
1443
|
-
case io = find_pager_jruby(pager)
|
1444
|
-
when nil then break
|
1445
|
-
when false then next
|
1446
|
-
else io
|
1447
|
-
end
|
1448
|
-
else
|
1449
|
-
io = IO.popen(pager, 'w') rescue next
|
1450
|
-
end
|
1494
|
+
pager = Shellwords.split(pager)
|
1495
|
+
next if pager.empty?
|
1451
1496
|
|
1497
|
+
io = IO.popen(pager, 'w') rescue next
|
1452
1498
|
next if $? and $?.pid == io.pid and $?.exited? # pager didn't work
|
1453
1499
|
|
1454
1500
|
@paging = true
|
@@ -1465,7 +1511,11 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1465
1511
|
# Starts a WEBrick server for ri.
|
1466
1512
|
|
1467
1513
|
def start_server
|
1468
|
-
|
1514
|
+
begin
|
1515
|
+
require 'webrick'
|
1516
|
+
rescue LoadError
|
1517
|
+
abort "webrick is not found. You may need to `gem install webrick` to install webrick."
|
1518
|
+
end
|
1469
1519
|
|
1470
1520
|
server = WEBrick::HTTPServer.new :Port => @server
|
1471
1521
|
|
@@ -1479,4 +1529,38 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
|
|
1479
1529
|
server.start
|
1480
1530
|
end
|
1481
1531
|
|
1532
|
+
RDOC_REFS_REGEXP = /\[rdoc-ref:([\w.]+)(@.*)?\]/
|
1533
|
+
|
1534
|
+
def expand_rdoc_refs_at_the_bottom(out)
|
1535
|
+
return unless @expand_refs
|
1536
|
+
|
1537
|
+
extracted_rdoc_refs = []
|
1538
|
+
|
1539
|
+
out.each do |part|
|
1540
|
+
content = if part.respond_to?(:text)
|
1541
|
+
part.text
|
1542
|
+
else
|
1543
|
+
next
|
1544
|
+
end
|
1545
|
+
|
1546
|
+
rdoc_refs = content.scan(RDOC_REFS_REGEXP).uniq.map do |file_name, _anchor|
|
1547
|
+
file_name
|
1548
|
+
end
|
1549
|
+
|
1550
|
+
extracted_rdoc_refs.concat(rdoc_refs)
|
1551
|
+
end
|
1552
|
+
|
1553
|
+
found_pages = extracted_rdoc_refs.map do |ref|
|
1554
|
+
begin
|
1555
|
+
@stores.first.load_page(ref)
|
1556
|
+
rescue RDoc::Store::MissingFileError
|
1557
|
+
end
|
1558
|
+
end.compact
|
1559
|
+
|
1560
|
+
found_pages.each do |page|
|
1561
|
+
out << RDoc::Markup::Heading.new(4, "Expanded from #{page.full_name}")
|
1562
|
+
out << RDoc::Markup::BlankLine.new
|
1563
|
+
out << page.comment.parse
|
1564
|
+
end
|
1565
|
+
end
|
1482
1566
|
end
|