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 PackageTask will create the following targets:

rdoc

Main task for this RDOC task.

:clobber_rdoc

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

:rerdoc

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

Simple Example:

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:

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

#clone, #paste

Constructor Details

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

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

Yields:

  • (_self)

Yield Parameters:



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rake/rdoctask.rb', line 68

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

Instance Attribute Details

#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. (default is ‘html’)



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.



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

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 paste("re", name) => [paste("clobber_", name), name]
  
  desc "Remove rdoc products" 
  task paste("clobber_", name) do
	rm_r rdoc_dir rescue nil
  end

  task :clobber => [paste("clobber_", name)]
  
  directory @rdoc_dir
  task name => [rdoc_target]
  file rdoc_target => @rdoc_files + [$rakefile] do
	rm_r @rdoc_dir rescue nil
	opts = option_list.join(' ')
	sh %{rdoc -o #{@rdoc_dir} #{opts} #{@rdoc_files}}
  end
  self
end

#option_listObject



109
110
111
112
113
114
115
# File 'lib/rake/rdoctask.rb', line 109

def option_list
  result = @options.dup
  result << "--main" << "'#{main}'" if main
  result << "--title" << "'#{title}'" if title
  result << "-T" << "'#{template}'" if template
  result
end

#option_stringObject



117
118
119
# File 'lib/rake/rdoctask.rb', line 117

def option_string
  option_list.join(' ')
end