require 'rake' # build man pages before building ruby gem using bundler if defined? Bundler::GemHelper %w[build install release].each {|t| task t => :md2man } end #----------------------------------------------------------------------------- desc 'Build manual pages from Markdown files in man/.' task :md2man => ['md2man:man', 'md2man:web'] #----------------------------------------------------------------------------- mkds = FileList['man/**/*.{markdown,mkd,md}'] mans = mkds.pathmap('%X') webs = mans.pathmap('%p.html') render_file_task = lambda do |src, dst, renderer| directory dir = dst.pathmap('%d') file dst => [dir, src] do input = File.read(src) output = renderer.call(input) File.open(dst, 'w') {|f| f << output } end end #----------------------------------------------------------------------------- desc 'Build UNIX manual pages from Markdown files in man/.' task 'md2man:man' => mans #----------------------------------------------------------------------------- mkds.zip(mans).each do |src, dst| render_file_task.call src, dst, lambda {|input| require 'md2man/engine' Md2Man::ENGINE.render(input) } end #----------------------------------------------------------------------------- desc 'Build HTML manual pages from Markdown files in man/.' task 'md2man:web' => 'man/index.html' #----------------------------------------------------------------------------- file 'man/index.html' => webs do |t| output = [] dirs = webs.group_by {|web| web.pathmap('%d') }.each do |dir, dir_webs| subdir = dir.pathmap('%f') output << %{