Permalink
Browse files

Thor is a sucky build tool; use Rake instead

That's not to say it's sucky in general but a build tool
needs to have file tasks and dependencies. Calling ruby
methods != depedencies. See make(1) for more info ...
  • Loading branch information...
1 parent 2fae1ad commit 9c2751372082ce30053ebeb523e2552f5bba10a8 @rtomayko rtomayko committed Jan 29, 2009
Showing with 176 additions and 136 deletions.
  1. +63 −0 README
  2. +0 −47 README.md
  3. +113 −0 Rakefile
  4. +0 −89 Thorfile
View
63 README
@@ -0,0 +1,63 @@
+Sinatra Website / Documentation
+===============================
+
+This repo contains the Sinatra website and documentation sources published
+at http://sinatra.github.com/.
+
+Working Locally
+---------------
+
+Grab the sources from github:
+
+ $ git clone git@github.com:sinatra/sinatra.github.com.git
+ $ cd sinatra.github.com
+
+Install Jekyll (with dependencies):
+
+ $ gem install jekyll
+
+Run the test server:
+
+ $ rake server
+
+Changes are immediately available at:
+
+ http://localhost:4000/
+
+Once your changes are complete, commit them and push back to the
+repository to publish:
+
+ $ git commit -m 'note that rtomayko is an asshole'
+ $ git push
+
+Creating Blog Posts
+-------------------
+
+Blog posts are stored under the `_posts` directory. To create a new blog post
+and open your `$EDITOR`, use:
+
+ thor blog:new 'Blog Post Title'
+
+This requires Thor:
+
+ $ gem install thor
+
+Prebuilt Files
+--------------
+
+You will need thor, rdoc, and mislav's hanna gem to rebuild static files
+and the API docs:
+
+ $ gem install thor rdoc
+ $ gem install mislav-hanna --source=http://gems.github.com/
+
+The prebuilt file sources are maintained under the sinatra and sinatra-book
+projects. To pull in the latest versions and build them:
+
+ rake pull build
+
+The generated files under the "_includes" and "api" directories need to be
+committed after building. To regenerate and add those files to your index
+for the next commit:
+
+ rake regen
View
@@ -1,47 +0,0 @@
-Sinatra Website / Documentation
-===============================
-
-This repo contains the Sinatra website and documentation sources published
-at http://sinatra.github.com/.
-
-Working Locally
----------------
-
-Create a local clone:
-
- $ git clone git@github.com:sinatra/sinatra.github.com.git
- $ cd sinatra.github.com
-
-Install Jekyll (with dependencies):
-
- $ sudo gem install jekyll
-
-Run the test server:
-
- $ jekyll --server --auto
-
-Changes are immediately available at:
-
- http://localhost:4000/
-
-Once you're changes are complete, commit them and push back to the
-repository to publish:
-
- $ git commit -m 'note that rtomayko is an asshole'
- $ git push
-
-Rebuilding Generated Files
---------------------------
-
-The project index.html and book.html files are maintained under
-separate projects. To sync those files with their current upstream:
-
- thor legend:build
-
-Creating Blog Posts
--------------------
-
-Blog posts are stored under the `_posts` directory. To create a new blog post
-and open your `$EDITOR`, use:
-
- thor blog:new 'Blog Post Title'
View
113 Rakefile
@@ -0,0 +1,113 @@
+require 'rake/clean'
+require 'rdoc/markup/to_html'
+
+task :default => ['_sinatra', '_book', :build]
+
+desc "Build outdated static files and API docs"
+task :build => ['build:static', 'build:api']
+
+desc "Build outdated static files"
+task 'build:static' => [
+ '_includes/README.html',
+ '_includes/CHANGES.txt',
+ '_includes/book.html'
+]
+
+desc "Build outdated the API docs"
+task 'build:api' => ['api/index.html']
+
+desc "Build anything that's outdated and stage changes for next commit"
+task :regen => [:build] do
+ sh 'git add api _includes'
+ puts "\nPrebuilt files regenerated and staged in your index. Commit with:"
+ puts " git commit -m 'Regen prebuilt files'"
+end
+
+desc 'Pull in the latest from the sinatra and sinatra-book repos'
+task :pull => ['pull:sinatra', 'pull:book']
+
+desc 'Pull in the latest from the sinatra repo'
+task 'pull:sinatra' do
+ if File.directory?("_sinatra")
+ puts 'Pulling sinatra.git'
+ sh "cd _sinatra && git pull &>/dev/null"
+ touch '_sinatra', :verbose => false
+ else
+ puts 'Cloning sinatra repo'
+ sh "git clone git://github.com/sinatra/sinatra.git _sinatra"
+ end
+end
+file('_sinatra') { Rake::Task['pull:sinatra'].invoke }
+CLOBBER.include '_sinatra'
+
+desc 'Pull in the latest from the book repo'
+task 'pull:book' do
+ if File.directory?("_book")
+ puts 'Pulling sinatra-book.git'
+ sh "cd _book && git pull &>/dev/null"
+ touch '_book', :verbose => false
+ else
+ puts 'Cloning sinatra-book repo'
+ sh "git clone git://github.com/sinatra/sinatra-book.git _book"
+ end
+ sh "cd _book && git pull &>/dev/null && thor book:build"
+end
+file('_book') { Rake::Task['pull:book'].invoke }
+CLOBBER.include '_book'
+
+%w[README.rdoc CHANGES AUTHORS].each do |fn|
+ file "_sinatra/#{fn}" => ['_sinatra']
+end
+
+# Build _includes/README.html from RDoc
+file '_includes/README.html' => ['_sinatra/README.rdoc', 'Rakefile'] do |f|
+ html = RDoc::Markup::ToHtml.new.convert(File.read("_sinatra/README.rdoc")).
+ sub("<h1>Sinatra</h1>", "")
+ File.open(f.name, 'wb') { |io| io.write(html) }
+end
+CLEAN.include '_includes/README.html'
+
+# Build _includes/CHANGES.txt from CHANGES file
+file '_includes/CHANGES.txt' => ['_sinatra/CHANGES', 'Rakefile'] do |f|
+ puts "Building _includes/CHANGES.txt"
+ cp '_sinatra/CHANGES', '_includes/CHANGES.txt'
+end
+CLEAN.include '_includes/CHANGES.txt'
+
+# Build _includes/book.html from the book project
+file '_includes/book.html' => (['_book', 'Rakefile'] + FileList['_book/**']) do |f|
+ puts "Building _includes/book.html"
+ sh "cd _book && thor book:build"
+ html = File.read("_book/output/sinatra-book.html")[/<body>(.*?)<\/body>/m, 1].
+ sub(/.*Table of Contents<\/h1>/, "")
+ File.open(f.name, 'wb') { |io| io.write(html) }
+end
+CLEAN.include '_includes/book.html'
+
+# Build the API docs
+file 'api/index.html' => FileList['_sinatra', '_sinatra/**', 'Rakefile'] do |f|
+ puts 'Building API docs'
+ rm_rf 'api'
+ Dir.chdir "_sinatra" do
+ sh <<-SH
+ hanna --charset utf8 --fmt html --inline-source --line-numbers \
+ --main README.rdoc --op ../api --title 'Sinatra API Documentation' \
+ lib/**/*.rb README.rdoc CHANGES AUTHORS
+ SH
+ end
+end
+CLEAN.include 'api'
+
+desc 'Rebuild site under _site with Jekyll'
+task :jekyll do
+ rm_rf '_site'
+ sh 'jekyll --pygments'
+end
+
+desc 'Start the Jekyll server on http://localhost:4000/'
+task :server do
+ rm_rf '_site'
+ puts 'jekyll --pygments --auto --server'
+ exec 'jekyll --pygments --auto --server'
+end
+CLEAN.include '_site'
View
@@ -1,91 +1,5 @@
-require "rubygems"
-require "haml"
-require "rdoc/markup/to_html"
require "fileutils"
-class Legend < Thor
- include FileUtils
-
- desc "build", "Update static files and API docs"
- def build
- static
- api
- end
-
- desc "static", "Update static files"
- def static
- copy_static
- build_readme
- build_book
- end
-
- desc "api", "Build Sinatra API docs"
- def api
- build_api
- end
-
- private
- def build_readme
- puts "building _includes/README.html"
- write_file "_includes/README.html", nil, readme
- end
-
- def build_book
- puts "building book.html"
- write_file "book.html", "Sinatra: The Book", book
- end
-
- def copy_static
- fetch_sinatra
- puts "building _includes/CHANGES.txt"
- cp '_sinatra/CHANGES', '_includes/CHANGES.txt', :preserve => true
- end
-
- def readme
- fetch_sinatra
-
- RDoc::Markup::ToHtml.new.convert(File.read("_sinatra/README.rdoc")).
- sub("<h1>Sinatra</h1>", "")
- end
-
- def book
- system "git clone git://github.com/sinatra/sinatra-book.git _book" unless File.directory?("_book")
- system "cd _book && git pull &>/dev/null && thor book:build"
-
- content = File.read("_book/output/sinatra-book.html")[/<body>(.*?)<\/body>/m, 1]
- content.gsub(/Table of Contents<\/h1>/, "The Book</h1>")
- end
-
- def build_api
- fetch_sinatra
-
- Dir.chdir "_sinatra" do
- system(<<-EOF)
- hanna --charset utf8 \
- --fmt html \
- --inline-source \
- --line-numbers \
- --main README.rdoc \
- --op ../api \
- --title 'Sinatra API Documentation' \
- lib/**/*.rb README.rdoc
- EOF
- end
- end
-
- def fetch_sinatra
- system "git clone git://github.com/sinatra/sinatra.git _sinatra" unless File.directory?("_sinatra")
- system "cd _sinatra && git pull &>/dev/null"
- end
-
- def write_file(file_name, title, content)
- File.open(file_name, "w") do |f|
- f.write "---\ntitle: \"#{title}\"\nlayout: default\n---\n" unless title.nil?
- f << content
- end
- end
-end
-
class Blog < Thor
TEMPLATE = (<<-TEXT).gsub(/^ +/, '')
---
@@ -109,9 +23,6 @@ class Blog < Thor
File.open(file, 'wb') { |f| f.write(post) }
system "$EDITOR #{file}"
end
-
end
-
-
# vim: ft=ruby

0 comments on commit 9c27513

Please sign in to comment.