summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-26 20:44:14 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-26 20:44:14 +0000
commit4e23c46ff4c2b6fb8c16a50b7123acb753f7b7d6 (patch)
tree03e7986b60a2ef8aca427d12f0288e8b09339f55 /lib/rdoc
parent74831046c7240243c57efec65c11e2e71a9287f4 (diff)
Merge from HEAD.
Add --system, --site, --home, --gems to ri. Allow --doc-dir to be specified multiple times. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/diagram.rb2
-rw-r--r--lib/rdoc/generators/chm_generator.rb4
-rw-r--r--lib/rdoc/markup/simple_markup/inline.rb4
-rw-r--r--lib/rdoc/markup/simple_markup/preprocess.rb7
-rw-r--r--lib/rdoc/parsers/parse_c.rb2
-rw-r--r--lib/rdoc/ri/ri_display.rb50
-rw-r--r--lib/rdoc/ri/ri_driver.rb19
-rw-r--r--lib/rdoc/ri/ri_formatter.rb2
-rw-r--r--lib/rdoc/ri/ri_options.rb105
-rw-r--r--lib/rdoc/ri/ri_paths.rb39
10 files changed, 151 insertions, 83 deletions
diff --git a/lib/rdoc/diagram.rb b/lib/rdoc/diagram.rb
index 9ae9dd6794..bbaa704365 100644
--- a/lib/rdoc/diagram.rb
+++ b/lib/rdoc/diagram.rb
@@ -295,7 +295,7 @@ module RDoc
f << graph.to_s << "\n"
end
- system "dot -T#{op_type} #{src} -o #{dot}"
+ system "dot", "-T#{op_type}", src, "-o", dot
# Now construct the imagemap wrapper around
# that png
diff --git a/lib/rdoc/generators/chm_generator.rb b/lib/rdoc/generators/chm_generator.rb
index 1c46769cc2..51eeda8dd1 100644
--- a/lib/rdoc/generators/chm_generator.rb
+++ b/lib/rdoc/generators/chm_generator.rb
@@ -4,7 +4,7 @@ module Generators
class CHMGenerator < HTMLGenerator
- HHC_PATH = "c:\\Program Files\\HTML Help Workshop\\hhc.exe"
+ HHC_PATH = "c:/Program Files/HTML Help Workshop/hhc.exe"
# Standard generator factory
def CHMGenerator.for(options)
@@ -103,7 +103,7 @@ module Generators
# Invoke the windows help compiler to compiler the project
def compile_project
- system("\"#{HHC_PATH}\" #@project_name")
+ system(HHC_PATH, @project_name)
end
end
diff --git a/lib/rdoc/markup/simple_markup/inline.rb b/lib/rdoc/markup/simple_markup/inline.rb
index 1e76c201c9..d54fe1e667 100644
--- a/lib/rdoc/markup/simple_markup/inline.rb
+++ b/lib/rdoc/markup/simple_markup/inline.rb
@@ -183,7 +183,7 @@ module SM
unless SPECIAL.empty?
SPECIAL.each do |regexp, attr|
str.scan(regexp) do
- attrs.set_attrs($`.length, $1.length, attr | Attribute::SPECIAL)
+ attrs.set_attrs($`.length, $&.length, attr | Attribute::SPECIAL)
end
end
end
@@ -215,6 +215,8 @@ module SM
add_html("b", :BOLD)
add_html("tt", :TT)
add_html("code", :TT)
+
+ add_special(/<!--(.*?)-->/, :COMMENT)
end
def add_word_pair(start, stop, name)
diff --git a/lib/rdoc/markup/simple_markup/preprocess.rb b/lib/rdoc/markup/simple_markup/preprocess.rb
index bbbae1b77c..101c9bdeb1 100644
--- a/lib/rdoc/markup/simple_markup/preprocess.rb
+++ b/lib/rdoc/markup/simple_markup/preprocess.rb
@@ -43,7 +43,12 @@ module SM
def include_file(name, indent)
if (full_name = find_include_file(name))
content = File.open(full_name) {|f| f.read}
- res = content.gsub(/^#?/, indent)
+ # strip leading '#'s, but only if all lines start with them
+ if content =~ /^[^#]/
+ content.gsub(/^/, indent)
+ else
+ content.gsub(/^#?/, indent)
+ end
else
$stderr.puts "Couldn't find file to include: '#{name}'"
''
diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb
index e6c18cb0ff..89d36c6c50 100644
--- a/lib/rdoc/parsers/parse_c.rb
+++ b/lib/rdoc/parsers/parse_c.rb
@@ -262,7 +262,7 @@ module RDoc
def find_class_comment(class_name, class_meth)
comment = nil
if @body =~ %r{((?>/\*.*?\*/\s+))
- (static\s+)?void\s+Init_#{class_name}\s*\(\)}xmi
+ (static\s+)?void\s+Init_#{class_name}\s*(?:_\(\s*)?\(\s*(?:void\s*)\)}xmi
comment = $1
elsif @body =~ %r{Document-(class|module):\s#{class_name}\s*?\n((?>.*?\*/))}m
comment = $2
diff --git a/lib/rdoc/ri/ri_display.rb b/lib/rdoc/ri/ri_display.rb
index 076df46b17..67962fc2c1 100644
--- a/lib/rdoc/ri/ri_display.rb
+++ b/lib/rdoc/ri/ri_display.rb
@@ -194,12 +194,15 @@ class DefaultDisplay
######################################################################
def page
- setup_pager
+ return yield unless pager = setup_pager
begin
+ save_stdout = STDOUT.clone
+ STDOUT.reopen(pager)
yield
- page_output
ensure
- STDOUT.reopen(@save_stdout) if @save_stdout
+ STDOUT.reopen(save_stdout)
+ save_stdout.close
+ pager.close
end
end
@@ -207,31 +210,11 @@ class DefaultDisplay
def setup_pager
unless @options.use_stdout
- require 'tempfile'
-
- @save_stdout = STDOUT.clone
- STDOUT.reopen(Tempfile.new("ri_"))
- end
- end
-
- ######################################################################
-
- def page_output
- unless @options.use_stdout
- path = STDOUT.path
- STDOUT.reopen(@save_stdout)
- @save_stdout = nil
- paged = false
- for pager in [ ENV['PAGER'], "less", "more <", 'pager' ].compact.uniq
- if system("#{pager} #{path}")
- paged = true
- break
- end
- end
- if !paged
- @options.use_stdout = true
- puts File.read(path)
+ for pager in [ ENV['PAGER'], "less", "more", 'pager' ].compact.uniq
+ return IO.popen(pager, "w") rescue nil
end
+ @options.use_stdout = true
+ nil
end
end
@@ -255,12 +238,6 @@ class DefaultDisplay
end
######################################################################
- def warn_no_database
- puts "Before using ri, you need to generate documentation"
- puts "using 'rdoc' with the --ri option"
- end
- ######################################################################
-
def display_flow(flow)
if !flow || flow.empty?
@formatter.wrap("(no description...)")
@@ -269,5 +246,10 @@ class DefaultDisplay
end
end
-
+ ######################################################################
+
+ def warn_no_database
+ puts "Before using ri, you need to generate documentation"
+ puts "using 'rdoc' with the --ri option"
+ end
end # class RiDisplay
diff --git a/lib/rdoc/ri/ri_driver.rb b/lib/rdoc/ri/ri_driver.rb
index d2545bb1da..6a1b082528 100644
--- a/lib/rdoc/ri/ri_driver.rb
+++ b/lib/rdoc/ri/ri_driver.rb
@@ -1,5 +1,6 @@
require 'rdoc/usage'
require 'rdoc/ri/ri_paths'
+require 'rdoc/usage'
require 'rdoc/ri/ri_cache'
require 'rdoc/ri/ri_util'
require 'rdoc/ri/ri_reader'
@@ -21,20 +22,18 @@ class RiDriver
@options.parse(args)
- paths = @options.paths || RI::Paths::PATH
- if paths.empty?
- report_missing_documentation(paths)
- end
- @ri_reader = RI::RiReader.new(RI::RiCache.new(paths))
+ path = @options.path
+ report_missing_documentation @options.raw_path if path.empty?
+
+ @ri_reader = RI::RiReader.new(RI::RiCache.new(path))
@display = @options.displayer
- end
+ end
- # Couldn't find documentation in paths, so tell the user
- # what to do
+ # Couldn't find documentation in +path+, so tell the user what to do
- def report_missing_documentation(paths)
+ def report_missing_documentation(path)
STDERR.puts "No ri documentation found in:"
- paths.each do |d|
+ path.each do |d|
STDERR.puts " #{d}"
end
STDERR.puts "\nWas rdoc run to create documentation?\n\n"
diff --git a/lib/rdoc/ri/ri_formatter.rb b/lib/rdoc/ri/ri_formatter.rb
index 745ae292ee..56a1fb4665 100644
--- a/lib/rdoc/ri/ri_formatter.rb
+++ b/lib/rdoc/ri/ri_formatter.rb
@@ -43,7 +43,7 @@ module RI
end
end
res << work if work.length.nonzero?
- puts(prefix + res.join("\n" + next_prefix))
+ puts(prefix + res.join("\n" + next_prefix))
end
######################################################################
diff --git a/lib/rdoc/ri/ri_options.rb b/lib/rdoc/ri/ri_options.rb
index 5ee9a45588..91a28e1ab4 100644
--- a/lib/rdoc/ri/ri_options.rb
+++ b/lib/rdoc/ri/ri_options.rb
@@ -37,23 +37,41 @@ module RI
OPTION_LIST = [
[ "--help", "-h", nil,
- "you're looking at it" ],
+ "you're looking at it" ],
[ "--classes", "-c", nil,
"Display the names of classes and modules we\n" +
"know about"],
[ "--doc-dir", "-d", "<dirname>",
- "A directory to search for documentation. If not\n"+
- "specified, we search the standard rdoc/ri directories."],
+ "A directory to search for documentation. If not\n" +
+ "specified, we search the standard rdoc/ri directories.\n" +
+ "May be repeated."],
+
+ [ "--system", nil, nil,
+ "Include documentation from Ruby's standard library:\n " +
+ RI::Paths::SYSDIR ],
+
+ [ "--site", nil, nil,
+ "Include documentation from libraries installed in site_lib:\n " +
+ RI::Paths::SITEDIR ],
+
+ [ "--home", nil, nil,
+ "Include documentation stored in ~/.rdoc:\n " +
+ (RI::Paths::HOMEDIR || "No ~/.rdoc found") ],
+
+ [ "--gems", nil, nil,
+ "Include documentation from Rubygems:\n " +
+ (RI::Paths::GEMDIRS ? "#{Gem.path}/doc/*/ri" :
+ "No Rubygems ri found.") ],
[ "--format", "-f", "<name>",
- "Format to use when displaying output:\n" +
- " " + RI::TextFormatter.list + "\n" +
- "Use 'bs' (backspace) with most pager programs.\n" +
- "To use ANSI, either also use the -T option, or\n" +
- "tell your pager to allow control characters\n" +
- "(for example using the -R option to less)"],
+ "Format to use when displaying output:\n" +
+ " " + RI::TextFormatter.list + "\n" +
+ "Use 'bs' (backspace) with most pager programs.\n" +
+ "To use ANSI, either also use the -T option, or\n" +
+ "tell your pager to allow control characters\n" +
+ "(for example using the -R option to less)"],
[ "--list-names", "-l", nil,
"List all the names known to RDoc, one per line"
@@ -74,10 +92,12 @@ module RI
def OptionList.options
OPTION_LIST.map do |long, short, arg,|
- [ long,
- short,
- arg ? GetoptLong::REQUIRED_ARGUMENT : GetoptLong::NO_ARGUMENT
- ]
+ option = []
+ option << long
+ option << short unless short.nil?
+ option << (arg ? GetoptLong::REQUIRED_ARGUMENT :
+ GetoptLong::NO_ARGUMENT)
+ option
end
end
@@ -108,6 +128,17 @@ module RI
puts
name = File.basename($0)
+
+ directories = [
+ RI::Paths::SYSDIR,
+ RI::Paths::SITEDIR,
+ RI::Paths::HOMEDIR
+ ]
+
+ directories << "#{Gem.path}/doc/*/ri" if RI::Paths::GEMDIRS
+
+ directories = directories.join("\n ")
+
OptionList.strip_output(<<-EOT)
Usage:
@@ -136,6 +167,15 @@ module RI
ri 'Array.[]'
ri compact\\!
+ By default ri searches for documentation in the following
+ directories:
+
+ #{directories}
+
+ Specifying the --system, --site, --home, --gems or --doc-dir
+ options will limit ri to searching only the specified
+ directories.
+
EOT
if short_form
@@ -144,7 +184,9 @@ module RI
else
puts "Options:\n\n"
OPTION_LIST.each do|long, short, arg, desc|
- opt = sprintf("%15s", "#{long}, #{short}")
+ opt = ''
+ opt << (short ? sprintf("%15s", "#{long}, #{short}") :
+ sprintf("%15s", long))
if arg
opt << " " << arg
end
@@ -173,26 +215,29 @@ module RI
exit(0)
end
-
def initialize
@use_stdout = !STDOUT.tty?
@width = 72
@formatter = RI::TextFormatter.for("plain")
@list_classes = false
@list_names = false
- end
+ # By default all paths are used. If any of these are true, only those
+ # directories are used.
+ @use_system = false
+ @use_site = false
+ @use_home = false
+ @use_gems = false
+ @doc_dirs = []
+ end
# Parse command line options.
def parse(args)
old_argv = ARGV.dup
-# if ENV["RI"]
-# ARGV.replace(ENV["RI"].split.concat(ARGV))
-# end
- ARGV.replace(args)
+ ARGV.replace(args)
begin
@@ -206,9 +251,15 @@ module RI
when "--list-names" then @list_names = true
when "--no-pager" then @use_stdout = true
when "--classes" then @list_classes = true
+
+ when "--system" then @use_system = true
+ when "--site" then @use_site = true
+ when "--home" then @use_home = true
+ when "--gems" then @use_gems = true
+
when "--doc-dir"
if File.directory?(arg)
- @doc_dir = arg
+ @doc_dirs << arg
else
$stderr.puts "Invalid directory: #{arg}"
exit 1
@@ -237,9 +288,15 @@ module RI
end
end
- # Return the doc_dir as an array, or nil if no overriding doc dir was given
- def paths
- defined?(@doc_dir) ? [ @doc_dir ] : nil
+ # Return the selected documentation directories.
+
+ def path
+ RI::Paths.path(@use_system, @use_site, @use_home, @use_gems, *@doc_dirs)
+ end
+
+ def raw_path
+ RI::Paths.raw_path(@use_system, @use_site, @use_home, @use_gems,
+ *@doc_dirs)
end
# Return an instance of the displayer (the thing that actually writes
diff --git a/lib/rdoc/ri/ri_paths.rb b/lib/rdoc/ri/ri_paths.rb
index 07d900238f..32363bf70a 100644
--- a/lib/rdoc/ri/ri_paths.rb
+++ b/lib/rdoc/ri/ri_paths.rb
@@ -29,13 +29,7 @@ module RI
version = Config::CONFIG['ruby_version']
base = File.join(Config::CONFIG['datadir'], "ri", version)
-
- if ENV["DESTDIR"]
- SYSDIR = File.join(ENV["DESTDIR"], base, "system")
- else
- SYSDIR = File.join(base, "system")
- end
-
+ SYSDIR = File.join(base, "system")
SITEDIR = File.join(base, "site")
homedir = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
@@ -50,8 +44,37 @@ module RI
begin
require 'rubygems'
- Dir["#{Gem.path}/doc/*/ri"].each { |path| RI::Paths::PATH << path }
+ GEMDIRS = Dir["#{Gem.path}/doc/*/ri"]
+ GEMDIRS.each { |path| RI::Paths::PATH << path }
rescue LoadError
+ GEMDIRS = nil
+ end
+
+ # Returns the selected documentation directories as an Array, or PATH if no
+ # overriding directories were given.
+
+ def self.path(use_system, use_site, use_home, use_gems, *extra_dirs)
+ path = raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
+ return path.select { |path| File.directory? path }
end
+
+ # Returns the selected documentation directories including nonexistent
+ # directories. Used to print out what paths were searched if no ri was
+ # found.
+
+ def self.raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
+ return PATH unless use_system or use_site or use_home or use_gems or
+ not extra_dirs.empty?
+
+ path = []
+ path << extra_dirs unless extra_dirs.empty?
+ path << RI::Paths::SYSDIR if use_system
+ path << RI::Paths::SITEDIR if use_site
+ path << RI::Paths::HOMEDIR if use_home
+ path << RI::Paths::GEMDIRS if use_gems
+
+ return path.flatten.compact
+ end
+
end
end