require 'binman'
require 'rake'

# build man pages before building ruby gem using bundler
if defined? Bundler::GemHelper
  %w[build install release].each {|t| task t => :binman }
end

#-----------------------------------------------------------------------------
desc 'Build manual pages for bin/ scripts.'
task :binman => ['binman:man', 'binman:web']
#-----------------------------------------------------------------------------

directory dir = 'man/man1'
bins = FileList['bin/*']
mkds = bins.pathmap("#{dir}/%n.1.markdown")

bins.zip(mkds).each do |src, dst|
  file dst => [dir, src] do
    output = BinMan.snip(src)
    File.open(dst, 'w') {|f| f << output }
  end
end

#-----------------------------------------------------------------------------
desc 'Build UNIX manual pages for bin/ scripts.'
task 'binman:man' => mkds do
#-----------------------------------------------------------------------------
  load 'md2man/rakefile.rb'
  Rake::Task['md2man:man'].invoke
end

#-----------------------------------------------------------------------------
desc 'Build HTML manual pages for bin/ scripts.'
task 'binman:web' => mkds do
#-----------------------------------------------------------------------------
  load 'md2man/rakefile.rb'
  Rake::Task['md2man:web'].invoke
end

require 'binman'
require 'rake'

# build man pages before building ruby gem using bundler
if defined? Bundler::GemHelper
  %w[build install release].each {|t| task t => :binman }
end

#-----------------------------------------------------------------------------
desc 'Build manual pages for bin/ scripts.'
task :binman => ['binman:man', 'binman:web']
#-----------------------------------------------------------------------------

directory dir = 'man/man1'
bins = FileList['bin/*']
mkds = bins.pathmap("#{dir}/%n.1.markdown")

bins.zip(mkds).each do |src, dst|
  file dst => [dir, src] do
    output = BinMan.snip(src)
    File.open(dst, 'w') {|f| f << output }
  end
end

#-----------------------------------------------------------------------------
desc 'Build UNIX manual pages for bin/ scripts.'
task 'binman:man' => mkds do
#-----------------------------------------------------------------------------
  require 'md2man/rakefile'
  Rake::Task['md2man:man'].invoke
end

#-----------------------------------------------------------------------------
desc 'Build HTML manual pages for bin/ scripts.'
task 'binman:web' => mkds do
#-----------------------------------------------------------------------------
  require 'md2man/rakefile'
  Rake::Task['md2man:web'].invoke
end

Revert "ensure 'binman:web' task works the first time thru"
Revert "ensure 'binman:web' task works the first time thru"

This reverts commit dd0511e78e02546cac4903b5c6de6243607a8bba,
which was causing the following error under Ruby 2.3.0p0.

  % rake build
  mkdir -p man/man1
  rake aborted!
  LoadError: cannot load such file -- md2man/rakefile.rb
  ./lib/binman/rakefile.rb:29:in `load'
  ./lib/binman/rakefile.rb:29:in `block in <top (required)>'
  Tasks: TOP => build => binman => binman:man
  (See full trace by running task with --trace)
  exit 1
