DannyBen/madman

View on GitHub
Runfile

Summary

Maintainability
Test Coverage
require "debug"
require "lp"
require 'madman/version'

title   "Madman Developer Toolbelt"
summary "Runfile tasks for building the Madman gem"
version Madman::VERSION

import_gem 'runfile-tasks/gem', gemname: 'madman'

help   "Inject usage to README"
action :usage do
  doc = Madman::Document.from_file 'README.md'

  usage_commands.each do |marker, command|
    doc.inject command_output(command), marker: marker
  end

  doc.save
end

help   "Count lines of code"
action :cloc do
  system "cloc . --exclude-dir coverage,spec,templates,tmp,dev --exclude-ext yml"
end

helpers do
  def usage_commands
    {
      'usage'        => 'madman',
      'render'       => 'madman render',
      'render-help'  => 'madman render --help',
      'preview'      => 'madman preview',
      'preview-help' => 'madman preview --help',
      'serve'        => 'madman serve',
      'serve-help'   => 'madman serve --help',
      'nav'          => 'madman nav',
      'nav-help'     => 'madman nav --help',
      'readme'       => 'madman readme',
      'readme-help'  => 'madman readme --help',
    }
  end

  def command_output(command)
    say "Executing g`#{command}`"
    "\n```\n" + "$ #{command}\n" + `#{command}`.chomp + "\n```\n"
  end
end