Rakefile in sinatra-0.3.1 vs Rakefile in sinatra-0.3.2

- old
+ new

@@ -1,6 +1,8 @@ +require 'rubygems' require 'rake/clean' +require 'fileutils' task :default => :test # SPECS =============================================================== @@ -52,11 +54,11 @@ sh "git archive --format=tar HEAD | gzip > #{f.name}" end # Rubyforge Release / Publish Tasks ================================== -desc 'Publish API docs to rubyforge' +desc 'Publish website to rubyforge' task 'publish:doc' => 'doc/api/index.html' do sh 'scp -rp doc/* rubyforge.org:/var/www/gforge-projects/sinatra/' end task 'publish:gem' => [package('.gem'), package('.tar.gz')] do |t| @@ -64,10 +66,81 @@ rubyforge add_release sinatra sinatra #{spec.version} #{package('.gem')} && rubyforge add_file sinatra sinatra #{spec.version} #{package('.tar.gz')} end end +# Website ============================================================ +# Building docs requires HAML and the hanna gem: +# gem install mislav-hanna --source=http://gems.github.com + +task 'doc' => ['doc:api','doc:site'] + +desc 'Generate Hanna RDoc under doc/api' +task 'doc:api' => ['doc/api/index.html'] + +file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f| + rb_files = f.prerequisites + sh((<<-end).gsub(/\s+/, ' ')) + hanna --charset utf8 \ + --fmt html \ + --inline-source \ + --line-numbers \ + --main README.rdoc \ + --op doc/api \ + --title 'Sinatra API Documentation' \ + #{rb_files.join(' ')} + end +end +CLEAN.include 'doc/api' + +def rdoc_to_html(file_name) + require 'rdoc/markup/to_html' + rdoc = RDoc::Markup::ToHtml.new + rdoc.convert(File.read(file_name)) +end + +def haml(locals={}) + require 'haml' + template = File.read('doc/template.haml') + haml = Haml::Engine.new(template, :format => :html4, :attr_wrapper => '"') + haml.render(Object.new, locals) +end + +desc 'Build website HTML and stuff' +task 'doc:site' => ['doc/index.html', 'doc/book.html'] + +file 'doc/index.html' => %w[README.rdoc doc/template.haml] do |file| + File.open(file.name, 'w') do |file| + file << haml(:title => 'Sinatra', :content => rdoc_to_html('README.rdoc')) + end +end +CLEAN.include 'doc/index.html' + +file 'doc/book.html' => ['book/output/sinatra-book.html'] do |file| + File.open(file.name, 'w') do |file| + book_content = File.read('book/output/sinatra-book.html') + file << haml(:title => 'Sinatra Book', :content => book_content) + end +end +CLEAN.include 'doc/book.html' + +file 'book/output/sinatra-book.html' => FileList['book/**'] do |f| + unless File.directory?('book') + sh 'git clone git://github.com/cschneid/sinatra-book.git book' + end + sh((<<-SH).strip.gsub(/\s+/, ' ')) + cd book && + git fetch origin && + git rebase origin/master && + thor book:build + SH +end +CLEAN.include 'book/output/sinatra-book.html' + +desc 'Build the Sinatra book' +task 'doc:book' => ['book/output/sinatra-book.html'] + # Gemspec Helpers ==================================================== file 'sinatra.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f| # read spec file and split out manifest section spec = File.read(f.name) @@ -76,36 +149,14 @@ # determine file list from git ls-files files = `git ls-files`. split("\n"). sort. reject{ |file| file =~ /^\./ }. + reject { |file| file =~ /^doc/ }. map{ |file| " #{file}" }. join("\n") # piece file back together and write... parts[1] = " s.files = %w[\n#{files}\n ]\n" spec = parts.join(" # = MANIFEST =\n") File.open(f.name, 'w') { |io| io.write(spec) } puts "updated #{f.name}" end - -# Hanna RDoc ========================================================= -# -# Building docs requires the hanna gem: -# gem install mislav-hanna --source=http://gems.github.com - -desc 'Generate Hanna RDoc under doc/api' -task :doc => ['doc/api/index.html'] - -file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f| - rb_files = f.prerequisites - sh((<<-end).gsub(/\s+/, ' ')) - hanna --charset utf8 \ - --fmt html \ - --inline-source \ - --line-numbers \ - --main README.rdoc \ - --op doc/api \ - --title 'Sinatra API Documentation' \ - #{rb_files.join(' ')} - end -end -CLEAN.include 'doc/api'