lib/reap/task/rdoc.rb in reap-4.3.2 vs lib/reap/task/rdoc.rb in reap-4.3.3

- old
+ new

@@ -1,76 +1,102 @@ require 'reap/task' +# ___ _ _____ _ +# | _ \__| |___ __ |_ _|_ _ __| |__ +# | / _` / _ \/ _| | |/ _` (_-< / / +# |_|_\__,_\___/\__| |_|\__,_/__/_\_\ # -# RDoc Task -# + +# = RDoc Task + class Reap::RDoc < Reap::Task + MUST_EXCLUDE = [ 'InstalledFiles', 'CVS/**/*' ] + task_desc "Generate RDocs." - attr_accessor :dir, :main, :title, :template, - :include, :exclude, :options + task_help %{ + reap rdoc + + Generate RDoc doumentation. + + dir Directory to store documentation [doc]. + main File to use as main page of RDocs. + title Project title to use in RDocs. + template Which RDoc template to use. + include Files to include in RDocs. + exclude Files to exclude from those. + options Pass-thru extra options to RDoc command. + + } + + task_attr :doc + + # Setup documentation task. + def init - @dir ||= 'doc' - @main ||= 'README' - @title ||= master["title"] - @template ||= 'html' # 'jamis' - @include ||= [ 'A-Z*', 'lib/**/*', 'ext/**/*' ] - @exclude ||= [ 'demo/**/*', 'example/**/*', 'sample/**/*' ] - @options ||= ['--merge', '--all'] + doc.dir ||= 'doc' + doc.main ||= 'README' + doc.title ||= master.title + doc.template ||= 'html' # 'jamis' + doc.include ||= [ 'A-Z*', 'lib/**/*', 'ext/**/*' ] + doc.exclude ||= [ 'demo/**/*', 'example/**/*', 'sample/**/*' ] + doc.options ||= ['--merge', '--all'] end + # Run the Ruby documentation task. + def run - must_exclude = [ 'InstalledFiles', 'CVS/**/*' ] + #must_exclude = [ 'InstalledFiles', 'CVS/**/*' ] - if !File.exists?(@main) or File.directory?(@main) - warn "Specified RDoc Main file #{@main} not found. Ignored." - @main = nil + if !File.exists?(doc.main) or File.directory?(doc.main) + warn "WARNING! Specified RDoc Main file #{doc.main} not found." + doc.main = nil end - rdoc_dir = File.expand_path(@dir) + rdoc_dir = File.expand_path(doc.dir) - if FileTest.directory?(@dir) - print "Directory '#{@dir}' already exists. Clobber? [y/N] " + if FileTest.directory?(doc.dir) + print "Directory '#{doc.dir}' already exists. Clobber? [y/N] " until inp = $stdin.gets[0,1] ; sleep 1 ; end ; puts if (inp || 'y').downcase == 'y' puts "Removing old directory '#{rdoc_dir}'..." #FileUtils.mkdir_p(".trash") unless FileTest.directory?(".trash") - #trashdir = ".trash/#{File.basename(@dir)}" + #trashdir = ".trash/#{File.basename(doc.dir)}" #FileUtils.rm_r(trashdir) if FileTest.exists?(trashdir) - #FileUtils.mv(@dir, trashdir) - FileUtils.rm_r(@dir) unless $PRETEND + #FileUtils.mv(doc.dir, trashdir) + FileUtils.rm_r(doc.dir) unless $PRETEND else puts "Reap rdoc task canceled." return nil end end rdoc_target = "#{rdoc_dir}/index.html" exc = [] - (@exclude + must_exclude).each{ |e| + (doc.exclude + MUST_EXCLUDE).each{ |e| exc << e exc |= Dir.glob(e+'/**/*') } inc = Dir.glob('[A-Z]*') - @include.each{ |i| inc |= Dir.glob(i) } + doc.include.each{ |i| inc |= Dir.glob(i) } inc -= exc inc = inc.select{ |f| File.file?(f) } rdoc_files = inc rdoc_files = '"' << rdoc_files.join('" "') << '"' # build options string build = [] - build += @options - build << "--main '#{@main}'" if @main - build << "--title '#{@title}'" if @title - build << "-T '#{@template}'" if @template + build += doc.options + build << "--main '#{doc.main}'" if doc.main + build << "--title '#{doc.title}'" if doc.title + build << "-T '#{doc.template}'" if doc.template rdoc_opts = build.join(' ') # do it! puts "Reap is shelling work out to RDoc..." sh %{rdoc -o #{rdoc_dir} #{rdoc_opts} #{rdoc_files}}