Permalink
Browse files

add doc:server take task - starts a doc development server

The server rebuilds all documentation files before serving
each request using the `rake doc' command. This makes hacking
on doc a little more tolerable.
  • Loading branch information...
1 parent 68459c7 commit 98782da4d461bfcf7e1f3dd2572c0c8497597661 @rtomayko committed Nov 3, 2008
Showing with 40 additions and 0 deletions.
  1. +6 −0 Rakefile
  2. +34 −0 doc/server.ru
View
6 Rakefile
@@ -87,10 +87,16 @@ FileList['doc/*.markdown'].each do |source|
CLEAN.include dest
end
+desc 'Publish documentation'
task 'doc:publish' => :doc do
sh 'rsync -avz doc/ gus@tomayko.com:/src/rack-cache'
end
+desc 'Start the documentation development server (requires thin)'
+task 'doc:server' do
+ sh 'cd doc && thin --rackup server.ru --port 3035 start'
+end
+
# PACKAGING =================================================================
def package(ext='')
View
34 doc/server.ru
@@ -0,0 +1,34 @@
+# Rackup config that serves the contents of Rack::Cache's
+# doc directory. The documentation is rebuilt on each request.
+
+# Rewrites URLs like conventional web server configs.
+class Rewriter < Struct.new(:app)
+ def call(env)
+ if env['PATH_INFO'] =~ /\/$/
+ env['PATH_INFO'] += 'index.html'
+ elsif env['PATH_INFO'] !~ /\.\w+$/
+ env['PATH_INFO'] += '.html'
+ end
+ app.call(env)
+ end
+end
+
+# Rebuilds documentation on each request.
+class DocBuilder < Struct.new(:app)
+ def call(env)
+ if env['PATH_INFO'] !~ /\.(css|js|gif|jpg|png|ico)$/
+ env['rack.errors'] << "*** rebuilding documentation (rake -s doc)\n"
+ system "rake -s doc"
+ end
+ app.call(env)
+ end
+end
+
+use Rack::CommonLogger
+use DocBuilder
+use Rewriter
+use Rack::Static, :root => File.dirname(__FILE__), :urls => ["/"]
+
+run(lambda{|env| [404,{},'<h1>Not Found</h1>']})
+
+# vim: ft=ruby

0 comments on commit 98782da

Please sign in to comment.