Class: Rake::RDocTask
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
The rd
object passed to the block is an RDocTask object. See the attributes list for the RDocTask class for available customization options.
Specifying different task names
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. << "--all"
end
The tasks would then be named :rdoc_dev, :clobber_rdoc_dev, and :rerdoc_dev.
If you wish to have completely different task names, then pass a Hash as first argument. With the :rdoc
, :clobber_rdoc
and :rerdoc
options, you can customize the task names to your liking. For example:
Rake::RDocTask.new(:rdoc => "rdoc", :clobber_rdoc => "rdoc:clean", :rerdoc => "rdoc:force")
This will create the tasks :rdoc
, :rdoc_clean
and :rdoc:force
.
Instance Attribute Summary collapse
-
#external ⇒ Object
Whether to run the rdoc process as an external shell (default is false).
-
#inline_source ⇒ Object
Returns the value of attribute inline_source.
-
#main ⇒ Object
Name of file to be used as the main, top level file of the RDoc.
-
#name ⇒ Object
Name of the main, top level task.
-
#options ⇒ Object
Additional list of options to be passed rdoc.
-
#rdoc_dir ⇒ Object
Name of directory to receive the html output files.
-
#rdoc_files ⇒ Object
List of files to be included in the rdoc generation.
-
#template ⇒ Object
Name of template to be used by rdoc.
-
#title ⇒ Object
Title of RDoc documentation.
Instance Method Summary collapse
-
#before_running_rdoc(&block) ⇒ Object
The block passed to this method will be called just before running the RDoc generator.
-
#define ⇒ Object
Create the tasks defined by this task lib.
-
#initialize(name = :rdoc) {|_self| ... } ⇒ RDocTask
constructor
Create an RDoc task with the given name.
- #option_list ⇒ Object
- #option_string ⇒ Object
- #quote(str) ⇒ Object
Methods inherited from TaskLib
Methods included from Cloneable
Constructor Details
#initialize(name = :rdoc) {|_self| ... } ⇒ RDocTask
Create an RDoc task with the given name. See the RDocTask class overview for documentation.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rake/rdoctask.rb', line 89 def initialize(name = :rdoc) # :yield: self if name.is_a?(Hash) = name.keys.map { |k| k.to_sym } - [:rdoc, :clobber_rdoc, :rerdoc] if !.empty? raise ArgumentError, "Invalid option(s) passed to RDocTask.new: #{.join(", ")}" end end @name = name @rdoc_files = Rake::FileList.new @rdoc_dir = 'html' @main = nil @title = nil @template = nil @external = false @inline_source = true @options = [] yield self if block_given? define end |
Instance Attribute Details
#external ⇒ Object
Whether to run the rdoc process as an external shell (default is false)
83 84 85 |
# File 'lib/rake/rdoctask.rb', line 83 def external @external end |
#inline_source ⇒ Object
Returns the value of attribute inline_source.
85 86 87 |
# File 'lib/rake/rdoctask.rb', line 85 def inline_source @inline_source end |
#main ⇒ Object
Name of file to be used as the main, top level file of the RDoc. (default is none)
71 72 73 |
# File 'lib/rake/rdoctask.rb', line 71 def main @main end |
#name ⇒ Object
Name of the main, top level task. (default is :rdoc)
61 62 63 |
# File 'lib/rake/rdoctask.rb', line 61 def name @name end |
#options ⇒ Object
Additional list of options to be passed rdoc. (default is [])
80 81 82 |
# File 'lib/rake/rdoctask.rb', line 80 def @options end |
#rdoc_dir ⇒ Object
Name of directory to receive the html output files. (default is “html”)
64 65 66 |
# File 'lib/rake/rdoctask.rb', line 64 def rdoc_dir @rdoc_dir end |
#rdoc_files ⇒ Object
List of files to be included in the rdoc generation. (default is [])
77 78 79 |
# File 'lib/rake/rdoctask.rb', line 77 def rdoc_files @rdoc_files end |
#template ⇒ Object
Name of template to be used by rdoc. (defaults to rdoc’s default)
74 75 76 |
# File 'lib/rake/rdoctask.rb', line 74 def template @template end |
#title ⇒ Object
Title of RDoc documentation. (defaults to rdoc’s default)
67 68 69 |
# File 'lib/rake/rdoctask.rb', line 67 def title @title end |
Instance Method Details
#before_running_rdoc(&block) ⇒ Object
The block passed to this method will be called just before running the RDoc generator. It is allowed to modify RDocTask attributes inside the block.
171 172 173 |
# File 'lib/rake/rdoctask.rb', line 171 def before_running_rdoc(&block) @before_running_rdoc = block end |
#define ⇒ Object
Create the tasks defined by this task lib.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/rake/rdoctask.rb', line 111 def define if rdoc_task_name != "rdoc" desc "Build the RDOC HTML Files" else desc "Build the #{rdoc_task_name} HTML Files" end task rdoc_task_name desc "Force a rebuild of the RDOC files" task rerdoc_task_name => [clobber_task_name, rdoc_task_name] desc "Remove rdoc products" task clobber_task_name do rm_r rdoc_dir rescue nil end task :clobber => [clobber_task_name] directory @rdoc_dir task rdoc_task_name => [rdoc_target] file rdoc_target => @rdoc_files + [Rake.application.rakefile] do rm_r @rdoc_dir rescue nil @before_running_rdoc.call if @before_running_rdoc args = option_list + @rdoc_files if @external argstring = args.join(' ') sh %{ruby -Ivendor vendor/rd #{argstring}} else require 'rdoc/rdoc' RDoc::RDoc.new.document(args) end end self end |
#option_list ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/rake/rdoctask.rb', line 146 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 << "--inline-source" if inline_source && !@options.include?("--inline-source") && !@options.include?("-S") result end |
#option_string ⇒ Object
164 165 166 |
# File 'lib/rake/rdoctask.rb', line 164 def option_string option_list.join(' ') end |
#quote(str) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/rake/rdoctask.rb', line 156 def quote(str) if @external "'#{str}'" else str end end |