-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
81 lines (65 loc) · 2.43 KB
/
Rakefile
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
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"
load "big_band.gemspec"
task :default => :spec
task :test => :spec
task :clobber => "doc:clobber_rdoc"
CLOBBER << "README.rdoc"
TOOLS = { :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 }
end
children.compact
end
def generate_readme(target = "README.rdoc", template = "README.rdoc.erb")
# 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", TOOLS) { |n| n != :Test }
version = SPEC.version.to_s
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[--all --inline-source --line-numbers --main README.rdoc --quiet
--tab-width 2 --title BigBand --charset 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]
end
end
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_opts = %w[--options spec/spec.opts]
t.spec_files = Dir.glob 'spec/**/*_spec.rb'
end