module Shoe
module Tasks
# Defines `rake ronn` to generate man pages from your
# {ronn}[http://rtomayko.github.com/ronn/] sources.
#
# To enable, create some man/*.ronn files.
#
# To configure the date and organization fields for your man pages, set the
# date[http://docs.rubygems.org/read/chapter/20#date]
# and the first of the
# authors[http://docs.rubygems.org/read/chapter/20#authors]
# in your gemspec, respectively.
#
# == Notes
#
# * It's best to include the generated man pages in your gem, so that
# {gem-man}[http://github.com/defunkt/gem-man] can get to them.
#
# * Ronn becomes a prerequisite for rake build, so your man pages
# are sure to be up-to-date.
#
# * You may like to add a task :man => :ronn to your
# Rakefile. I felt a little uncomfortable clogging that
# namespace without your consent.
class Ronn < Task
def active?
!ronn_files.empty?
end
def define
begin
require 'ronn'
rescue LoadError
warn "WARN: Please `gem install ronn`."
else
define_tasks
end
end
private
def define_tasks
desc <<-END.gsub(/^ */, '')
Generate man pages.
Configure via the `date` and `authors` fields in #{spec.name}.gemspec.
Uses ronn sources in man/*.ronn.
END
task :ronn => 'ronn:build' do
sh 'man', *man_files
end
namespace :ronn do
task :build => man_files
end
rule /\.\d$/ => '%p.ronn' do |task|
ronn('--roff', task.source)
end
if Rake::Task.task_defined?(:build)
task :build => 'ronn:build'
end
end
def ronn(format, file)
sh "ronn --build #{format} --date #{spec.date.strftime('%Y-%m-%d')} --manual='RubyGems Manual' --organization='#{spec.author}' #{file}"
end
def ronn_files
spec.files.grep /^man\/.*\.ronn$/
end
def man_files
ronn_files.map { |path| path.sub(/\.ronn$/, '') }
end
end
end
end