Class: Reap::RDoc

Inherits:
Task
  • Object
show all
Defined in:
lib/reap/task/rdoc.rb

Overview

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.

Constant Summary collapse

MUST_EXCLUDE =
[ 'InstalledFiles', 'CVS/**/*' ]

Constants inherited from Task

Task::RUBY

Instance Method Summary collapse

Methods inherited from Task

#ask, #execute, inherited, #initialize, #initiate, master, #master, #provide_setup_rb, #section, section_required, section_required?, #section_required?, #sh, #task, task_attr, #task_desc, task_desc, #task_help, task_help, task_list, #task_name, task_name, #tell, #use_subsection, verify?

Constructor Details

This class inherits a constructor from Reap::Task

Instance Method Details

#runObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/reap/task/rdoc.rb', line 49

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(' ')

  # do it!
  tell "Reap is shelling work out to RDoc..."
  sh %{rdoc -o #{rdoc_dir} #{rdoc_opts} #{rdoc_files}}
end