mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00

Synchronize rdoc with upstream version v6.3.1. [ruby/rdoc] Use File.open to fix the OS Command Injection vulnerability in CVE-2021-31799 https://github.com/ruby/rdoc/commit/a7f5d6ab88 --- lib/rdoc/rdoc.rb | 2 +- test/rdoc/test_rdoc_rdoc.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) [ruby/rdoc] Support ChangeLog generated by `git log` https://github.com/ruby/rdoc/commit/5e0a123ca1 --- lib/rdoc/parser/changelog.rb | 35 +++++++++++++++++++++ test/rdoc/test_rdoc_parser_changelog.rb | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) [ruby/rdoc] Make each commit entries h3 https://github.com/ruby/rdoc/commit/11eefb2ae9 --- lib/rdoc/parser/changelog.rb | 12 ++++++------ test/rdoc/test_rdoc_parser_changelog.rb | 12 ++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) [ruby/rdoc] Tweak log entry markdown * add 3 levels to headings * prefix commit log to labels to make unique IDs https://github.com/ruby/rdoc/commit/5074c13209 --- lib/rdoc/parser/changelog.rb | 20 +++++++++++++++++- test/rdoc/test_rdoc_parser_changelog.rb | 36 ++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) [ruby/rdoc] Shorten commit hashes https://github.com/ruby/rdoc/commit/5d3e153963 --- lib/rdoc/parser/changelog.rb | 2 +- test/rdoc/test_rdoc_parser_changelog.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) [ruby/rdoc] Add links to the commits https://github.com/ruby/rdoc/commit/1821628076 --- lib/rdoc/parser/changelog.rb | 107 +++++++++++++++++++++++++------- test/rdoc/test_rdoc_parser_changelog.rb | 36 ++++++----- 2 files changed, 107 insertions(+), 36 deletions(-) [ruby/rdoc] Sort by CommitDate if available https://github.com/ruby/rdoc/commit/455715e930 --- lib/rdoc/parser/changelog.rb | 11 ++++++--- test/rdoc/test_rdoc_parser_changelog.rb | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) [ruby/rdoc] Skip non-date logs by git-log `RDoc::Parser::ChangeLog` mis-parses ChangeLog generated by git-log, because of too heuristic `Time.parse`. For instance, "commit 8187228de0142d3ac7950b7d977c2849e934c637" results in "8187-08-16", that is, day 228 in the year 8187. https://github.com/ruby/rdoc/commit/9711e6f6d9 --- lib/rdoc/parser/changelog.rb | 36 ++++++++++++++++++++------------- test/rdoc/test_rdoc_parser_changelog.rb | 2 ++ 2 files changed, 24 insertions(+), 14 deletions(-) [ruby/rdoc] Support other date formats in git-log https://github.com/ruby/rdoc/commit/ad8cf37d72 --- lib/rdoc/parser/changelog.rb | 6 +++--- test/rdoc/test_rdoc_parser_changelog.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) [ruby/rdoc] Support iso-strict format in git-log https://github.com/ruby/rdoc/commit/2a6c22da63 --- lib/rdoc/parser/changelog.rb | 6 +++--- test/rdoc/test_rdoc_parser_changelog.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) [ruby/rdoc] Update Rdoc.css sidebar panel. Updates css so the sidebar look like a panel instead of looking like chopped edges. https://github.com/ruby/rdoc/commit/b0098c6d72 --- lib/rdoc/generator/template/darkfish/css/rdoc.css | 1 + 1 file changed, 1 insertion(+) [ruby/rdoc] Support GFM table https://github.com/ruby/rdoc/commit/9dc933df16 --- lib/rdoc/markdown.rb | 349 +++++++++++++++++++++++++++++++- lib/rdoc/markup.rb | 1 + lib/rdoc/markup/table.rb | 47 +++++ lib/rdoc/markup/to_html.rb | 23 +++ lib/rdoc/markup/to_joined_paragraph.rb | 1 + lib/rdoc/markup/to_rdoc.rb | 28 +++ lib/rdoc/markup/to_table_of_contents.rb | 1 + test/rdoc/test_rdoc_markdown.rb | 23 +++ 8 files changed, 471 insertions(+), 2 deletions(-) create mode 100644 lib/rdoc/markup/table.rb [ruby/rdoc] Add table style https://github.com/ruby/rdoc/commit/2219c5ae80 --- lib/rdoc/generator/template/darkfish/css/rdoc.css | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) [ruby/rdoc] Fixed CodeFence without blank lines Currently a fenced code block needs a preceding blank line, it should not be required, as: https://github.github.com/gfm/#fenced-code-blocks > A fenced code block may interrupt a paragraph, and does not > require a blank line either before or after. Just recommended: https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks > We recommend placing a blank line before and after code blocks > to make the raw formatting easier to read. https://github.com/ruby/rdoc/commit/0e1776caf3 --- lib/rdoc/markdown.rb | 447 +++++++--------------------------------- test/rdoc/test_rdoc_markdown.rb | 36 +++- 2 files changed, 112 insertions(+), 371 deletions(-) [ruby/rdoc] Allow partial default values to be overridden with .rdoc_options https://github.com/ruby/rdoc/commit/e14800891f --- lib/rdoc/options.rb | 34 +++++++++++++++++++++++++++++++++- lib/rdoc/rdoc.rb | 7 ++++++- test/rdoc/test_rdoc_rdoc.rb | 12 ++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) [ruby/rdoc] Allow empty .rdoc_options https://github.com/ruby/rdoc/commit/0c8cb25b50 --- lib/rdoc/rdoc.rb | 2 ++ test/rdoc/test_rdoc_rdoc.rb | 11 +++++++++++ 2 files changed, 13 insertions(+) [ruby/rdoc] Suppress unused variable warning of "text" https://github.com/ruby/rdoc/commit/3a4120b155 --- lib/rdoc/markdown.rb | 345 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 343 insertions(+), 2 deletions(-) [ruby/rdoc] Get rid of a trailing space https://github.com/ruby/rdoc/commit/7b7b91768e --- lib/rdoc/markdown.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) [ruby/rdoc] Disable other notations in <code> tags https://github.com/ruby/rdoc/commit/0cd3b55210 --- lib/rdoc/markup/attr_span.rb | 10 ++- lib/rdoc/markup/attribute_manager.rb | 102 ++++++++++++++++++------ test/rdoc/test_rdoc_markup_attribute_manager.rb | 24 +++++- test/rdoc/test_rdoc_markup_to_html.rb | 6 ++ 4 files changed, 114 insertions(+), 28 deletions(-) [ruby/rdoc] Treat other tags as word boundaries https://github.com/ruby/rdoc/commit/8222f85a17 --- lib/rdoc/markup/attribute_manager.rb | 17 +++++++++++++---- test/rdoc/test_rdoc_markup_to_html.rb | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) [ruby/rdoc] Treat emphasis tags as excluding other notations And exclusive notations don't exclude other exclusive notations. https://github.com/ruby/rdoc/commit/b8baa9a435 --- lib/rdoc/markup/attr_span.rb | 2 +- lib/rdoc/markup/attribute_manager.rb | 10 +++++----- test/rdoc/test_rdoc_markup_attribute_manager.rb | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) [ruby/rdoc] Clarify that dots in URL are replaced The dots in all path components from the document root are replaced with underscores, not only in the basename. https://github.com/ruby/rdoc/commit/7a3417ea4c --- test/rdoc/test_rdoc_top_level.rb | 3 +++ 1 file changed, 3 insertions(+) [ruby/rdoc] Links to document texts without "rdoc-ref:" prefix While links to generated HTML from RDoc file needs to be prefixed by "rdoc-ref:" currently, in case of explicit references this seems just redundant. Also GitHub RDoc support does not work with this prefix. This patch lets links to such document texts (".rb", ".rdoc" and ".md" now) refer URLs generated by `RDoc::TopLevel#http_url` without the prefix. https://github.com/ruby/rdoc/commit/f18b27b69d --- lib/rdoc/markup/to_html.rb | 4 ++++ test/rdoc/test_rdoc_markup_to_html.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) [ruby/rdoc] Use File.open to fix the OS Command Injection vulnerability in CVE-2021-31799 https://github.com/ruby/rdoc/commit/a7f5d6ab88 --- lib/rdoc/rdoc.rb | 2 +- test/rdoc/test_rdoc_rdoc.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) [ruby/rdoc] Version 6.3.1 https://github.com/ruby/rdoc/commit/9307f932b7 --- lib/rdoc/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
579 lines
14 KiB
Ruby
579 lines
14 KiB
Ruby
# frozen_string_literal: true
|
|
require 'rdoc'
|
|
|
|
require 'find'
|
|
require 'fileutils'
|
|
require 'pathname'
|
|
require 'time'
|
|
|
|
##
|
|
# This is the driver for generating RDoc output. It handles file parsing and
|
|
# generation of output.
|
|
#
|
|
# To use this class to generate RDoc output via the API, the recommended way
|
|
# is:
|
|
#
|
|
# rdoc = RDoc::RDoc.new
|
|
# options = rdoc.load_options # returns an RDoc::Options instance
|
|
# # set extra options
|
|
# rdoc.document options
|
|
#
|
|
# You can also generate output like the +rdoc+ executable:
|
|
#
|
|
# rdoc = RDoc::RDoc.new
|
|
# rdoc.document argv
|
|
#
|
|
# Where +argv+ is an array of strings, each corresponding to an argument you'd
|
|
# give rdoc on the command line. See <tt>rdoc --help</tt> for details.
|
|
|
|
class RDoc::RDoc
|
|
|
|
@current = nil
|
|
|
|
##
|
|
# This is the list of supported output generators
|
|
|
|
GENERATORS = {}
|
|
|
|
##
|
|
# Generator instance used for creating output
|
|
|
|
attr_accessor :generator
|
|
|
|
##
|
|
# Hash of files and their last modified times.
|
|
|
|
attr_reader :last_modified
|
|
|
|
##
|
|
# RDoc options
|
|
|
|
attr_accessor :options
|
|
|
|
##
|
|
# Accessor for statistics. Available after each call to parse_files
|
|
|
|
attr_reader :stats
|
|
|
|
##
|
|
# The current documentation store
|
|
|
|
attr_reader :store
|
|
|
|
##
|
|
# Add +klass+ that can generate output after parsing
|
|
|
|
def self.add_generator(klass)
|
|
name = klass.name.sub(/^RDoc::Generator::/, '').downcase
|
|
GENERATORS[name] = klass
|
|
end
|
|
|
|
##
|
|
# Active RDoc::RDoc instance
|
|
|
|
def self.current
|
|
@current
|
|
end
|
|
|
|
##
|
|
# Sets the active RDoc::RDoc instance
|
|
|
|
def self.current= rdoc
|
|
@current = rdoc
|
|
end
|
|
|
|
##
|
|
# Creates a new RDoc::RDoc instance. Call #document to parse files and
|
|
# generate documentation.
|
|
|
|
def initialize
|
|
@current = nil
|
|
@generator = nil
|
|
@last_modified = {}
|
|
@old_siginfo = nil
|
|
@options = nil
|
|
@stats = nil
|
|
@store = nil
|
|
end
|
|
|
|
##
|
|
# Report an error message and exit
|
|
|
|
def error(msg)
|
|
raise RDoc::Error, msg
|
|
end
|
|
|
|
##
|
|
# Gathers a set of parseable files from the files and directories listed in
|
|
# +files+.
|
|
|
|
def gather_files files
|
|
files = ["."] if files.empty?
|
|
|
|
file_list = normalized_file_list files, true, @options.exclude
|
|
|
|
file_list = remove_unparseable(file_list)
|
|
|
|
if file_list.count {|name, mtime|
|
|
file_list[name] = @last_modified[name] unless mtime
|
|
mtime
|
|
} > 0
|
|
@last_modified.replace file_list
|
|
file_list.keys.sort
|
|
else
|
|
[]
|
|
end
|
|
end
|
|
|
|
##
|
|
# Turns RDoc from stdin into HTML
|
|
|
|
def handle_pipe
|
|
@html = RDoc::Markup::ToHtml.new @options
|
|
|
|
parser = RDoc::Text::MARKUP_FORMAT[@options.markup]
|
|
|
|
document = parser.parse $stdin.read
|
|
|
|
out = @html.convert document
|
|
|
|
$stdout.write out
|
|
end
|
|
|
|
##
|
|
# Installs a siginfo handler that prints the current filename.
|
|
|
|
def install_siginfo_handler
|
|
return unless Signal.list.include? 'INFO'
|
|
|
|
@old_siginfo = trap 'INFO' do
|
|
puts @current if @current
|
|
end
|
|
end
|
|
|
|
##
|
|
# Loads options from .rdoc_options if the file exists, otherwise creates a
|
|
# new RDoc::Options instance.
|
|
|
|
def load_options
|
|
options_file = File.expand_path '.rdoc_options'
|
|
return RDoc::Options.new unless File.exist? options_file
|
|
|
|
RDoc.load_yaml
|
|
|
|
begin
|
|
options = YAML.load_file '.rdoc_options'
|
|
rescue Psych::SyntaxError
|
|
end
|
|
|
|
return RDoc::Options.new if options == false # Allow empty file.
|
|
|
|
raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless
|
|
RDoc::Options === options or Hash === options
|
|
|
|
if Hash === options
|
|
# Override the default values with the contents of YAML file.
|
|
options = RDoc::Options.new options
|
|
end
|
|
|
|
options
|
|
end
|
|
|
|
##
|
|
# Create an output dir if it doesn't exist. If it does exist, but doesn't
|
|
# contain the flag file <tt>created.rid</tt> then we refuse to use it, as
|
|
# we may clobber some manually generated documentation
|
|
|
|
def setup_output_dir(dir, force)
|
|
flag_file = output_flag_file dir
|
|
|
|
last = {}
|
|
|
|
if @options.dry_run then
|
|
# do nothing
|
|
elsif File.exist? dir then
|
|
error "#{dir} exists and is not a directory" unless File.directory? dir
|
|
|
|
begin
|
|
File.open flag_file do |io|
|
|
unless force then
|
|
Time.parse io.gets
|
|
|
|
io.each do |line|
|
|
file, time = line.split "\t", 2
|
|
time = Time.parse(time) rescue next
|
|
last[file] = time
|
|
end
|
|
end
|
|
end
|
|
rescue SystemCallError, TypeError
|
|
error <<-ERROR
|
|
|
|
Directory #{dir} already exists, but it looks like it isn't an RDoc directory.
|
|
|
|
Because RDoc doesn't want to risk destroying any of your existing files,
|
|
you'll need to specify a different output directory name (using the --op <dir>
|
|
option)
|
|
|
|
ERROR
|
|
end unless @options.force_output
|
|
else
|
|
FileUtils.mkdir_p dir
|
|
FileUtils.touch flag_file
|
|
end
|
|
|
|
last
|
|
end
|
|
|
|
##
|
|
# Sets the current documentation tree to +store+ and sets the store's rdoc
|
|
# driver to this instance.
|
|
|
|
def store= store
|
|
@store = store
|
|
@store.rdoc = self
|
|
end
|
|
|
|
##
|
|
# Update the flag file in an output directory.
|
|
|
|
def update_output_dir(op_dir, time, last = {})
|
|
return if @options.dry_run or not @options.update_output_dir
|
|
unless ENV['SOURCE_DATE_EPOCH'].nil?
|
|
time = Time.at(ENV['SOURCE_DATE_EPOCH'].to_i).gmtime
|
|
end
|
|
|
|
File.open output_flag_file(op_dir), "w" do |f|
|
|
f.puts time.rfc2822
|
|
last.each do |n, t|
|
|
f.puts "#{n}\t#{t.rfc2822}"
|
|
end
|
|
end
|
|
end
|
|
|
|
##
|
|
# Return the path name of the flag file in an output directory.
|
|
|
|
def output_flag_file(op_dir)
|
|
File.join op_dir, "created.rid"
|
|
end
|
|
|
|
##
|
|
# The .document file contains a list of file and directory name patterns,
|
|
# representing candidates for documentation. It may also contain comments
|
|
# (starting with '#')
|
|
|
|
def parse_dot_doc_file in_dir, filename
|
|
# read and strip comments
|
|
patterns = File.read(filename).gsub(/#.*/, '')
|
|
|
|
result = {}
|
|
|
|
patterns.split(' ').each do |patt|
|
|
candidates = Dir.glob(File.join(in_dir, patt))
|
|
result.update normalized_file_list(candidates, false, @options.exclude)
|
|
end
|
|
|
|
result
|
|
end
|
|
|
|
##
|
|
# Given a list of files and directories, create a list of all the Ruby
|
|
# files they contain.
|
|
#
|
|
# If +force_doc+ is true we always add the given files, if false, only
|
|
# add files that we guarantee we can parse. It is true when looking at
|
|
# files given on the command line, false when recursing through
|
|
# subdirectories.
|
|
#
|
|
# The effect of this is that if you want a file with a non-standard
|
|
# extension parsed, you must name it explicitly.
|
|
|
|
def normalized_file_list(relative_files, force_doc = false,
|
|
exclude_pattern = nil)
|
|
file_list = {}
|
|
|
|
relative_files.each do |rel_file_name|
|
|
rel_file_name = rel_file_name.sub(/^\.\//, '')
|
|
next if rel_file_name.end_with? 'created.rid'
|
|
next if exclude_pattern && exclude_pattern =~ rel_file_name
|
|
stat = File.stat rel_file_name rescue next
|
|
|
|
case type = stat.ftype
|
|
when "file" then
|
|
mtime = (stat.mtime unless (last_modified = @last_modified[rel_file_name] and
|
|
stat.mtime.to_i <= last_modified.to_i))
|
|
|
|
if force_doc or RDoc::Parser.can_parse(rel_file_name) then
|
|
file_list[rel_file_name] = mtime
|
|
end
|
|
when "directory" then
|
|
next if rel_file_name == "CVS" || rel_file_name == ".svn"
|
|
|
|
created_rid = File.join rel_file_name, "created.rid"
|
|
next if File.file? created_rid
|
|
|
|
dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME
|
|
|
|
if File.file? dot_doc then
|
|
file_list.update(parse_dot_doc_file(rel_file_name, dot_doc))
|
|
else
|
|
file_list.update(list_files_in_directory(rel_file_name))
|
|
end
|
|
else
|
|
warn "rdoc can't parse the #{type} #{rel_file_name}"
|
|
end
|
|
end
|
|
|
|
file_list
|
|
end
|
|
|
|
##
|
|
# Return a list of the files to be processed in a directory. We know that
|
|
# this directory doesn't have a .document file, so we're looking for real
|
|
# files. However we may well contain subdirectories which must be tested
|
|
# for .document files.
|
|
|
|
def list_files_in_directory dir
|
|
files = Dir.glob File.join(dir, "*")
|
|
|
|
normalized_file_list files, false, @options.exclude
|
|
end
|
|
|
|
##
|
|
# Parses +filename+ and returns an RDoc::TopLevel
|
|
|
|
def parse_file filename
|
|
encoding = @options.encoding
|
|
filename = filename.encode encoding
|
|
|
|
@stats.add_file filename
|
|
|
|
return if RDoc::Parser.binary? filename
|
|
|
|
content = RDoc::Encoding.read_file filename, encoding
|
|
|
|
return unless content
|
|
|
|
filename_path = Pathname(filename).expand_path
|
|
begin
|
|
relative_path = filename_path.relative_path_from @options.root
|
|
rescue ArgumentError
|
|
relative_path = filename_path
|
|
end
|
|
|
|
if @options.page_dir and
|
|
relative_path.to_s.start_with? @options.page_dir.to_s then
|
|
relative_path =
|
|
relative_path.relative_path_from @options.page_dir
|
|
end
|
|
|
|
top_level = @store.add_file filename, relative_name: relative_path.to_s
|
|
|
|
parser = RDoc::Parser.for top_level, filename, content, @options, @stats
|
|
|
|
return unless parser
|
|
|
|
parser.scan
|
|
|
|
# restart documentation for the classes & modules found
|
|
top_level.classes_or_modules.each do |cm|
|
|
cm.done_documenting = false
|
|
end
|
|
|
|
top_level
|
|
|
|
rescue Errno::EACCES => e
|
|
$stderr.puts <<-EOF
|
|
Unable to read #{filename}, #{e.message}
|
|
|
|
Please check the permissions for this file. Perhaps you do not have access to
|
|
it or perhaps the original author's permissions are to restrictive. If the
|
|
this is not your library please report a bug to the author.
|
|
EOF
|
|
rescue => e
|
|
$stderr.puts <<-EOF
|
|
Before reporting this, could you check that the file you're documenting
|
|
has proper syntax:
|
|
|
|
#{Gem.ruby} -c #{filename}
|
|
|
|
RDoc is not a full Ruby parser and will fail when fed invalid ruby programs.
|
|
|
|
The internal error was:
|
|
|
|
\t(#{e.class}) #{e.message}
|
|
|
|
EOF
|
|
|
|
$stderr.puts e.backtrace.join("\n\t") if $DEBUG_RDOC
|
|
|
|
raise e
|
|
nil
|
|
end
|
|
|
|
##
|
|
# Parse each file on the command line, recursively entering directories.
|
|
|
|
def parse_files files
|
|
file_list = gather_files files
|
|
@stats = RDoc::Stats.new @store, file_list.length, @options.verbosity
|
|
|
|
return [] if file_list.empty?
|
|
|
|
original_options = @options.dup
|
|
@stats.begin_adding
|
|
|
|
file_info = file_list.map do |filename|
|
|
@current = filename
|
|
parse_file filename
|
|
end.compact
|
|
|
|
@stats.done_adding
|
|
@options = original_options
|
|
|
|
file_info
|
|
end
|
|
|
|
##
|
|
# Removes file extensions known to be unparseable from +files+ and TAGS
|
|
# files for emacs and vim.
|
|
|
|
def remove_unparseable files
|
|
files.reject do |file, *|
|
|
file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
|
|
(file =~ /tags$/i and
|
|
File.open(file, 'rb') { |io|
|
|
io.read(100) =~ /\A(\f\n[^,]+,\d+$|!_TAG_)/
|
|
})
|
|
end
|
|
end
|
|
|
|
##
|
|
# Generates documentation or a coverage report depending upon the settings
|
|
# in +options+.
|
|
#
|
|
# +options+ can be either an RDoc::Options instance or an array of strings
|
|
# equivalent to the strings that would be passed on the command line like
|
|
# <tt>%w[-q -o doc -t My\ Doc\ Title]</tt>. #document will automatically
|
|
# call RDoc::Options#finish if an options instance was given.
|
|
#
|
|
# For a list of options, see either RDoc::Options or <tt>rdoc --help</tt>.
|
|
#
|
|
# By default, output will be stored in a directory called "doc" below the
|
|
# current directory, so make sure you're somewhere writable before invoking.
|
|
|
|
def document options
|
|
self.store = RDoc::Store.new
|
|
|
|
if RDoc::Options === options then
|
|
@options = options
|
|
@options.finish
|
|
else
|
|
@options = load_options
|
|
@options.parse options
|
|
end
|
|
|
|
if @options.pipe then
|
|
handle_pipe
|
|
exit
|
|
end
|
|
|
|
unless @options.coverage_report then
|
|
@last_modified = setup_output_dir @options.op_dir, @options.force_update
|
|
end
|
|
|
|
@store.encoding = @options.encoding
|
|
@store.dry_run = @options.dry_run
|
|
@store.main = @options.main_page
|
|
@store.title = @options.title
|
|
@store.path = @options.op_dir
|
|
|
|
@start_time = Time.now
|
|
|
|
@store.load_cache
|
|
|
|
file_info = parse_files @options.files
|
|
|
|
@options.default_title = "RDoc Documentation"
|
|
|
|
@store.complete @options.visibility
|
|
|
|
@stats.coverage_level = @options.coverage_report
|
|
|
|
if @options.coverage_report then
|
|
puts
|
|
|
|
puts @stats.report.accept RDoc::Markup::ToRdoc.new
|
|
elsif file_info.empty? then
|
|
$stderr.puts "\nNo newer files." unless @options.quiet
|
|
else
|
|
gen_klass = @options.generator
|
|
|
|
@generator = gen_klass.new @store, @options
|
|
|
|
generate
|
|
end
|
|
|
|
if @stats and (@options.coverage_report or not @options.quiet) then
|
|
puts
|
|
puts @stats.summary.accept RDoc::Markup::ToRdoc.new
|
|
end
|
|
|
|
exit @stats.fully_documented? if @options.coverage_report
|
|
end
|
|
|
|
##
|
|
# Generates documentation for +file_info+ (from #parse_files) into the
|
|
# output dir using the generator selected
|
|
# by the RDoc options
|
|
|
|
def generate
|
|
if @options.dry_run then
|
|
# do nothing
|
|
@generator.generate
|
|
else
|
|
Dir.chdir @options.op_dir do
|
|
unless @options.quiet then
|
|
$stderr.puts "\nGenerating #{@generator.class.name.sub(/^.*::/, '')} format into #{Dir.pwd}..."
|
|
end
|
|
|
|
@generator.generate
|
|
update_output_dir '.', @start_time, @last_modified
|
|
end
|
|
end
|
|
end
|
|
|
|
##
|
|
# Removes a siginfo handler and replaces the previous
|
|
|
|
def remove_siginfo_handler
|
|
return unless Signal.list.key? 'INFO'
|
|
|
|
handler = @old_siginfo || 'DEFAULT'
|
|
|
|
trap 'INFO', handler
|
|
end
|
|
|
|
end
|
|
|
|
begin
|
|
require 'rubygems'
|
|
|
|
rdoc_extensions = Gem.find_files 'rdoc/discover'
|
|
|
|
rdoc_extensions.each do |extension|
|
|
begin
|
|
load extension
|
|
rescue => e
|
|
warn "error loading #{extension.inspect}: #{e.message} (#{e.class})"
|
|
warn "\t#{e.backtrace.join "\n\t"}" if $DEBUG
|
|
end
|
|
end
|
|
rescue LoadError
|
|
end
|
|
|
|
# require built-in generators after discovery in case they've been replaced
|
|
require_relative 'generator/darkfish'
|
|
require_relative 'generator/ri'
|
|
require_relative 'generator/pot'
|