tasks.rb |
|
---|---|
Rocco Rake TasksTo use the Rocco Rake tasks, require
This creates a
It’s a good idea to guard against Rocco not being available, since your Rakefile will fail to load otherwise. Consider doing something like this, so that your Rakefile will still work
It’s also possible to pass a glob pattern:
Or a list of glob patterns:
Finally, it is also possible to specify which Pygments language you would
like to use to highlight the code, as well as the comment characters for the
language in the Rocco::make ‘html/’, ‘lib/thing/*/.rb’, {
} |
|
Might be nice to defer this until we actually need to build docs but this will have to do for now. |
require 'rocco' |
Reopen the Rocco class and add a |
class Rocco
def self.make(dest='docs/', source_files='lib/**/*.rb', options={})
Task.new(:rocco, dest, source_files, options)
end |
|
class Task
def initialize(task_name, dest='docs/', sources='lib/**/*.rb', options={})
@name = task_name
@dest = dest[-1] == ?/ ? dest : "#{dest}/"
@sources = FileList[sources]
@options = options |
Make sure there’s a |
define_directory_task @dest |
Run over the source file list, constructing destination filenames and defining file tasks. |
@sources.each do |source_file|
dest_file = File.basename(source_file).split('.')[0..-2].join('.') + '.html'
define_file_task source_file, "#{@dest}#{dest_file}" |
If |
CLEAN.include "#{@dest}#{dest_file}" if defined? CLEAN
end
end |
Define the destination directory task and make the |
def define_directory_task(path)
directory path
task @name => path
end |
Setup a You can run these tasks directly with Rake:
… would generate the |
def define_file_task(source_file, dest_file)
prerequisites = [@dest, source_file] + rocco_source_files
file dest_file => prerequisites do |f|
verbose { puts "rocco: #{source_file} -> #{dest_file}" }
rocco = Rocco.new(source_file, @sources.to_a, @options)
File.open(dest_file, 'wb') { |fd| fd.write(rocco.to_html) }
end
task @name => dest_file
end |
Return a |
def rocco_source_files
libdir = File.expand_path('../..', __FILE__)
FileList["#{libdir}/rocco.rb", "#{libdir}/rocco/**"]
end
end
end |