lib/yard/cli/yardoc.rb in yard-0.2.2 vs lib/yard/cli/yardoc.rb in yard-0.2.3

- old
+ new

@@ -1,50 +1,75 @@ require 'optparse' module YARD module CLI class Yardoc + DEFAULT_YARDOPTS_FILE = ".yardopts" + attr_reader :options, :visibilities attr_accessor :files, :reload, :generate + attr_accessor :options_file def self.run(*args) new.run(*args) end def initialize @options = SymbolHash[ :format => :html, :template => :default, :serializer => YARD::Serializers::FileSystemSerializer.new, - :readme => ['README', 'README.txt'], :verifier => lambda do |gen, obj| return false if gen.respond_to?(:visibility) && !visibilities.include?(gen.visibility) end ] @visibilities = [:public] @reload = true @generate = true @files = ['lib/**/*.rb'] + @options_file = DEFAULT_YARDOPTS_FILE end def run(*args) + args += support_rdoc_document_file! + optparse(*yardopts) optparse(*args) Registry.load(files, reload) if generate - Generators::FullDocGenerator.new(options).generate Registry.all(:module, :class) + Generators::FullDocGenerator.new(options).generate(all_objects) end end + + def all_objects + Registry.all(:root, :module, :class) + end + def yardopts + IO.read(options_file).split(/\s+/) + rescue Errno::ENOENT + [] + end + private + def support_rdoc_document_file! + IO.read(".document").split(/\s+/) + rescue Errno::ENOENT + [] + end + def optparse(*args) serialopts = SymbolHash.new opts = OptionParser.new opts.banner = "Usage: yardoc [options] [source files]" opts.separator "(if a list of source files is omitted, lib/**/*.rb is used.)" opts.separator "" + opts.separator "A base set of options can be specified by adding a .yardopts" + opts.separator "file to your base path containing all extra options separated" + opts.separator "by whitespace." + opts.separator "" opts.separator "General Options:" opts.on('-c', '--use-cache [FILE]', 'Use the cached .yardoc db to generate documentation. (defaults to no cache)') do |file| YARD::Registry.yardoc_file = file if file @@ -63,10 +88,14 @@ if !require(file.gsub(/\.rb$/, '')) log.error "The file `#{file}' was already loaded, perhaps you need to specify the absolute path to avoid name collisions." exit end end + + opts.on('--legacy', 'Use old style parser and handlers. Unavailable under Ruby 1.8.x') do + YARD::Parser::SourceParser.parser_type = :ruby18 + end opts.separator "" opts.separator "Output options:" opts.on('--no-public', "Don't show public methods. (default shows public)") do @@ -78,28 +107,52 @@ end opts.on('--private', "Show or don't show private methods. (default hides private)") do visibilities.push(:private) end - + + opts.on('--no-highlight', "Don't highlight code in docs as Ruby.") do + options[:no_highlight] = true + end + opts.on('-r', '--readme FILE', 'The readme file used as the title page of documentation.') do |readme| + raise Errno::ENOENT, readme unless File.file?(readme) options[:readme] = readme end - opts.on('-d', '--output-dir PATH', + opts.on('--files FILE1,FILE2,...', 'Any extra comma separated static files to be included (eg. FAQ)') do |files| + options[:files] = [] + files.split(",").each do |file| + raise Errno::ENOENT, file unless File.file?(file) + options[:files] << file + end + end + + opts.on('-m', '--markup MARKUP', + 'Markup style used in documentation, like textile, markdown or rdoc. (defaults to rdoc)') do |markup| + options[:markup] = markup.to_sym + end + + opts.on('-M', '--markup-provider MARKUP_PROVIDER', + 'Overrides the library used to process markup formatting (specify the gem name)') do |markup_provider| + options[:markup_provider] = markup_provider.to_sym + end + + opts.on('-o', '--output-dir PATH', 'The output directory. (defaults to ./doc)') do |dir| + options[:serializer] = nil serialopts[:basepath] = dir end opts.on('-t', '--template TEMPLATE', 'The template to use. (defaults to "default")') do |template| options[:template] = template.to_sym end opts.on('-p', '--template-path PATH', 'The template path to look for templates in. (used with -t).') do |path| - YARD::Generator::Base.register_template_path(path) + YARD::Generators::Base.register_template_path(path) end opts.on('-f', '--format FORMAT', 'The output format for the template. (defaults to html)') do |format| options[:format] = format @@ -121,11 +174,11 @@ end # Last minute modifications self.files = args unless args.empty? self.reload = false if self.files.empty? - visibilities.uniq! - options[:serializer] = Serializers::FileSystemSerializer.new(serialopts) + self.visibilities.uniq! + options[:serializer] ||= Serializers::FileSystemSerializer.new(serialopts) end end end -end \ No newline at end of file +end