Class: Rake::RDocTask

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

Constant Summary

Constants included from FileUtilsExt

FileUtilsExt::DEFAULT

Constants included from FileUtils

FileUtils::LN_SUPPORTED, FileUtils::RUBY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TaskLib

#paste

Methods included from FileUtilsExt

#nowrite, #rake_check_options, #rake_merge_option, #rake_output_message, #verbose, #when_writing

Methods included from FileUtils

#ruby, #safe_ln, #sh, #split_all

Methods included from Cloneable

#initialize_copy

Constructor Details

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

Returns a new instance of RDocTask.

Yields:

  • (_self)

Yield Parameters:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/rake/rdoctask.rb', line 112

def initialize(name = :rdoc)  # :yield: self
  if name.is_a?(Hash)
    invalid_options = name.keys.map { |k| k.to_sym } - [:rdoc, :clobber_rdoc, :rerdoc]
    if !invalid_options.empty?
      raise ArgumentError, "Invalid option(s) passed to RDocTask.new: #{invalid_options.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

#externalObject

Returns the value of attribute external



106
107
108
# File 'lib/rake/rdoctask.rb', line 106

def external
  @external
end

#inline_sourceObject

Returns the value of attribute inline_source



108
109
110
# File 'lib/rake/rdoctask.rb', line 108

def inline_source
  @inline_source
end

#mainObject

Returns the value of attribute main



94
95
96
# File 'lib/rake/rdoctask.rb', line 94

def main
  @main
end

#nameObject

Returns the value of attribute name



84
85
86
# File 'lib/rake/rdoctask.rb', line 84

def name
  @name
end

#optionsObject

Returns the value of attribute options



103
104
105
# File 'lib/rake/rdoctask.rb', line 103

def options
  @options
end

#rdoc_dirObject

Returns the value of attribute rdoc_dir



87
88
89
# File 'lib/rake/rdoctask.rb', line 87

def rdoc_dir
  @rdoc_dir
end

#rdoc_filesObject

Returns the value of attribute rdoc_files



100
101
102
# File 'lib/rake/rdoctask.rb', line 100

def rdoc_files
  @rdoc_files
end

#templateObject

Returns the value of attribute template



97
98
99
# File 'lib/rake/rdoctask.rb', line 97

def template
  @template
end

#titleObject

Returns the value of attribute title



90
91
92
# File 'lib/rake/rdoctask.rb', line 90

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.



194
195
196
# File 'lib/rake/rdoctask.rb', line 194

def before_running_rdoc(&block)
  @before_running_rdoc = block
end

#defineObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/rake/rdoctask.rb', line 134

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_listObject



169
170
171
172
173
174
175
176
177
# File 'lib/rake/rdoctask.rb', line 169

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_stringObject



187
188
189
# File 'lib/rake/rdoctask.rb', line 187

def option_string
  option_list.join(' ')
end

#quote(str) ⇒ Object



179
180
181
182
183
184
185
# File 'lib/rake/rdoctask.rb', line 179

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