summaryrefslogtreecommitdiff
path: root/lib/rdoc/ri
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-20 03:22:49 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-20 03:22:49 +0000
commit2ef9c50c6e405717d06362787c4549ca4f1c6485 (patch)
treeee99486567461dd5796f3d6edcc9e204187f2666 /lib/rdoc/ri
parentd7effd506f5b91a636f2e6452ef1946b923007c7 (diff)
Import RDoc 3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/ri')
-rw-r--r--lib/rdoc/ri/driver.rb68
-rw-r--r--lib/rdoc/ri/paths.rb15
-rw-r--r--lib/rdoc/ri/store.rb25
3 files changed, 76 insertions, 32 deletions
diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb
index f3fd9539e3..9d61b1f243 100644
--- a/lib/rdoc/ri/driver.rb
+++ b/lib/rdoc/ri/driver.rb
@@ -6,6 +6,11 @@ begin
rescue LoadError
end
+begin
+ require 'win32console'
+rescue LoadError
+end
+
require 'rdoc/ri'
require 'rdoc/ri/paths'
require 'rdoc/markup'
@@ -55,6 +60,9 @@ class RDoc::RI::Driver
end
end
+ ##
+ # An RDoc::RI::Store for each entry in the RI path
+
attr_accessor :stores
##
@@ -97,23 +105,10 @@ class RDoc::RI::Driver
##
# Parses +argv+ and returns a Hash of options
- def self.process_args argv = []
+ def self.process_args argv
options = default_options
- opts = OptionParser.new
- setup_options(opts, options)
- argv = ENV['RI'].to_s.split.concat argv
- opts.parse!(argv)
-
- fixup_options(options, argv)
-
- rescue OptionParser::ParseError => e
- puts opts, nil, e
- abort
- end
-
- def self.setup_options(opt, options)
- begin
+ opts = OptionParser.new do |opt|
opt.accept File do |file,|
File.readable?(file) and not File.directory?(file) and file
end
@@ -133,7 +128,7 @@ Where name can be:
All class names may be abbreviated to their minimum unambiguous form. If a name
is ambiguous, all valid options will be listed.
-The form '.' method matches either class or instance methods, while #method
+A '.' matches either class or instance methods, while #method
matches only instance and ::method matches only class methods.
For example:
@@ -143,7 +138,7 @@ For example:
#{opt.program_name} File.new
#{opt.program_name} zip
-Note that shell quoting may be required for method names containing
+Note that shell quoting or escaping may be required for method names containing
punctuation:
#{opt.program_name} 'Array.[]'
@@ -287,9 +282,11 @@ Options may also be set in the 'RI' environment variable.
options[:dump_path] = value
end
end
- end
- def self.fixup_options(options, argv)
+ argv = ENV['RI'].to_s.split.concat argv
+
+ opts.parse! argv
+
options[:names] = argv
options[:use_stdout] ||= !$stdout.tty?
@@ -297,6 +294,12 @@ Options may also be set in the 'RI' environment variable.
options[:width] ||= 72
options
+
+ rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
+ puts opts
+ puts
+ puts e
+ exit 1
end
##
@@ -359,7 +362,7 @@ Options may also be set in the 'RI' environment variable.
paths = RDoc::Markup::Verbatim.new
also_in.each do |store|
- paths.parts.push ' ', store.friendly_path, "\n"
+ paths.parts.push store.friendly_path, "\n"
end
out << paths
end
@@ -427,7 +430,7 @@ Options may also be set in the 'RI' environment variable.
verb = RDoc::Markup::Verbatim.new
wout.each do |incl|
- verb.push ' ', incl.name, "\n"
+ verb.push incl.name, "\n"
end
out << verb
@@ -446,7 +449,7 @@ Options may also be set in the 'RI' environment variable.
out << RDoc::Markup::BlankLine.new
out.push(*methods.map do |method|
- RDoc::Markup::Verbatim.new ' ', method
+ RDoc::Markup::Verbatim.new method
end)
out << RDoc::Markup::BlankLine.new
@@ -664,8 +667,8 @@ Options may also be set in the 'RI' environment variable.
if method.arglists then
arglists = method.arglists.chomp.split "\n"
- arglists = arglists.map { |line| [' ', line, "\n"] }
- out << RDoc::Markup::Verbatim.new(*arglists.flatten)
+ arglists = arglists.map { |line| line + "\n" }
+ out << RDoc::Markup::Verbatim.new(*arglists)
out << RDoc::Markup::Rule.new(1)
end
@@ -847,6 +850,17 @@ Options may also be set in the 'RI' environment variable.
end
##
+ # Is +file+ in ENV['PATH']?
+
+ def in_path? file
+ return true if file =~ %r%\A/% and File.exist? file
+
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? do |path|
+ File.exist? File.join(path, file)
+ end
+ end
+
+ ##
# Lists classes known to ri
def list_known_classes
@@ -1041,7 +1055,11 @@ Options may also be set in the 'RI' environment variable.
pagers.compact.uniq.each do |pager|
next unless pager
- io = IO.popen pager, "w" rescue next
+ pager_cmd = pager.split.first
+
+ next unless in_path? pager_cmd
+
+ io = IO.popen(pager, 'w') rescue next
next if $? and $?.exited? # pager didn't work
diff --git a/lib/rdoc/ri/paths.rb b/lib/rdoc/ri/paths.rb
index 9b338d7ad8..ec4d16b857 100644
--- a/lib/rdoc/ri/paths.rb
+++ b/lib/rdoc/ri/paths.rb
@@ -10,10 +10,21 @@ module RDoc::RI::Paths
version = RbConfig::CONFIG['ruby_version']
- base = File.join RbConfig::CONFIG['ridir'], version
+ base = if RbConfig::CONFIG.key? 'ridir' then
+ File.join RbConfig::CONFIG['ridir'], version
+ else
+ File.join RbConfig::CONFIG['datadir'], 'ri', version
+ end
+
SYSDIR = File.join base, "system"
SITEDIR = File.join base, "site"
- HOMEDIR = (File.expand_path('~/.rdoc') rescue nil)
+
+ homedir = File.expand_path('~') ||
+ ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
+
+ HOMEDIR = if homedir then
+ File.join homedir, ".rdoc"
+ end
#:startdoc:
@gemdirs = nil
diff --git a/lib/rdoc/ri/store.rb b/lib/rdoc/ri/store.rb
index db02202f81..1fcd313d0f 100644
--- a/lib/rdoc/ri/store.rb
+++ b/lib/rdoc/ri/store.rb
@@ -11,6 +11,11 @@ require 'fileutils'
class RDoc::RI::Store
##
+ # If true this Store will not write any files
+
+ attr_accessor :dry_run
+
+ ##
# Path this store reads or writes
attr_accessor :path
@@ -21,14 +26,18 @@ class RDoc::RI::Store
attr_accessor :type
+ ##
+ # The contents of the Store
+
attr_reader :cache
##
# Creates a new Store of +type+ that will load or save to +path+
def initialize path, type = nil
- @type = type
- @path = path
+ @dry_run = false
+ @type = type
+ @path = path
@cache = {
:class_methods => {},
@@ -178,6 +187,8 @@ class RDoc::RI::Store
@cache[:instance_methods].each do |_, m| m.uniq!; m.sort! end
@cache[:modules].uniq!; @cache[:modules].sort!
+ return if @dry_run
+
open cache_path, 'wb' do |io|
Marshal.dump @cache, io
end
@@ -187,7 +198,7 @@ class RDoc::RI::Store
# Writes the ri data for +klass+
def save_class klass
- FileUtils.mkdir_p class_path(klass.full_name)
+ FileUtils.mkdir_p class_path(klass.full_name) unless @dry_run
@cache[:modules] << klass.full_name
@@ -214,7 +225,7 @@ class RDoc::RI::Store
@cache[:ancestors][klass.full_name].push(*ancestors)
attributes = klass.attributes.map do |attribute|
- "#{attribute.type} #{attribute.name}"
+ "#{attribute.definition} #{attribute.name}"
end
unless attributes.empty? then
@@ -222,6 +233,8 @@ class RDoc::RI::Store
@cache[:attributes][klass.full_name].push(*attributes)
end
+ return if @dry_run
+
open path, 'wb' do |io|
Marshal.dump klass, io
end
@@ -231,7 +244,7 @@ class RDoc::RI::Store
# Writes the ri data for +method+ on +klass+
def save_method klass, method
- FileUtils.mkdir_p class_path(klass.full_name)
+ FileUtils.mkdir_p class_path(klass.full_name) unless @dry_run
cache = if method.singleton then
@cache[:class_methods]
@@ -241,6 +254,8 @@ class RDoc::RI::Store
cache[klass.full_name] ||= []
cache[klass.full_name] << method.name
+ return if @dry_run
+
open method_file(klass.full_name, method.full_name), 'wb' do |io|
Marshal.dump method, io
end