Rakefile 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. require 'rake/clean'
  2. task :default => [:setup, :test]
  3. CLEAN.include %w[coverage/ doc/api tags]
  4. CLOBBER.include %w[dist]
  5. desc "Install gem dependencies"
  6. task :setup do
  7. sh "bundle check >/dev/null || bundle install", :verbose => false
  8. end
  9. # SPECS =====================================================================
  10. desc 'Run specs with unit test style output'
  11. task :test => FileList['test/*_test.rb'] do |t|
  12. suite = t.prerequisites
  13. sh "bundle exec bacon -q -I.:lib:test #{suite.join(' ')}", :verbose => false
  14. end
  15. desc 'Run specs with story style output'
  16. task :spec => FileList['test/*_test.rb'] do |t|
  17. suite = t.prerequisites
  18. sh "bundle exec bacon -I.:lib:test #{suite.join(' ')}", :verbose => false
  19. end
  20. desc 'Generate test coverage report'
  21. task :rcov do
  22. sh "rcov -I.:lib:test test/*_test.rb"
  23. end
  24. # DOC =======================================================================
  25. desc 'Build all documentation'
  26. task :doc => %w[doc:api doc:markdown]
  27. # requires the hanna gem:
  28. # gem install mislav-hanna --source=http://gems.github.com
  29. desc 'Build API documentation (doc/api)'
  30. task 'doc:api' => 'doc/api/index.html'
  31. file 'doc/api/index.html' => FileList['lib/**/*.rb'] do |f|
  32. rm_rf 'doc/api'
  33. sh((<<-SH).gsub(/[\s\n]+/, ' ').strip)
  34. hanna
  35. --op doc/api
  36. --promiscuous
  37. --charset utf8
  38. --fmt html
  39. --inline-source
  40. --line-numbers
  41. --accessor option_accessor=RW
  42. --main Rack::Cache
  43. --title 'Rack::Cache API Documentation'
  44. #{f.prerequisites.join(' ')}
  45. SH
  46. end
  47. CLEAN.include 'doc/api'
  48. desc 'Build markdown documentation files'
  49. task 'doc:markdown'
  50. FileList['doc/*.markdown'].each do |source|
  51. dest = "doc/#{File.basename(source, '.markdown')}.html"
  52. file dest => [source, 'doc/layout.html.erb'] do |f|
  53. puts "markdown: #{source} -> #{dest}" if verbose
  54. require 'erb' unless defined? ERB
  55. require 'rdiscount' unless defined? RDiscount
  56. template = File.read(source)
  57. content = Markdown.new(ERB.new(template, 0, "%<>").result(binding), :smart).to_html
  58. title = content.match("<h1>(.*)</h1>")[1] rescue ''
  59. layout = ERB.new(File.read("doc/layout.html.erb"), 0, "%<>")
  60. output = layout.result(binding)
  61. File.open(dest, 'w') { |io| io.write(output) }
  62. end
  63. task 'doc:markdown' => dest
  64. CLEAN.include dest
  65. end
  66. desc 'Publish documentation'
  67. task 'doc:publish' => :doc do
  68. sh 'rsync -avz doc/ gus@tomayko.com:/src/rack-cache'
  69. end
  70. desc 'Start the documentation development server (requires thin)'
  71. task 'doc:server' do
  72. sh 'cd doc && thin --rackup server.ru --port 3035 start'
  73. end
  74. # PACKAGING =================================================================
  75. if defined?(Gem)
  76. # load gemspec
  77. $spec = eval(File.read('rack-cache.gemspec'))
  78. def package(ext='')
  79. "dist/rack-cache-#{$spec.version}" + ext
  80. end
  81. desc 'Build packages'
  82. task :package => %w[.gem .tar.gz].map {|e| package(e)}
  83. desc 'Build and install as local gem'
  84. task :install => package('.gem') do
  85. sh "gem install #{package('.gem')}"
  86. end
  87. directory 'dist/'
  88. file package('.gem') => %w[dist/ rack-cache.gemspec] + $spec.files do |f|
  89. sh "gem build rack-cache.gemspec"
  90. mv File.basename(f.name), f.name
  91. end
  92. file package('.tar.gz') => %w[dist/] + $spec.files do |f|
  93. sh "git archive --format=tar HEAD | gzip > #{f.name}"
  94. end
  95. desc 'Upload gem to gemcutter.org'
  96. task 'release' => [package('.gem')] do |t|
  97. sh "gem push #{package('.gem')}"
  98. end
  99. end
  100. # GEMSPEC ===================================================================
  101. file 'rack-cache.gemspec' => FileList['{lib,test}/**','Rakefile'] do |f|
  102. # read spec file and split out manifest section
  103. spec = File.read(f.name)
  104. parts = spec.split(" # = MANIFEST =\n")
  105. fail 'bad spec' if parts.length != 3
  106. # determine file list from git ls-files
  107. files = `git ls-files`.
  108. split("\n").sort.reject{ |file| file =~ /^\./ }.
  109. map{ |file| " #{file}" }.join("\n")
  110. # piece file back together and write...
  111. parts[1] = " s.files = %w[\n#{files}\n ]\n"
  112. spec = parts.join(" # = MANIFEST =\n")
  113. spec.sub!(/s.date = '.*'/, "s.date = '#{Time.now.strftime("%Y-%m-%d")}'")
  114. File.open(f.name, 'w') { |io| io.write(spec) }
  115. puts "updated #{f.name}"
  116. end