Class: Rake::RDocTask

Inherits:
TaskLib show all
Defined in:
lib/rake/rdoctask.rb

Overview

Create a documentation task that will generate the RDoc files for a project.

The RDocTask will create the following targets:

rdoc

Main task for this RDOC task.

:clobber_rdoc

Delete all the rdoc files. This target is automatically added to the main clobber target.

:rerdoc

Rebuild the rdoc files from scratch, even if they are not out of date.

Simple Example:

Rake::RDocTask.new do |rd|
  rd.main = "README.rdoc"
  rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
end

You may wish to give the task a different name, such as if you are generating two sets of documentation. For instance, if you want to have a development set of documentation including private methods:

Rake::RDocTask.new(:rdoc_dev) do |rd|
  rd.main = "README.doc"
  rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
  rd.options << "--all"
end

The tasks would then be named :rdoc_dev, :clobber_rdoc_dev, and :rerdoc_dev.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TaskLib

#paste

Methods included from Cloneable

#clone, #dup

Constructor Details

#initialize(name = :rdoc) {|_self| ... } ⇒ RDocTask

Create an RDoc task named rdoc. Default task name is rdoc.

Yields:

  • (_self)

Yield Parameters:



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rake/rdoctask.rb', line 71

def initialize(name=:rdoc)  # :yield: self
  @name = name
  @rdoc_files = Rake::FileList.new
  @rdoc_dir = 'html'
  @main = nil
  @title = nil
  @template = nil
  @external = false
  @options = []
  yield self if block_given?
  define
end

Instance Attribute Details

#externalObject

Run the rdoc process as an external shell (default is false)



68
69
70
# File 'lib/rake/rdoctask.rb', line 68

def external
  @external
end

#mainObject

Name of file to be used as the main, top level file of the RDoc. (default is none)



56
57
58
# File 'lib/rake/rdoctask.rb', line 56

def main
  @main
end

#nameObject

Name of the main, top level task. (default is :rdoc)



46
47
48
# File 'lib/rake/rdoctask.rb', line 46

def name
  @name
end

#optionsObject

List of options to be passed rdoc. (default is [])



65
66
67
# File 'lib/rake/rdoctask.rb', line 65

def options
  @options
end

#rdoc_dirObject

Name of directory to receive the html output files. (default is “html”)



49
50
51
# File 'lib/rake/rdoctask.rb', line 49

def rdoc_dir
  @rdoc_dir
end

#rdoc_filesObject

List of files to be included in the rdoc generation. (default is [])



62
63
64
# File 'lib/rake/rdoctask.rb', line 62

def rdoc_files
  @rdoc_files
end

#templateObject

Name of template to be used by rdoc. (defaults to rdoc’s default)



59
60
61
# File 'lib/rake/rdoctask.rb', line 59

def template
  @template
end

#titleObject

Title of RDoc documentation. (default is none)



52
53
54
# File 'lib/rake/rdoctask.rb', line 52

def title
  @title
end

Instance Method Details

#defineObject

Create the tasks defined by this task lib.



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
117
# File 'lib/rake/rdoctask.rb', line 85

def define
  if name.to_s != "rdoc"
    desc "Build the RDOC HTML Files"
  end

  desc "Build the #{name} HTML Files"
  task name
  
  desc "Force a rebuild of the RDOC files"
  task "re#{name}" => ["clobber_#{name}", name]
  
  desc "Remove rdoc products" 
  task "clobber_#{name}" do
    rm_r rdoc_dir rescue nil
  end
  
  task :clobber => ["clobber_#{name}"]
  
  directory @rdoc_dir
  task name => [rdoc_target]
  file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
    rm_r @rdoc_dir rescue nil
    args = option_list + @rdoc_files
    if @external
      argstring = args.join(' ')
      sh %{ruby -Ivendor vender/rd #{argstring}}
    else
      require 'rdoc/rdoc'
      RDoc::RDoc.new.document(args)
    end
  end
  self
end

#option_listObject



119
120
121
122
123
124
125
126
# File 'lib/rake/rdoctask.rb', line 119

def option_list
  result = @options.dup
  result << "-o" << @rdoc_dir
  result << "--main" << quote(main) if main
  result << "--title" << quote(title) if title
  result << "-T" << quote(template) if template
  result
end

#option_stringObject



136
137
138
# File 'lib/rake/rdoctask.rb', line 136

def option_string
  option_list.join(' ')
end

#quote(str) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/rake/rdoctask.rb', line 128

def quote(str)
  if @external
    "'#{str}'"
  else
    str
  end
end