Browse files

Re-enable Sinatra integration for local preview

  • Loading branch information...
1 parent df3378f commit b18c934c3064b59371eb288e62f2a408d8ce36f0 @runpaint committed Sep 26, 2010
Showing with 40 additions and 19 deletions.
  1. +10 −17 README.md
  2. +5 −2 Rakefile
  3. +25 −0 bin/browse
View
27 README.md
@@ -13,27 +13,20 @@ Tracker](http://github.com/runpaint/read-ruby/issues).
Contributor's guide
-------------------
-Fork the [GitHub repository](http://github.com/runpaint/read-ruby), make commits and do pull requests.
+Fork the [GitHub repository](http://github.com/runpaint/read-ruby), make
+commits and do pull requests.
To generate the book, you'll need:
* Ruby 1.9, which can be installed via [rvm](http://rvm.beginrescueend.com/).
-* The gems Mustache, Nokogiri, h5-min, & `pngrammar`: `gem install mustache
- nokogiri h5-min pngrammar`.
+* The Nokogiri gem. (Optionally, the `h5-min` and `coderay` gem).
+* For validation: `xmllint`, `onvdl`, `xlstproc`, and `h5-valid`
* `gzip` for compressing HTML/CSS/JS. Installed by default on most systems.
-* `pygments` for highlighting examples. Packaged as `python-pygments` on Debian/Ubuntu. Can also be
- installed with `easy_install Pygments`.
-* `optipng` for compressing railroad diagrams. Packaged as `optipng` on Debian/Ubuntu.
-* `yuicompressor` for minifying CSS and JS. ([YUI
- Compressor](http://yuilibrary.com/downloads/#yuicompressor))
-
-To preview it locally, there are two options:
-
-* Install Apache 2, symlink the config file at out/apache.conf from your Apache 2
- `sites-enabled` directory, assign the hostname `read-ruby` to localhost,
- then view `http://read-ruby/`.
-* Or, install the `sinatra` gem, run `rake browse` to start the bundled web
- server, note the port it’s listening on, then navigate to
- `http://localhost:`<var>port</var>`/`.
+
+To preview it locally:
+
+* Install the `sinatra` gem
+* Run `rake browse` to start the bundled web server
+* Navigate to `http://localhost:4567/`
To upload the site to a remote server you will also need `rsync`.
View
7 Rakefile
@@ -100,6 +100,9 @@ task :push do
sh 'git push github'
end
-task :default => [:html, :highlight, :minify, :validate]
+desc 'View locally with a web browser'
+task :browse do
+ sh "./bin/browse #{OUT_DIR}"
+end
-# TODO: Add Sinatra integration back in
+task :default => [:html, :highlight, :minify, :validate]
View
25 bin/browse
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+require 'rubygems'
+require 'sinatra'
+require 'pathname'
+
+raise "Usage: #$0 <dir>" unless ARGV.size == 1
+OUT_DIR = Pathname(ARGV.first)
+
+enable :run
+set :public, OUT_DIR
+
+helpers do
+ def show name
+ glob = OUT_DIR.join(name).to_s + ?*
+ send_file Dir[glob].sort_by(&:size).first || halt(404)
+ end
+end
+
+get '/' do
+ show 'index'
+end
+
+get '/*' do
+ show params[:splat].join(?/)
+end

0 comments on commit b18c934

Please sign in to comment.