Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v0.2.1
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 128 lines (103 sloc) 3.415 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
require "erb"
require "spec/rake/spectask"
require "rake/clean"
require "rake/rdoctask"
require "monkey-lib"
require "yard"

$LOAD_PATH.unshift __FILE__.dirname.expand_path / "lib"
require "big_band/integration/yard"
require "big_band/integration/rake"
require "big_band/version"

include BigBand::Integration::Rake
RoutesTask.new

task :default => "gems:build"
task :test => :spec
task :clobber => "doc:clobber_rdoc"

CLEAN.include "**/*.rbc"
CLOBBER.include "*.gem", "README.rdoc"

Spec::Rake::SpecTask.new('spec') do |t|
  t.spec_opts = %w[--options spec/spec.opts]
  t.spec_files = Dir.glob 'spec/**/*_spec.rb'
end

TOOL_NAMES = { :Rspec => :RSpec, :Yard => :YARD, :TestSpec => :"Test::Spec", :TestUnit => :"Test::Unit" }

def yard(files)
  YARD::Registry.load(Dir[files], true)
  YARD::Registry.resolve(false, "BigBand")
end

def yard_children(ydoc, directory, defaults = {}, &block)
  children = Dir.glob("#{directory}/*.rb").map { |f| f[(directory.size+1)..-4].to_const_string.to_sym }
  children.select!(&block) if block
  children.map! do |name|
    rewritten_name = defaults[name] || name
    ydoc.child(rewritten_name) or ydoc.child(name).tap { |c| c.name = rewritten_name unless c.nil? }
  end
  children.compact
end

def generate_readme(target = "README.rdoc", template = "README.rdoc.erb")
  puts "generating #{target} from #{template}"
  # HACK: loading other libraries later, for some strange heisenbug setting the docstring to an empty string later.
  docstring = yard("lib/big_band.rb").docstring
  ydoc = yard("lib/big_band/{**/,}*.rb")
  extensions = yard_children(ydoc, "lib/big_band") { |n| n != :Integration }
  integration = yard_children(ydoc.child(:Integration), "lib/big_band/integration", TOOL_NAMES) { |n| n != :Test }
  version = BigBand::VERSION
  File.open(target, "w") { |f| f << ERB.new(File.read(template), nil, "<>").result(binding) }
end

file "README.rdoc" => ["README.rdoc.erb", "lib/big_band.rb"] do
  generate_readme
end

desc "Generate documentation"
task "doc" => "doc:yardoc"
task "yardoc" => "doc:yardoc"
task "rdoc" => "doc:yardoc"

namespace :doc do

  task "yardoc" => "readme"
  task "rdoc" => "readme"
  task "rerdoc" => "readme"

  desc "Generate README.rdoc from source files"
  task "readme" do |t|
    generate_readme
  end

  Rake::RDocTask.new("rdoc") do |rdoc|
    rdoc.rdoc_dir = 'doc'
    rdoc.options += %w[-a -S -N -m README.rdoc -q -w 2 -t BigBand -c UTF-8]
    rdoc.rdoc_files.add ['*.{rdoc,rb}', '{config,lib,routes}/**/*.rb']
  end

  YARD::Rake::YardocTask.new("yardoc") do |t|
    t.options = %w[--main README.rdoc --backtrace]
  end

end

task :gems => "gems:build"

namespace :gems do

  desc "Build gems (runs specs first)"
  task :build => [:clobber, :spec, "doc:readme"] do
    GEMS = []
    Dir.glob("*.gemspec") do |file|
      sh "gem build #{file}"
      GEMS << "#{file[0..-9]}-#{BigBand::VERSION}.gem"
    end
  end

  desc "Install gems"
  task :install => :build do
    GEMS.each { |file| sh "gem install #{file}" }
  end

  desc "Publish gems (gemcutter)"
  task :push => :build do
    GEMS.each { |file| sh "gem push #{file}" }
  end

end

############
# aliases

task :c => [:clobber, "doc:readme"]
task :s => :spec
task :d
namespace :d do
  task :r => "doc:readme"
  task :y => "doc:yardoc"
end
task :g => :gems
namespace :g do
  task :b => "gems:build"
  task :i => "gems:install"
  task :p => "gems:push"
end
Something went wrong with that request. Please try again.