lib/yard/cli/yardoc.rb in yard-0.8.2.1 vs lib/yard/cli/yardoc.rb in yard-0.8.3
- old
+ new
@@ -136,14 +136,11 @@
# You can do this by deleting the +.yardoc+ directory manually, or running
# Yardoc without +--use-cache+ (+-c+).
#
# @since 0.2.1
# @see Verifier
- class Yardoc < Command
- # The configuration filename to load extra options from
- DEFAULT_YARDOPTS_FILE = ".yardopts"
-
+ class Yardoc < YardoptsCommand
# @return [Hash] the hash of options passed to the template.
# @see Templates::Engine#render
attr_reader :options
# @return [Array<String>] list of Ruby source files to process
@@ -156,30 +153,20 @@
# @return [Boolean] whether to use the existing yardoc db if the
# .yardoc already exists. Also makes use of file checksums to
# parse only changed files.
attr_accessor :use_cache
- # @return [Boolean] whether to parse options from .yardopts
- attr_accessor :use_yardopts_file
-
- # @return [Boolean] whether to parse options from .document
- attr_accessor :use_document_file
-
# @return [Boolean] whether objects should be serialized to .yardoc db
attr_accessor :save_yardoc
# @return [Boolean] whether to generate output
attr_accessor :generate
# @return [Boolean] whether to print a list of objects
# @since 0.5.5
attr_accessor :list
- # The options file name (defaults to {DEFAULT_YARDOPTS_FILE})
- # @return [String] the filename to load extra options from
- attr_accessor :options_file
-
# Keep track of which visibilities are to be shown
# @return [Array<Symbol>] a list of visibilities
# @since 0.5.6
attr_accessor :visibilities
@@ -214,14 +201,11 @@
@assets = {}
@excluded = []
@files = []
@hidden_tags = []
@use_cache = false
- @use_yardopts_file = true
- @use_document_file = true
@generate = true
- @options_file = DEFAULT_YARDOPTS_FILE
@statistics = true
@list = false
@save_yardoc = true
@has_markup = false
@@ -277,17 +261,12 @@
# Parses commandline arguments
# @param [Array<String>] args the list of arguments
# @return [Boolean] whether or not arguments are valid
# @since 0.5.6
def parse_arguments(*args)
- parse_yardopts_options(*args)
+ super(*args)
- # Parse files and then command line arguments
- optparse(*support_rdoc_document_file!) if use_document_file
- optparse(*yardopts) if use_yardopts_file
- optparse(*args)
-
# Last minute modifications
self.files = ['{lib,app}/**/*.rb', 'ext/**/*.c'] if self.files.empty?
self.files.delete_if {|x| x =~ /\A\s*\Z/ } # remove empty ones
readme = Dir.glob('README*').first
readme ||= Dir.glob(files.first).first if options.onefile
@@ -296,10 +275,12 @@
Tags::Library.visible_tags -= hidden_tags
add_visibility_verifier
add_api_verifier
+ apply_locale
+
# US-ASCII is invalid encoding for onefile
if defined?(::Encoding) && options.onefile
if ::Encoding.default_internal == ::Encoding::US_ASCII
log.warn "--one-file is not compatible with US-ASCII encoding, using ASCII-8BIT"
::Encoding.default_external, ::Encoding.default_internal = ['ascii-8bit'] * 2
@@ -320,19 +301,10 @@
# @return [Array<CodeObjects::Base>] a list of code objects to process
def all_objects
Registry.all(:root, :module, :class)
end
- # Parses the .yardopts file for default yard options
- # @return [Array<String>] an array of options parsed from .yardopts
- def yardopts
- return [] unless use_yardopts_file
- File.read_binary(options_file).shell_split
- rescue Errno::ENOENT
- []
- end
-
private
# Generates output for objects
# @param [Hash, nil] checksums if supplied, a list of checkums for files.
# @return [void]
@@ -401,38 +373,14 @@
# @since 0.5.5
def print_list
Registry.load_all
run_verifier(Registry.all).
sort_by {|item| [item.file || '', item.line || 0] }.each do |item|
- puts "#{item.file}:#{item.line}: #{item.path}"
+ log.puts "#{item.file}:#{item.line}: #{item.path}"
end
end
- # Parses out the yardopts/document options
- def parse_yardopts_options(*args)
- opts = OptionParser.new
- opts.base.long.clear # HACK: why are --help and --version defined?
- yardopts_options(opts)
- begin
- opts.parse(args)
- rescue OptionParser::ParseError => err
- idx = args.index(err.args.first)
- args = args[(idx+1)..-1]
- args.shift while args.first && args.first[0,1] != '-'
- retry
- end
- end
-
- # Reads a .document file in the directory to get source file globs
- # @return [Array<String>] an array of files parsed from .document
- def support_rdoc_document_file!
- return [] unless use_document_file
- File.read(".document").gsub(/^[ \t]*#.+/m, '').split(/\s+/)
- rescue Errno::ENOENT
- []
- end
-
# Adds a set of extra documentation files to be processed
# @param [Array<String>] files the set of documentation files
def add_extra_files(*files)
files.map! {|f| f.include?("*") ? Dir.glob(f) : f }.flatten!
files.each do |file|
@@ -487,10 +435,19 @@
expr = "#{apis.uniq.inspect}.include?(@api.text)"
expr += " || !@api" if no_api
options.verifier.add_expressions(expr)
end
+ # Applies the specified locale to collected objects
+ # @return [void]
+ # @since 0.8.3
+ def apply_locale
+ options.files.each do |file|
+ file.locale = options.locale
+ end
+ end
+
# (see Templates::Helpers::BaseHelper#run_verifier)
def run_verifier(list)
options.verifier ? options.verifier.run(list) : list
end
@@ -567,29 +524,10 @@
opts.on('--exclude REGEXP', 'Ignores a file if it matches path match (regexp)') do |path|
self.excluded << path
end
end
- # Adds --[no-]yardopts / --[no-]document
- def yardopts_options(opts)
- opts.on('--[no-]yardopts [FILE]',
- "If arguments should be read from FILE",
- " (defaults to yes, FILE defaults to .yardopts)") do |use_yardopts|
- if use_yardopts.is_a?(String)
- self.options_file = use_yardopts
- self.use_yardopts_file = true
- else
- self.use_yardopts_file = (use_yardopts != false)
- end
- end
-
- opts.on('--[no-]document', "If arguments should be read from .document file. ",
- " (defaults to yes)") do |use_document|
- self.use_document_file = use_document
- end
- end
-
# Adds output options
def output_options(opts)
opts.separator ""
opts.separator "Output options:"
@@ -733,10 +671,22 @@
end
opts.on('--no-stats', 'Don\'t print statistics') do
self.statistics = false
end
+
+ opts.on('--locale LOCALE',
+ 'The locale for generated documentation.',
+ ' (defaults to en)') do |locale|
+ options.locale = locale
+ end
+
+ opts.on('--po-dir DIR',
+ 'The directory that has .po files.',
+ ' (defaults to #{YARD::Registry.po_dir})') do |dir|
+ YARD::Registry.po_dir = dir
+ end
end
# Adds tag options
# @since 0.6.0
def tag_options(opts)
@@ -765,11 +715,15 @@
opts.on('--hide-tag TAG', 'Hides a previously defined tag from templates') do |tag|
self.hidden_tags |= [tag.to_sym]
end
- opts.on('--transitive-tag TAG', 'Adds a transitive tag') do |tag|
- Tags::Library.transitive_tags += [tag.to_sym]
+ opts.on('--transitive-tag TAG', 'Marks a tag as transitive') do |tag|
+ Tags::Library.transitive_tags |= [tag.to_sym]
+ end
+
+ opts.on('--non-transitive-tag TAG', 'Marks a tag as not transitive') do |tag|
+ Tags::Library.transitive_tags -= [tag.to_sym]
end
end
end
end
end