2017-11-27 05:45:24 -05:00
|
|
|
# frozen_string_literal: true
|
2008-01-07 01:56:46 -05:00
|
|
|
require 'optparse'
|
2012-11-27 03:54:03 -05:00
|
|
|
require 'pathname'
|
2003-12-16 00:44:25 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# RDoc::Options handles the parsing and storage of options
|
2012-11-26 23:28:14 -05:00
|
|
|
#
|
|
|
|
# == Saved Options
|
|
|
|
#
|
|
|
|
# You can save some options like the markup format in the
|
|
|
|
# <tt>.rdoc_options</tt> file in your gem. The easiest way to do this is:
|
|
|
|
#
|
|
|
|
# rdoc --markup tomdoc --write-options
|
|
|
|
#
|
|
|
|
# Which will automatically create the file and fill it with the options you
|
|
|
|
# specified.
|
|
|
|
#
|
|
|
|
# The following options will not be saved since they interfere with the user's
|
|
|
|
# preferences or with the normal operation of RDoc:
|
|
|
|
#
|
|
|
|
# * +--coverage-report+
|
|
|
|
# * +--dry-run+
|
|
|
|
# * +--encoding+
|
|
|
|
# * +--force-update+
|
|
|
|
# * +--format+
|
|
|
|
# * +--pipe+
|
|
|
|
# * +--quiet+
|
|
|
|
# * +--template+
|
|
|
|
# * +--verbose+
|
|
|
|
#
|
|
|
|
# == Custom Options
|
|
|
|
#
|
|
|
|
# Generators can hook into RDoc::Options to add generator-specific command
|
|
|
|
# line options.
|
|
|
|
#
|
|
|
|
# When <tt>--format</tt> is encountered in ARGV, RDoc calls ::setup_options on
|
|
|
|
# the generator class to add extra options to the option parser. Options for
|
|
|
|
# custom generators must occur after <tt>--format</tt>. <tt>rdoc --help</tt>
|
|
|
|
# will list options for all installed generators.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# class RDoc::Generator::Spellcheck
|
|
|
|
# RDoc::RDoc.add_generator self
|
|
|
|
#
|
|
|
|
# def self.setup_options rdoc_options
|
|
|
|
# op = rdoc_options.option_parser
|
|
|
|
#
|
|
|
|
# op.on('--spell-dictionary DICTIONARY',
|
|
|
|
# RDoc::Options::Path) do |dictionary|
|
|
|
|
# rdoc_options.spell_dictionary = dictionary
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
2013-09-18 19:33:36 -04:00
|
|
|
# Of course, RDoc::Options does not respond to +spell_dictionary+ by default
|
|
|
|
# so you will need to add it:
|
|
|
|
#
|
|
|
|
# class RDoc::Options
|
|
|
|
#
|
|
|
|
# ##
|
|
|
|
# # The spell dictionary used by the spell-checking plugin.
|
|
|
|
#
|
|
|
|
# attr_accessor :spell_dictionary
|
|
|
|
#
|
|
|
|
# end
|
|
|
|
#
|
2012-11-26 23:28:14 -05:00
|
|
|
# == Option Validators
|
|
|
|
#
|
|
|
|
# OptionParser validators will validate and cast user input values. In
|
|
|
|
# addition to the validators that ship with OptionParser (String, Integer,
|
|
|
|
# Float, TrueClass, FalseClass, Array, Regexp, Date, Time, URI, etc.),
|
|
|
|
# RDoc::Options adds Path, PathArray and Template.
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
class RDoc::Options
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# The deprecated options.
|
|
|
|
|
|
|
|
DEPRECATED = {
|
|
|
|
'--accessor' => 'support discontinued',
|
|
|
|
'--diagram' => 'support discontinued',
|
|
|
|
'--help-output' => 'support discontinued',
|
|
|
|
'--image-format' => 'was an option for --diagram',
|
|
|
|
'--inline-source' => 'source code is now always inlined',
|
|
|
|
'--merge' => 'ri now always merges class information',
|
|
|
|
'--one-file' => 'support discontinued',
|
|
|
|
'--op-name' => 'support discontinued',
|
|
|
|
'--opname' => 'support discontinued',
|
|
|
|
'--promiscuous' => 'files always only document their content',
|
|
|
|
'--ri-system' => 'Ruby installers use other techniques',
|
|
|
|
}
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
2012-11-26 23:28:14 -05:00
|
|
|
# RDoc options ignored (or handled specially) by --write-options
|
|
|
|
|
|
|
|
SPECIAL = %w[
|
|
|
|
coverage_report
|
|
|
|
dry_run
|
|
|
|
encoding
|
|
|
|
files
|
|
|
|
force_output
|
|
|
|
force_update
|
|
|
|
generator
|
|
|
|
generator_name
|
|
|
|
generator_options
|
|
|
|
generators
|
|
|
|
op_dir
|
|
|
|
option_parser
|
|
|
|
pipe
|
|
|
|
rdoc_include
|
2012-11-27 03:54:03 -05:00
|
|
|
root
|
2012-11-26 23:28:14 -05:00
|
|
|
static_path
|
|
|
|
stylesheet_url
|
|
|
|
template
|
|
|
|
template_dir
|
|
|
|
update_output_dir
|
|
|
|
verbosity
|
|
|
|
write_options
|
|
|
|
]
|
|
|
|
|
2012-11-27 03:54:03 -05:00
|
|
|
##
|
|
|
|
# Option validator for OptionParser that matches a directory that exists on
|
|
|
|
# the filesystem.
|
|
|
|
|
|
|
|
Directory = Object.new
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# Option validator for OptionParser that matches a file or directory that
|
|
|
|
# exists on the filesystem.
|
|
|
|
|
|
|
|
Path = Object.new
|
|
|
|
|
|
|
|
##
|
|
|
|
# Option validator for OptionParser that matches a comma-separated list of
|
|
|
|
# files or directories that exist on the filesystem.
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
PathArray = Object.new
|
|
|
|
|
|
|
|
##
|
|
|
|
# Option validator for OptionParser that matches a template directory for an
|
|
|
|
# installed generator that lives in
|
|
|
|
# <tt>"rdoc/generator/template/#{template_name}"</tt>
|
|
|
|
|
|
|
|
Template = Object.new
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Character-set for HTML output. #encoding is preferred over #charset
|
|
|
|
|
|
|
|
attr_accessor :charset
|
|
|
|
|
|
|
|
##
|
|
|
|
# If true, RDoc will not write any files.
|
|
|
|
|
|
|
|
attr_accessor :dry_run
|
|
|
|
|
|
|
|
##
|
2012-11-26 23:28:14 -05:00
|
|
|
# The output encoding. All input files will be transcoded to this encoding.
|
|
|
|
#
|
|
|
|
# The default encoding is UTF-8. This is set via --encoding.
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
attr_accessor :encoding
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
|
|
|
# Files matching this pattern will be excluded
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2018-12-08 12:39:52 -05:00
|
|
|
attr_writer :exclude
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
|
|
|
# The list of files to be processed
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
attr_accessor :files
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Create the output even if the output directory does not look
|
|
|
|
# like an rdoc output directory
|
|
|
|
|
|
|
|
attr_accessor :force_output
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
|
|
|
# Scan newer sources than the flag file if true.
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :force_update
|
|
|
|
|
|
|
|
##
|
|
|
|
# Formatter to mark up text with
|
|
|
|
|
|
|
|
attr_accessor :formatter
|
2008-01-07 01:56:46 -05:00
|
|
|
|
|
|
|
##
|
2012-11-26 23:28:14 -05:00
|
|
|
# Description of the output generator (set with the <tt>--format</tt> option)
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
attr_accessor :generator
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# For #==
|
|
|
|
|
|
|
|
attr_reader :generator_name # :nodoc:
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Loaded generator options. Used to prevent --help from loading the same
|
|
|
|
# options multiple times.
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :generator_options
|
|
|
|
|
|
|
|
##
|
|
|
|
# Old rdoc behavior: hyperlink all words that match a method name,
|
|
|
|
# even if not preceded by '#' or '::'
|
|
|
|
|
|
|
|
attr_accessor :hyperlink_all
|
|
|
|
|
|
|
|
##
|
|
|
|
# Include line numbers in the source code
|
|
|
|
|
|
|
|
attr_accessor :line_numbers
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2014-09-04 21:41:25 -04:00
|
|
|
##
|
|
|
|
# The output locale.
|
|
|
|
|
|
|
|
attr_accessor :locale
|
|
|
|
|
|
|
|
##
|
|
|
|
# The directory where locale data live.
|
|
|
|
|
|
|
|
attr_accessor :locale_dir
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
|
|
|
# Name of the file, class or module to display in the initial index page (if
|
|
|
|
# not specified the first file we encounter is used)
|
|
|
|
|
|
|
|
attr_accessor :main_page
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# The default markup format. The default is 'rdoc'. 'markdown', 'tomdoc'
|
|
|
|
# and 'rd' are also built-in.
|
|
|
|
|
|
|
|
attr_accessor :markup
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# If true, only report on undocumented files
|
|
|
|
|
|
|
|
attr_accessor :coverage_report
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
|
|
|
# The name of the output directory
|
|
|
|
|
|
|
|
attr_accessor :op_dir
|
|
|
|
|
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# The OptionParser for this instance
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :option_parser
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
##
|
|
|
|
# Output heading decorations?
|
|
|
|
attr_accessor :output_decoration
|
|
|
|
|
2012-12-11 02:44:56 -05:00
|
|
|
##
|
|
|
|
# Directory where guides, FAQ, and other pages not associated with a class
|
|
|
|
# live. You may leave this unset if these are at the root of your project.
|
|
|
|
|
|
|
|
attr_accessor :page_dir
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Is RDoc in pipe mode?
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :pipe
|
2008-01-07 01:56:46 -05:00
|
|
|
|
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Array of directories to search for files to satisfy an :include:
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :rdoc_include
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2012-11-27 03:54:03 -05:00
|
|
|
##
|
|
|
|
# Root of the source documentation will be generated for. Set this when
|
|
|
|
# building documentation outside the source directory. Defaults to the
|
|
|
|
# current directory.
|
|
|
|
|
|
|
|
attr_accessor :root
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
|
|
|
# Include the '#' at the front of hyperlinked instance method names
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :show_hash
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# Directory to copy static files from
|
|
|
|
|
|
|
|
attr_accessor :static_path
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
|
|
|
# The number of columns in a tab
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :tab_width
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
2010-04-01 03:45:16 -04:00
|
|
|
# Template to be used when generating output
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :template
|
|
|
|
|
|
|
|
##
|
|
|
|
# Directory the template lives in
|
|
|
|
|
|
|
|
attr_accessor :template_dir
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
##
|
|
|
|
# Additional template stylesheets
|
|
|
|
|
|
|
|
attr_accessor :template_stylesheets
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
|
|
|
# Documentation title
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :title
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2011-02-01 19:32:30 -05:00
|
|
|
##
|
|
|
|
# Should RDoc update the timestamps in the output dir?
|
|
|
|
|
|
|
|
attr_accessor :update_output_dir
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
##
|
|
|
|
# Verbosity, zero means quiet
|
|
|
|
|
|
|
|
attr_accessor :verbosity
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# URL of web cvs frontend
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :webcvs
|
|
|
|
|
|
|
|
##
|
2013-09-18 19:33:36 -04:00
|
|
|
# Minimum visibility of a documented method. One of +:public+, +:protected+,
|
|
|
|
# +:private+ or +:nodoc+.
|
|
|
|
#
|
|
|
|
# The +:nodoc+ visibility ignores all directives related to visibility. The
|
|
|
|
# other visibilities may be overridden on a per-method basis with the :doc:
|
|
|
|
# directive.
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2014-09-04 21:41:25 -04:00
|
|
|
attr_reader :visibility
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def initialize # :nodoc:
|
2012-11-26 23:28:14 -05:00
|
|
|
init_ivars
|
|
|
|
end
|
|
|
|
|
|
|
|
def init_ivars # :nodoc:
|
2010-12-19 22:22:49 -05:00
|
|
|
@dry_run = false
|
2019-01-13 08:16:56 -05:00
|
|
|
@exclude = %w[
|
|
|
|
~\z \.orig\z \.rej\z \.bak\z
|
2019-01-13 08:49:25 -05:00
|
|
|
\.gemspec\z
|
2019-01-13 08:16:56 -05:00
|
|
|
]
|
2012-11-26 23:28:14 -05:00
|
|
|
@files = nil
|
2010-12-19 22:22:49 -05:00
|
|
|
@force_output = false
|
|
|
|
@force_update = true
|
|
|
|
@generator = nil
|
2010-04-01 03:45:16 -04:00
|
|
|
@generator_name = nil
|
2010-12-19 22:22:49 -05:00
|
|
|
@generator_options = []
|
|
|
|
@generators = RDoc::RDoc::GENERATORS
|
|
|
|
@hyperlink_all = false
|
|
|
|
@line_numbers = false
|
2014-09-04 21:41:25 -04:00
|
|
|
@locale = nil
|
|
|
|
@locale_name = nil
|
|
|
|
@locale_dir = 'locale'
|
2010-12-19 22:22:49 -05:00
|
|
|
@main_page = nil
|
2012-11-26 23:28:14 -05:00
|
|
|
@markup = 'rdoc'
|
2010-12-19 22:22:49 -05:00
|
|
|
@coverage_report = false
|
|
|
|
@op_dir = nil
|
2012-12-11 02:44:56 -05:00
|
|
|
@page_dir = nil
|
2010-12-19 22:22:49 -05:00
|
|
|
@pipe = false
|
2013-09-18 19:33:36 -04:00
|
|
|
@output_decoration = true
|
2008-01-07 01:56:46 -05:00
|
|
|
@rdoc_include = []
|
2012-11-27 03:54:03 -05:00
|
|
|
@root = Pathname(Dir.pwd)
|
2008-01-07 01:56:46 -05:00
|
|
|
@show_hash = false
|
2012-11-26 23:28:14 -05:00
|
|
|
@static_path = []
|
|
|
|
@stylesheet_url = nil # TODO remove in RDoc 4
|
2008-01-07 01:56:46 -05:00
|
|
|
@tab_width = 8
|
2010-12-19 22:22:49 -05:00
|
|
|
@template = nil
|
|
|
|
@template_dir = nil
|
2013-09-18 19:33:36 -04:00
|
|
|
@template_stylesheets = []
|
2010-12-19 22:22:49 -05:00
|
|
|
@title = nil
|
2011-02-01 19:32:30 -05:00
|
|
|
@update_output_dir = true
|
2008-07-21 14:35:14 -04:00
|
|
|
@verbosity = 1
|
2010-12-19 22:22:49 -05:00
|
|
|
@visibility = :protected
|
2008-01-07 01:56:46 -05:00
|
|
|
@webcvs = nil
|
2012-11-26 23:28:14 -05:00
|
|
|
@write_options = false
|
2016-09-07 18:23:38 -04:00
|
|
|
@encoding = Encoding::UTF_8
|
|
|
|
@charset = @encoding.name
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def init_with map # :nodoc:
|
|
|
|
init_ivars
|
|
|
|
|
|
|
|
encoding = map['encoding']
|
2016-09-07 18:23:38 -04:00
|
|
|
@encoding = encoding ? Encoding.find(encoding) : encoding
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
@charset = map['charset']
|
|
|
|
@exclude = map['exclude']
|
|
|
|
@generator_name = map['generator_name']
|
|
|
|
@hyperlink_all = map['hyperlink_all']
|
|
|
|
@line_numbers = map['line_numbers']
|
2014-09-04 21:41:25 -04:00
|
|
|
@locale_name = map['locale_name']
|
|
|
|
@locale_dir = map['locale_dir']
|
2012-11-26 23:28:14 -05:00
|
|
|
@main_page = map['main_page']
|
|
|
|
@markup = map['markup']
|
|
|
|
@op_dir = map['op_dir']
|
|
|
|
@show_hash = map['show_hash']
|
|
|
|
@tab_width = map['tab_width']
|
|
|
|
@template_dir = map['template_dir']
|
|
|
|
@title = map['title']
|
|
|
|
@visibility = map['visibility']
|
|
|
|
@webcvs = map['webcvs']
|
|
|
|
|
|
|
|
@rdoc_include = sanitize_path map['rdoc_include']
|
|
|
|
@static_path = sanitize_path map['static_path']
|
|
|
|
end
|
|
|
|
|
|
|
|
def yaml_initialize tag, map # :nodoc:
|
|
|
|
init_with map
|
|
|
|
end
|
|
|
|
|
|
|
|
def == other # :nodoc:
|
|
|
|
self.class === other and
|
|
|
|
@encoding == other.encoding and
|
|
|
|
@generator_name == other.generator_name and
|
|
|
|
@hyperlink_all == other.hyperlink_all and
|
|
|
|
@line_numbers == other.line_numbers and
|
2014-09-04 21:41:25 -04:00
|
|
|
@locale == other.locale and
|
|
|
|
@locale_dir == other.locale_dir and
|
2012-11-26 23:28:14 -05:00
|
|
|
@main_page == other.main_page and
|
|
|
|
@markup == other.markup and
|
|
|
|
@op_dir == other.op_dir and
|
|
|
|
@rdoc_include == other.rdoc_include and
|
|
|
|
@show_hash == other.show_hash and
|
|
|
|
@static_path == other.static_path and
|
|
|
|
@tab_width == other.tab_width and
|
|
|
|
@template == other.template and
|
|
|
|
@title == other.title and
|
|
|
|
@visibility == other.visibility and
|
|
|
|
@webcvs == other.webcvs
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Check that the files on the command line exist
|
|
|
|
|
|
|
|
def check_files
|
|
|
|
@files.delete_if do |file|
|
|
|
|
if File.exist? file then
|
|
|
|
if File.readable? file then
|
|
|
|
false
|
|
|
|
else
|
|
|
|
warn "file '#{file}' not readable"
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
else
|
|
|
|
warn "file '#{file}' not found"
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Ensure only one generator is loaded
|
|
|
|
|
|
|
|
def check_generator
|
|
|
|
if @generator then
|
|
|
|
raise OptionParser::InvalidOption,
|
|
|
|
"generator already set to #{@generator_name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Set the title, but only if not already set. Used to set the title
|
|
|
|
# from a source file, so that a title set from the command line
|
|
|
|
# will have the priority.
|
|
|
|
|
|
|
|
def default_title=(string)
|
|
|
|
@title ||= string
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# For dumping YAML
|
|
|
|
|
|
|
|
def encode_with coder # :nodoc:
|
|
|
|
encoding = @encoding ? @encoding.name : nil
|
|
|
|
|
|
|
|
coder.add 'encoding', encoding
|
|
|
|
coder.add 'static_path', sanitize_path(@static_path)
|
|
|
|
coder.add 'rdoc_include', sanitize_path(@rdoc_include)
|
|
|
|
|
|
|
|
ivars = instance_variables.map { |ivar| ivar.to_s[1..-1] }
|
|
|
|
ivars -= SPECIAL
|
|
|
|
|
|
|
|
ivars.sort.each do |ivar|
|
|
|
|
coder.add ivar, instance_variable_get("@#{ivar}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-08 12:39:52 -05:00
|
|
|
##
|
|
|
|
# Create a regexp for #exclude
|
|
|
|
|
|
|
|
def exclude
|
|
|
|
if @exclude.nil? or Regexp === @exclude then
|
|
|
|
# done, #finish is being re-run
|
|
|
|
@exclude
|
|
|
|
elsif @exclude.empty? then
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
Regexp.new(@exclude.join("|"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-01 19:32:30 -05:00
|
|
|
##
|
|
|
|
# Completes any unfinished option setup business such as filtering for
|
|
|
|
# existent files, creating a regexp for #exclude and setting a default
|
|
|
|
# #template.
|
|
|
|
|
|
|
|
def finish
|
|
|
|
@op_dir ||= 'doc'
|
|
|
|
|
|
|
|
@rdoc_include << "." if @rdoc_include.empty?
|
2013-09-18 19:33:36 -04:00
|
|
|
root = @root.to_s
|
2013-07-31 15:06:21 -04:00
|
|
|
@rdoc_include << root unless @rdoc_include.include?(root)
|
2011-02-01 19:32:30 -05:00
|
|
|
|
2018-12-08 12:39:52 -05:00
|
|
|
@exclude = self.exclude
|
2011-02-01 19:32:30 -05:00
|
|
|
|
2012-12-11 02:44:56 -05:00
|
|
|
finish_page_dir
|
|
|
|
|
2011-02-01 19:32:30 -05:00
|
|
|
check_files
|
|
|
|
|
|
|
|
# If no template was specified, use the default template for the output
|
|
|
|
# formatter
|
|
|
|
|
|
|
|
unless @template then
|
|
|
|
@template = @generator_name
|
|
|
|
@template_dir = template_dir_for @template
|
|
|
|
end
|
|
|
|
|
2014-09-04 21:41:25 -04:00
|
|
|
if @locale_name
|
|
|
|
@locale = RDoc::I18n::Locale[@locale_name]
|
|
|
|
@locale.load(@locale_dir)
|
|
|
|
else
|
|
|
|
@locale = nil
|
|
|
|
end
|
|
|
|
|
2011-02-01 19:32:30 -05:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2012-12-11 02:44:56 -05:00
|
|
|
##
|
|
|
|
# Fixes the page_dir to be relative to the root_dir and adds the page_dir to
|
|
|
|
# the files list.
|
|
|
|
|
|
|
|
def finish_page_dir
|
|
|
|
return unless @page_dir
|
|
|
|
|
|
|
|
@files << @page_dir.to_s
|
|
|
|
|
2019-10-27 12:44:09 -04:00
|
|
|
page_dir = nil
|
|
|
|
begin
|
|
|
|
page_dir = @page_dir.expand_path.relative_path_from @root
|
|
|
|
rescue ArgumentError
|
|
|
|
# On Windows, sometimes crosses different drive letters.
|
|
|
|
page_dir = @page_dir.expand_path
|
|
|
|
end
|
2012-12-11 02:44:56 -05:00
|
|
|
|
|
|
|
@page_dir = page_dir
|
|
|
|
end
|
|
|
|
|
2010-12-28 17:08:56 -05:00
|
|
|
##
|
|
|
|
# Returns a properly-space list of generators and their descriptions.
|
|
|
|
|
|
|
|
def generator_descriptions
|
|
|
|
lengths = []
|
|
|
|
|
|
|
|
generators = RDoc::RDoc::GENERATORS.map do |name, generator|
|
|
|
|
lengths << name.length
|
|
|
|
|
|
|
|
description = generator::DESCRIPTION if
|
|
|
|
generator.const_defined? :DESCRIPTION
|
|
|
|
|
|
|
|
[name, description]
|
|
|
|
end
|
|
|
|
|
|
|
|
longest = lengths.max
|
|
|
|
|
|
|
|
generators.sort.map do |name, description|
|
|
|
|
if description then
|
|
|
|
" %-*s - %s" % [longest, name, description]
|
|
|
|
else
|
|
|
|
" #{name}"
|
|
|
|
end
|
|
|
|
end.join "\n"
|
|
|
|
end
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
2011-02-01 19:32:30 -05:00
|
|
|
# Parses command line options.
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def parse argv
|
2010-04-01 03:45:16 -04:00
|
|
|
ignore_invalid = true
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
argv.insert(0, *ENV['RDOCOPT'].split) if ENV['RDOCOPT']
|
|
|
|
|
2008-04-04 17:16:19 -04:00
|
|
|
opts = OptionParser.new do |opt|
|
2010-12-19 22:22:49 -05:00
|
|
|
@option_parser = opt
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.program_name = File.basename $0
|
|
|
|
opt.version = RDoc::VERSION
|
2008-09-24 22:43:03 -04:00
|
|
|
opt.release = nil
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.summary_indent = ' ' * 4
|
|
|
|
opt.banner = <<-EOF
|
|
|
|
Usage: #{opt.program_name} [options] [names...]
|
|
|
|
|
|
|
|
Files are parsed, and the information they contain collected, before any
|
|
|
|
output is produced. This allows cross references between all files to be
|
|
|
|
resolved. If a name is a directory, it is traversed. If no names are
|
|
|
|
specified, all Ruby files in the current directory (and subdirectories) are
|
|
|
|
processed.
|
|
|
|
|
|
|
|
How RDoc generates output depends on the output formatter being used, and on
|
|
|
|
the options you give.
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
Options can be specified via the RDOCOPT environment variable, which
|
|
|
|
functions similar to the RUBYOPT environment variable for ruby.
|
|
|
|
|
|
|
|
$ export RDOCOPT="--show-hash"
|
|
|
|
|
|
|
|
will make rdoc show hashes in method links by default. Command-line options
|
|
|
|
always will override those in RDOCOPT.
|
|
|
|
|
2010-12-28 17:08:56 -05:00
|
|
|
Available formatters:
|
|
|
|
|
|
|
|
#{generator_descriptions}
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
RDoc understands the following file formats:
|
2008-01-07 01:56:46 -05:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
parsers = Hash.new { |h,parser| h[parser] = [] }
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
RDoc::Parser.parsers.each do |regexp, parser|
|
|
|
|
parsers[parser.name.sub('RDoc::Parser::', '')] << regexp.source
|
|
|
|
end
|
|
|
|
|
|
|
|
parsers.sort.each do |parser, regexp|
|
2017-11-27 05:45:24 -05:00
|
|
|
opt.banner += " - #{parser}: #{regexp.join ', '}\n"
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
2017-11-27 05:45:24 -05:00
|
|
|
opt.banner += " - TomDoc: Only in ruby files\n"
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2017-11-27 05:45:24 -05:00
|
|
|
opt.banner += "\n The following options are deprecated:\n\n"
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
name_length = DEPRECATED.keys.sort_by { |k| k.length }.last.length
|
|
|
|
|
|
|
|
DEPRECATED.sort_by { |k,| k }.each do |name, reason|
|
2017-11-27 05:45:24 -05:00
|
|
|
opt.banner += " %*1$2$s %3$s\n" % [-name_length, name, reason]
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
opt.accept Template do |template|
|
|
|
|
template_dir = template_dir_for template
|
|
|
|
|
|
|
|
unless template_dir then
|
2012-11-26 23:28:14 -05:00
|
|
|
$stderr.puts "could not find template #{template}"
|
2010-12-19 22:22:49 -05:00
|
|
|
nil
|
|
|
|
else
|
|
|
|
[template, template_dir]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-27 03:54:03 -05:00
|
|
|
opt.accept Directory do |directory|
|
|
|
|
directory = File.expand_path directory
|
|
|
|
|
|
|
|
raise OptionParser::InvalidArgument unless File.directory? directory
|
|
|
|
|
|
|
|
directory
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.accept Path do |path|
|
|
|
|
path = File.expand_path path
|
|
|
|
|
|
|
|
raise OptionParser::InvalidArgument unless File.exist? path
|
|
|
|
|
|
|
|
path
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.accept PathArray do |paths,|
|
|
|
|
paths = if paths then
|
|
|
|
paths.split(',').map { |d| d unless d.empty? }
|
|
|
|
end
|
|
|
|
|
|
|
|
paths.map do |path|
|
|
|
|
path = File.expand_path path
|
|
|
|
|
|
|
|
raise OptionParser::InvalidArgument unless File.exist? path
|
|
|
|
|
|
|
|
path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
opt.separator nil
|
2010-12-19 22:22:49 -05:00
|
|
|
opt.separator "Parsing options:"
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2006-09-17 10:46:13 -04:00
|
|
|
|
2016-09-07 18:23:38 -04:00
|
|
|
opt.on("--encoding=ENCODING", "-e", Encoding.list.map { |e| e.name },
|
|
|
|
"Specifies the output encoding. All files",
|
|
|
|
"read will be converted to this encoding.",
|
|
|
|
"The default encoding is UTF-8.",
|
|
|
|
"--encoding is preferred over --charset") do |value|
|
|
|
|
@encoding = Encoding.find value
|
|
|
|
@charset = @encoding.name # may not be valid value
|
|
|
|
end
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2016-09-07 18:23:38 -04:00
|
|
|
opt.separator nil
|
2014-09-04 21:41:25 -04:00
|
|
|
|
|
|
|
opt.on("--locale=NAME",
|
|
|
|
"Specifies the output locale.") do |value|
|
|
|
|
@locale_name = value
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.on("--locale-data-dir=DIR",
|
|
|
|
"Specifies the directory where locale data live.") do |value|
|
|
|
|
@locale_dir = value
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.on("--all", "-a",
|
2010-12-19 22:22:49 -05:00
|
|
|
"Synonym for --visibility=private.") do |value|
|
|
|
|
@visibility = :private
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.on("--exclude=PATTERN", "-x", Regexp,
|
|
|
|
"Do not process files or directories",
|
2008-09-24 22:43:03 -04:00
|
|
|
"matching PATTERN.") do |value|
|
2008-01-07 01:56:46 -05:00
|
|
|
@exclude << value
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--extension=NEW=OLD", "-E",
|
|
|
|
"Treat files ending with .new as if they",
|
|
|
|
"ended with .old. Using '-E cgi=rb' will",
|
|
|
|
"cause xxx.cgi to be parsed as a Ruby file.") do |value|
|
|
|
|
new, old = value.split(/=/, 2)
|
|
|
|
|
|
|
|
unless new and old then
|
|
|
|
raise OptionParser::InvalidArgument, "Invalid parameter to '-E'"
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
unless RDoc::Parser.alias_extension old, new then
|
2008-01-07 01:56:46 -05:00
|
|
|
raise OptionParser::InvalidArgument, "Unknown extension .#{old} to -E"
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-04-03 02:09:37 -04:00
|
|
|
opt.on("--[no-]force-update", "-U",
|
2008-01-07 01:56:46 -05:00
|
|
|
"Forces rdoc to scan all sources even if",
|
2019-09-28 01:45:44 -04:00
|
|
|
"no files are newer than the flag file.") do |value|
|
2008-01-07 01:56:46 -05:00
|
|
|
@force_update = value
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2012-12-11 02:44:56 -05:00
|
|
|
opt.on("--pipe", "-p",
|
2010-04-01 03:45:16 -04:00
|
|
|
"Convert RDoc on stdin to HTML") do
|
|
|
|
@pipe = true
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
opt.on("--tab-width=WIDTH", "-w", Integer,
|
2010-12-19 22:22:49 -05:00
|
|
|
"Set the width of tab characters.") do |value|
|
2013-09-18 19:33:36 -04:00
|
|
|
raise OptionParser::InvalidArgument,
|
|
|
|
"#{value} is an invalid tab width" if value <= 0
|
2010-12-19 22:22:49 -05:00
|
|
|
@tab_width = value
|
|
|
|
end
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
opt.on("--visibility=VISIBILITY", "-V", RDoc::VISIBILITIES + [:nodoc],
|
2010-12-19 22:22:49 -05:00
|
|
|
"Minimum visibility to document a method.",
|
2013-09-18 19:33:36 -04:00
|
|
|
"One of 'public', 'protected' (the default),",
|
|
|
|
"'private' or 'nodoc' (show everything)") do |value|
|
2010-12-19 22:22:49 -05:00
|
|
|
@visibility = value
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
markup_formats = RDoc::Text::MARKUP_FORMAT.keys.sort
|
|
|
|
|
|
|
|
opt.on("--markup=MARKUP", markup_formats,
|
|
|
|
"The markup format for the named files.",
|
|
|
|
"The default is rdoc. Valid values are:",
|
|
|
|
markup_formats.join(', ')) do |value|
|
|
|
|
@markup = value
|
|
|
|
end
|
|
|
|
|
2012-11-27 03:54:03 -05:00
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--root=ROOT", Directory,
|
|
|
|
"Root of the source tree documentation",
|
|
|
|
"will be generated for. Set this when",
|
|
|
|
"building documentation outside the",
|
|
|
|
"source directory. Default is the",
|
|
|
|
"current directory.") do |root|
|
|
|
|
@root = Pathname(root)
|
|
|
|
end
|
|
|
|
|
2012-12-11 02:44:56 -05:00
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--page-dir=DIR", Directory,
|
|
|
|
"Directory where guides, your FAQ or",
|
|
|
|
"other pages not associated with a class",
|
|
|
|
"live. Set this when you don't store",
|
|
|
|
"such files at your project root.",
|
|
|
|
"NOTE: Do not use the same file name in",
|
|
|
|
"the page dir and the root of your project") do |page_dir|
|
|
|
|
@page_dir = Pathname(page_dir)
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
opt.separator nil
|
|
|
|
opt.separator "Common generator options:"
|
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--force-output", "-O",
|
|
|
|
"Forces rdoc to write the output files,",
|
|
|
|
"even if the output directory exists",
|
|
|
|
"and does not seem to have been created",
|
|
|
|
"by rdoc.") do |value|
|
|
|
|
@force_output = value
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
generator_text = @generators.keys.map { |name| " #{name}" }.sort
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
opt.on("-f", "--fmt=FORMAT", "--format=FORMAT", @generators.keys,
|
2010-04-01 03:45:16 -04:00
|
|
|
"Set the output formatter. One of:", *generator_text) do |value|
|
2010-12-19 22:22:49 -05:00
|
|
|
check_generator
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@generator_name = value.downcase
|
|
|
|
setup_generator
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.on("--include=DIRECTORIES", "-i", PathArray,
|
2010-04-01 03:45:16 -04:00
|
|
|
"Set (or add to) the list of directories to",
|
|
|
|
"be searched when satisfying :include:",
|
|
|
|
"requests. Can be used more than once.") do |value|
|
|
|
|
@rdoc_include.concat value.map { |dir| dir.strip }
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2011-02-01 19:32:30 -05:00
|
|
|
opt.on("--[no-]coverage-report=[LEVEL]", "--[no-]dcov", "-C", Integer,
|
2010-12-19 22:22:49 -05:00
|
|
|
"Prints a report on undocumented items.",
|
|
|
|
"Does not generate files.") do |value|
|
2011-02-01 19:32:30 -05:00
|
|
|
value = 0 if value.nil? # Integer converts -C to nil
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
@coverage_report = value
|
|
|
|
@force_update = true if value
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
opt.on("--output=DIR", "--op", "-o",
|
|
|
|
"Set the output directory.") do |value|
|
|
|
|
@op_dir = value
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
2006-09-17 10:46:13 -04:00
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
opt.on("-d",
|
|
|
|
"Deprecated --diagram option.",
|
|
|
|
"Prevents firing debug mode",
|
|
|
|
"with legacy invocation.") do |value|
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
opt.separator 'HTML generator options:'
|
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--charset=CHARSET", "-c",
|
|
|
|
"Specifies the output HTML character-set.",
|
|
|
|
"Use --encoding instead of --charset if",
|
|
|
|
"available.") do |value|
|
|
|
|
@charset = value
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--hyperlink-all", "-A",
|
|
|
|
"Generate hyperlinks for all words that",
|
|
|
|
"correspond to known methods, even if they",
|
|
|
|
"do not start with '#' or '::' (legacy",
|
|
|
|
"behavior).") do |value|
|
|
|
|
@hyperlink_all = value
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--main=NAME", "-m",
|
|
|
|
"NAME will be the initial page displayed.") do |value|
|
|
|
|
@main_page = value
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--[no-]line-numbers", "-N",
|
|
|
|
"Include line numbers in the source code.",
|
|
|
|
"By default, only the number of the first",
|
|
|
|
"line is displayed, in a leading comment.") do |value|
|
|
|
|
@line_numbers = value
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
opt.on("--show-hash", "-H",
|
|
|
|
"A name of the form #name in a comment is a",
|
|
|
|
"possible hyperlink to an instance method",
|
|
|
|
"name. When displayed, the '#' is removed",
|
|
|
|
"unless this option is specified.") do |value|
|
|
|
|
@show_hash = value
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
opt.on("--template=NAME", "-T", Template,
|
2010-04-01 03:45:16 -04:00
|
|
|
"Set the template used when generating",
|
2010-12-19 22:22:49 -05:00
|
|
|
"output. The default depends on the",
|
|
|
|
"formatter used.") do |(template, template_dir)|
|
|
|
|
@template = template
|
|
|
|
@template_dir = template_dir
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
opt.on("--template-stylesheets=FILES", PathArray,
|
|
|
|
"Set (or add to) the list of files to",
|
|
|
|
"include with the html template.") do |value|
|
|
|
|
@template_stylesheets << value
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
opt.on("--title=TITLE", "-t",
|
|
|
|
"Set TITLE as the title for HTML output.") do |value|
|
|
|
|
@title = value
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.on("--copy-files=PATH", Path,
|
|
|
|
"Specify a file or directory to copy static",
|
|
|
|
"files from.",
|
|
|
|
"If a file is given it will be copied into",
|
|
|
|
"the output dir. If a directory is given the",
|
|
|
|
"entire directory will be copied.",
|
|
|
|
"You can use this multiple times") do |value|
|
|
|
|
@static_path << value
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
opt.on("--webcvs=URL", "-W",
|
|
|
|
"Specify a URL for linking to a web frontend",
|
|
|
|
"to CVS. If the URL contains a '\%s', the",
|
|
|
|
"name of the current file will be",
|
|
|
|
"substituted; if the URL doesn't contain a",
|
|
|
|
"'\%s', the filename will be appended to it.") do |value|
|
|
|
|
@webcvs = value
|
2008-07-21 14:35:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
opt.separator nil
|
2010-12-19 22:22:49 -05:00
|
|
|
opt.separator "ri generator options:"
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--ri", "-r",
|
|
|
|
"Generate output for use by `ri`. The files",
|
|
|
|
"are stored in the '.rdoc' directory under",
|
|
|
|
"your home directory unless overridden by a",
|
|
|
|
"subsequent --op parameter, so no special",
|
|
|
|
"privileges are needed.") do |value|
|
2010-12-19 22:22:49 -05:00
|
|
|
check_generator
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
@generator_name = "ri"
|
2010-04-01 03:45:16 -04:00
|
|
|
@op_dir ||= RDoc::RI::Paths::HOMEDIR
|
2008-01-07 01:56:46 -05:00
|
|
|
setup_generator
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
|
|
|
opt.on("--ri-site", "-R",
|
|
|
|
"Generate output for use by `ri`. The files",
|
|
|
|
"are stored in a site-wide directory,",
|
|
|
|
"making them accessible to others, so",
|
|
|
|
"special privileges are needed.") do |value|
|
2010-12-19 22:22:49 -05:00
|
|
|
check_generator
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
@generator_name = "ri"
|
2013-09-18 19:33:36 -04:00
|
|
|
@op_dir = RDoc::RI::Paths.site_dir
|
2008-01-07 01:56:46 -05:00
|
|
|
setup_generator
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
2010-12-19 22:22:49 -05:00
|
|
|
opt.separator "Generic options:"
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.on("--write-options",
|
|
|
|
"Write .rdoc_options to the current",
|
|
|
|
"directory with the given options. Not all",
|
|
|
|
"options will be used. See RDoc::Options",
|
|
|
|
"for details.") do |value|
|
|
|
|
@write_options = true
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
opt.on("--[no-]dry-run",
|
|
|
|
"Don't write any files") do |value|
|
|
|
|
@dry_run = value
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.separator nil
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
opt.on("-D", "--[no-]debug",
|
|
|
|
"Displays lots on internal stuff.") do |value|
|
|
|
|
$DEBUG_RDOC = value
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.separator nil
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
opt.on("--[no-]ignore-invalid",
|
2010-12-19 22:22:49 -05:00
|
|
|
"Ignore invalid options and continue",
|
|
|
|
"(default true).") do |value|
|
2010-04-01 03:45:16 -04:00
|
|
|
ignore_invalid = value
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.separator nil
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
opt.on("--quiet", "-q",
|
|
|
|
"Don't show progress as we parse.") do |value|
|
|
|
|
@verbosity = 0
|
2008-01-07 01:56:46 -05:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.separator nil
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
opt.on("--verbose", "-V",
|
2010-12-19 22:22:49 -05:00
|
|
|
"Display extra progress as RDoc parses") do |value|
|
2010-04-01 03:45:16 -04:00
|
|
|
@verbosity = 2
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
opt.separator nil
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
opt.on("--version", "-v", "print the version") do
|
|
|
|
puts opt.version
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.separator nil
|
|
|
|
|
2014-09-04 21:41:25 -04:00
|
|
|
opt.on("--help", "-h", "Display this help") do
|
2010-12-19 22:22:49 -05:00
|
|
|
RDoc::RDoc::GENERATORS.each_key do |generator|
|
|
|
|
setup_generator generator
|
|
|
|
end
|
|
|
|
|
|
|
|
puts opt.help
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
opt.separator nil
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
setup_generator 'darkfish' if
|
|
|
|
argv.grep(/\A(-f|--fmt|--format|-r|-R|--ri|--ri-site)\b/).empty?
|
|
|
|
|
|
|
|
deprecated = []
|
|
|
|
invalid = []
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
begin
|
|
|
|
opts.parse! argv
|
2013-09-18 19:33:36 -04:00
|
|
|
rescue OptionParser::ParseError => e
|
2010-12-19 22:22:49 -05:00
|
|
|
if DEPRECATED[e.args.first] then
|
|
|
|
deprecated << e.args.first
|
|
|
|
elsif %w[--format --ri -r --ri-site -R].include? e.args.first then
|
|
|
|
raise
|
2010-04-01 03:45:16 -04:00
|
|
|
else
|
2010-12-19 22:22:49 -05:00
|
|
|
invalid << e.args.join(' ')
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
|
|
|
|
unless @generator then
|
|
|
|
@generator = RDoc::Generator::Darkfish
|
|
|
|
@generator_name = 'darkfish'
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
if @pipe and not argv.empty? then
|
|
|
|
@pipe = false
|
2010-12-19 22:22:49 -05:00
|
|
|
invalid << '-p (with files)'
|
2010-04-26 23:45:22 -04:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
unless quiet then
|
|
|
|
deprecated.each do |opt|
|
2017-11-27 05:45:24 -05:00
|
|
|
$stderr.puts 'option ' + opt + ' is deprecated: ' + DEPRECATED[opt]
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
2013-09-18 19:33:36 -04:00
|
|
|
end
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
unless invalid.empty? then
|
|
|
|
invalid = "invalid options: #{invalid.join ', '}"
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
if ignore_invalid then
|
|
|
|
unless quiet then
|
2010-12-19 22:22:49 -05:00
|
|
|
$stderr.puts invalid
|
|
|
|
$stderr.puts '(invalid options are ignored)'
|
2013-09-18 19:33:36 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
unless quiet then
|
2010-12-19 22:22:49 -05:00
|
|
|
$stderr.puts opts
|
|
|
|
end
|
2013-09-18 19:33:36 -04:00
|
|
|
$stderr.puts invalid
|
|
|
|
exit 1
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
2010-04-20 23:10:03 -04:00
|
|
|
end
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
@files = argv.dup
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2011-02-01 19:32:30 -05:00
|
|
|
finish
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
if @write_options then
|
|
|
|
write_options
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
##
|
|
|
|
# Don't display progress as we process the files
|
|
|
|
|
|
|
|
def quiet
|
|
|
|
@verbosity.zero?
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Set quietness to +bool+
|
|
|
|
|
|
|
|
def quiet= bool
|
2008-07-21 14:35:14 -04:00
|
|
|
@verbosity = bool ? 0 : 1
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# Removes directories from +path+ that are outside the current directory
|
|
|
|
|
|
|
|
def sanitize_path path
|
|
|
|
require 'pathname'
|
|
|
|
dot = Pathname.new('.').expand_path
|
|
|
|
|
|
|
|
path.reject do |item|
|
|
|
|
path = Pathname.new(item).expand_path
|
2019-10-27 12:44:09 -04:00
|
|
|
is_reject = nil
|
|
|
|
relative = nil
|
|
|
|
begin
|
|
|
|
relative = path.relative_path_from(dot).to_s
|
|
|
|
rescue ArgumentError
|
|
|
|
# On Windows, sometimes crosses different drive letters.
|
|
|
|
is_reject = true
|
|
|
|
else
|
|
|
|
is_reject = relative.start_with? '..'
|
|
|
|
end
|
|
|
|
is_reject
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-07 01:56:46 -05:00
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Set up an output generator for the named +generator_name+.
|
|
|
|
#
|
|
|
|
# If the found generator responds to :setup_options it will be called with
|
|
|
|
# the options instance. This allows generators to add custom options or set
|
|
|
|
# default options.
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def setup_generator generator_name = @generator_name
|
|
|
|
@generator = @generators[generator_name]
|
2008-01-07 01:56:46 -05:00
|
|
|
|
|
|
|
unless @generator then
|
2010-12-19 22:22:49 -05:00
|
|
|
raise OptionParser::InvalidArgument,
|
|
|
|
"Invalid output formatter #{generator_name}"
|
2003-12-16 00:44:25 -05:00
|
|
|
end
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
return if @generator_options.include? @generator
|
|
|
|
|
|
|
|
@generator_name = generator_name
|
|
|
|
@generator_options << @generator
|
|
|
|
|
2011-02-01 19:32:30 -05:00
|
|
|
if @generator.respond_to? :setup_options then
|
|
|
|
@option_parser ||= OptionParser.new
|
2011-02-05 01:20:57 -05:00
|
|
|
@generator.setup_options self
|
2011-02-01 19:32:30 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-01-07 01:56:46 -05:00
|
|
|
|
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Finds the template dir for +template+
|
2008-01-07 01:56:46 -05:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def template_dir_for template
|
|
|
|
template_path = File.join 'rdoc', 'generator', 'template', template
|
|
|
|
|
|
|
|
$LOAD_PATH.map do |path|
|
|
|
|
File.join File.expand_path(path), template_path
|
|
|
|
end.find do |dir|
|
|
|
|
File.directory? dir
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-04 21:41:25 -04:00
|
|
|
# Sets the minimum visibility of a documented method.
|
|
|
|
#
|
|
|
|
# Accepts +:public+, +:protected+, +:private+, +:nodoc+, or +:all+.
|
|
|
|
#
|
|
|
|
# When +:all+ is passed, visibility is set to +:private+, similarly to
|
|
|
|
# RDOCOPT="--all", see #visibility for more information.
|
|
|
|
|
|
|
|
def visibility= visibility
|
|
|
|
case visibility
|
|
|
|
when :all
|
|
|
|
@visibility = :private
|
|
|
|
else
|
|
|
|
@visibility = visibility
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# Displays a warning using Kernel#warn if we're being verbose
|
|
|
|
|
|
|
|
def warn message
|
|
|
|
super message if @verbosity > 1
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Writes the YAML file .rdoc_options to the current directory containing the
|
|
|
|
# parsed options.
|
|
|
|
|
|
|
|
def write_options
|
|
|
|
RDoc.load_yaml
|
|
|
|
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open '.rdoc_options', 'w' do |io|
|
2016-09-07 18:23:38 -04:00
|
|
|
io.set_encoding Encoding::UTF_8
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
YAML.dump self, io
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|