Delicious rake feature

written by zsombor on April 28th, 2005 @ 10:57 AM

Found something delicious yesterday that I was totally unaware of. But then again surprising things can happen when using the proper tool for the job. Rake tasks (or targets in make tool parlance) have extensible actions and prerequisites.

For example here standard rdoc tasks are created via the Rake::RDocTask class. However rdoc generated html files reference an image from directory that will not be published. Rdoc was not built to copy image files around and changing image’s location is not desirable either. Solution: we extend generated rdoc task to copy image into proper location. Simply define the task again.

#Generate the RDoc documentation
Rake::RDocTask.new { |rdoc|
  rdoc.rdoc_dir = 'doc'
  rdoc.title    = "Active Record -- Object-relation mapping put on rails"
  rdoc.options << '--line-numbers --inline-source --accessor cattr_accessor=object'
  rdoc.template = "#{ENV['template']}.rb" if ENV['template']
  rdoc.rdoc_files.include('README', 'RUNNING_UNIT_TESTS', 'CHANGELOG')
  rdoc.rdoc_files.include('lib/**/*.rb')
  rdoc.rdoc_files.exclude('lib/active_record/vendor/*')
  rdoc.rdoc_files.include('dev-utils/*.rb')
}

# Enhance rdoc task to copy referenced images also
task :rdoc do
  FileUtils.copy "examples/associations.png", "doc/files/examples/associations.png"
end

And this magic is by rake’s design not by accident. Multiple target definitions append their prerequisites and actions to original ones.

Post a comment

Options:

Size

Colors