#-- # ___ _ # | _ \__| |___ __ # | / _` / _ \/ _| # |_|_\__,_\___/\__| # #++ module Reap # = RDoc # # This class generates RDoc API documentation from source # comments. # # title Project title to use in RDocs. # dir Directory to store documentation [doc]. # main File to use as main page of 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 RDoc # < Task include TaskUtils MUST_EXCLUDE = [ 'InstalledFiles', 'CVS/**/*', '_darcs/**/*' ] # Note that ++dir++ is not offset by trunk. attr_accessor :dir, :main, :title, :template, :trunk, :include, :exclude, :options def initialize( doc ) # set default values @dir = 'doc' @main = 'README' #@title ||= master.title @template = 'html' # 'jamis' @include = [ 'A-Z*', 'lib/**/*', 'ext/**/*' ] #, @main ] @exclude = [ 'demo/**/*', 'example/**/*', 'sample/**/*' ] @options = ['--merge', '--all'] super @include = [ @include, @main ].flatten @exclude = [ @exclude ].flatten @options = [ @options ].flatten end # Generate RDocs. def generate @rdoc_dir = File.expand_path(@dir) if @trunk Dir.chdir( @trunk ) { generate_rdocs } else generate_rdocs end end alias_method :call, :generate private def generate_rdocs # warn if main file doesn't exist if !File.exists?(@main) or File.directory?(@main) warn "WARNING! Specified RDoc Main file #{@main} not found." @main = nil end if FileTest.directory?(@rdoc_dir) q = "Directory '#{@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(@rdoc_dir) unless $PRETEND else tell "Reap rdoc task canceled." return nil end end #rdoc_target = "#{@rdoc_dir}/index.html" exc = [] (@exclude + MUST_EXCLUDE).each{ |e| exc << e exc |= Dir.glob(e+'/**/*') } inc = Dir.glob('[A-Z]*') @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 rdoc_opts = build.join(' ') #-- # SHELL OUT! Can RDoc be called from code? #++ tell "Reap is shelling work out to RDoc..." sh %{rdoc -o #{@rdoc_dir} #{rdoc_opts} #{rdoc_files}} end end end #module Reap