require 'reap/task' # ___ _ _____ _ # | _ \__| |___ __ |_ _|_ _ __| |__ # | / _` / _ \/ _| | |/ _` (_-< / / # |_|_\__,_\___/\__| |_|\__,_/__/_\_\ # # = RDoc Task class Reap::RDoc < Reap::Task MUST_EXCLUDE = [ 'InstalledFiles', 'CVS/**/*' ] task_desc "Generate RDocs." 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 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/**/*' ] 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(doc.dir) 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(doc.dir)}" #FileUtils.rm_r(trashdir) if FileTest.exists?(trashdir) #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 = [] (doc.exclude + MUST_EXCLUDE).each{ |e| exc << e exc |= Dir.glob(e+'/**/*') } inc = Dir.glob('[A-Z]*') 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 += 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}} end end