require 'reap/task' # ___ _ _____ _ # | _ \__| |___ __ |_ _|_ _ __| |__ # | / _` / _ \/ _| | |/ _` (_-< / / # |_|_\__,_\___/\__| |_|\__,_/__/_\_\ # # = RDoc Task # # This task generates RDoc API documentation trom source # comments. # # rdoc: # 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. # class Reap::RDoc < Reap::Task MUST_EXCLUDE = [ 'InstalledFiles', 'CVS/**/*' ] task_desc "Generate RDoc API documentation." 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. } alias_method :doc, :task def run # setup 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'] doc.include = [ doc.include ].flatten doc.exclude = [ doc.exclude ].flatten doc.options = [ doc.options ].flatten # document 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) q = "Directory '#{doc.dir}' already exists. Clobber?" #until inp = $stdin.gets[0,1] ; sleep 1 ; end ; puts inp = ask( q, 'yN' ) case inp.downcase when 'y', 'yes', 'okay' tell "Removing old directory '#{rdoc_dir}'..." FileUtils.rm_r(doc.dir) unless $PRETEND else tell "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(' ') #-- # SHELL OUT! Can RDoc be called from code? #++ # do it! tell "Reap is shelling work out to RDoc..." sh %{rdoc -o #{rdoc_dir} #{rdoc_opts} #{rdoc_files}} end end # Rake interface. if defined?(Rake) #require 'reap/rake/adapter' module Rake ReapRDoc = ::Reap::RakeAdapter( ::Reap::RDoc ) end end