Permalink
Browse files

Update yardoc CLI to accept extra files after source files with '-' s…

…eparator

Example: yardoc lib/**/*.rb - FAQ LICENSE
  • Loading branch information...
1 parent 72a92e6 commit 8e8aebdf3e1b818f85c05f87cf56150daaae12f3 @lsegal committed Jul 6, 2009
Showing with 72 additions and 10 deletions.
  1. +12 −1 .yardopts
  2. +37 −9 lib/yard/cli/yardoc.rb
  3. +23 −0 spec/cli/yardoc_spec.rb
View
@@ -1 +1,12 @@
---files docs/WHATSNEW.markdown,docs/GETTING_STARTED.markdown,docs/OVERVIEW.markdown,docs/CODE_OBJECTS.markdown,docs/TAGS.markdown,docs/PARSER.markdown,docs/HANDLERS.markdown,docs/GENERATORS.markdown,docs/FAQ.markdown,docs/GLOSSARY.markdown,LICENSE
+-
+docs/WHATSNEW.markdown
+docs/GETTING_STARTED.markdown
+docs/OVERVIEW.markdown
+docs/CODE_OBJECTS.markdown
+docs/TAGS.markdown
+docs/PARSER.markdown
+docs/HANDLERS.markdown
+docs/GENERATORS.markdown
+docs/FAQ.markdown
+docs/GLOSSARY.markdown
+LICENSE
View
@@ -16,14 +16,14 @@ def initialize
:format => :html,
:template => :default,
:serializer => YARD::Serializers::FileSystemSerializer.new,
+ :files => [],
: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
@@ -56,14 +56,47 @@ def support_rdoc_document_file!
[]
end
+ def add_extra_files(*files)
+ files.map! {|f| f.include?("*") ? Dir.glob(f) : f }.flatten!
+ files.each do |file|
+ raise Errno::ENOENT, "Could not find extra file: #{file}" unless File.file?(file)
+ options[:files] << file
+ end
+ end
+
+ def parse_files(*files)
+ self.files = []
+ seen_extra_files_marker = false
+
+ files.each do |file|
+ if file == "-"
+ seen_extra_files_marker = true
+ next
+ end
+
+ if seen_extra_files_marker
+ add_extra_files(file)
+ else
+ self.files << file
+ end
+ end
+
+ self.files = ['lib/**/*.rb'] if self.files.empty?
+ end
+
def optparse(*args)
serialopts = SymbolHash.new
opts = OptionParser.new
- opts.banner = "Usage: yardoc [options] [source files]"
+ opts.banner = "Usage: yardoc [options] [source_files [- extra_files]]"
opts.separator "(if a list of source files is omitted, lib/**/*.rb is used.)"
opts.separator ""
+ opts.separator "Example: yardoc -o documentation/ - FAQ LICENSE"
+ opts.separator " The above example outputs documentation for files in"
+ opts.separator " lib/**/*.rb to documentation/ including the extra files"
+ opts.separator " FAQ and LICENSE."
+ 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."
@@ -120,11 +153,7 @@ def optparse(*args)
end
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
+ add_extra_files *files.split(",")
end
opts.on('-m', '--markup MARKUP',
@@ -174,8 +203,7 @@ def optparse(*args)
end
# Last minute modifications
- self.files = args unless args.empty?
- self.reload = false if self.files.empty?
+ parse_files(*args) unless args.empty?
self.visibilities.uniq!
options[:serializer] ||= Serializers::FileSystemSerializer.new(serialopts)
end
View
@@ -40,4 +40,27 @@ class YARD::CLI::Yardoc; public :optparse end
@yardoc.options[:serializer].options[:basepath].should == :MYPATH
@yardoc.files.should == ["FILE1", "FILE2", "FILE3"]
end
+
+ it "should accept extra files if specified after '-' with source files" do
+ File.should_receive(:file?).with('extra_file1').and_return(true)
+ File.should_receive(:file?).with('extra_file2').and_return(true)
+ @yardoc.optparse *%w( file1 file2 - extra_file1 extra_file2 )
+ @yardoc.files.should == %w( file1 file2 )
+ @yardoc.options[:files].should == %w( extra_file1 extra_file2 )
+ end
+
+ it "should accept files section only containing extra files" do
+ @yardoc.optparse *%w( - LICENSE )
+ @yardoc.files.should == %w( lib/**/*.rb )
+ @yardoc.options[:files].should == %w( LICENSE )
+ end
+
+ it "should accept globs as extra files" do
+ Dir.should_receive(:glob).with('*.txt').and_return ['a.txt', 'b.txt']
+ File.should_receive(:file?).with('a.txt').and_return(true)
+ File.should_receive(:file?).with('b.txt').and_return(true)
+ @yardoc.optparse *%w( file1 file2 - *.txt )
+ @yardoc.files.should == %w( file1 file2 )
+ @yardoc.options[:files].should == %w( a.txt b.txt )
+ end
end

0 comments on commit 8e8aebd

Please sign in to comment.