# # Gem specification # def gemspec @gemspec ||= TOPLEVEL_BINDING.eval(File.read('<%= project_name %>.gemspec')) end desc 'build the gem' task :gem, :dir => 'pkg' do |config| output = `gem build '<%= project_name %>.gemspec'` output =~ /File: (.*)$/ FileUtils.mkdir_p(config.dir) unless File.exists?(config.dir) FileUtils.mv($1, File.join(config.dir, $1), :force => true) end desc 'Prints the gemspec manifest.' task :print_manifest do # collect files from the gemspec, labeling # with true or false corresponding to the # file existing or not files = gemspec.files.inject({}) do |files, file| files[File.expand_path(file)] = [File.exists?(file), file] files end # gather non-rdoc/pkg files for the project # and add to the files list if they are not # included already (marking by the absence # of a label) Dir.glob("**/*").each do |file| next if file =~ /^(rdoc|pkg|test)/ || File.directory?(file) path = File.expand_path(file) files[path] = ["", file] unless files.has_key?(path) end # sort and output the results files.values.sort_by {|exists, file| file }.each do |entry| puts "%-5s %s" % entry end end # # Documentation tasks # desc 'Generate documentation.' task :rdoc, :rebuild => false, :dir => 'rdoc' do |config| require 'rdoc/rdoc' require 'cdoc' if config.rebuild && File.directory?(config.dir) FileUtils.rm_r(config.dir) end files = gemspec.files.select {|file| file =~ /^lib.*\.rb$/ }.uniq files += gemspec.extra_rdoc_files # Using CDoc to template your RDoc will result in configurations being # listed with documentation in a subsection following attributes. Not # necessary, but nice. cdoc_options = ['--fmt', 'cdoc', '--template', 'cdoc/cdoc_html_template'] args = ['-o', config.dir] + cdoc_options + gemspec.rdoc_options + files RDoc::RDoc.new.document(args) end # # Test tasks # desc 'Run the tests' task :test do tests = Dir.glob('test/**/*_test.rb') sh('ruby', '-w', '-e', 'ARGV.dup.each {|test| load test}', *tests) end