webficient / rack-coderay

CodeRay Syntax Highlighter for Rack

This URL has Read+Write access

name age message
file .document Thu Aug 20 17:54:09 -0700 2009 Initial commit to rack-coderay. [philm]
file .gitignore Thu Aug 20 17:54:09 -0700 2009 Initial commit to rack-coderay. [philm]
file MIT-LICENSE Fri Aug 28 00:55:51 -0700 2009 more documentation, license info [philm]
file README.rdoc Fri Aug 28 00:55:51 -0700 2009 more documentation, license info [philm]
file Rakefile Thu Sep 03 21:25:28 -0700 2009 Removed rubygems and gem references per recomme... [philm]
file VERSION Thu Sep 03 21:26:04 -0700 2009 Version bump to 0.2.0 [philm]
directory lib/ Fri Aug 28 00:55:51 -0700 2009 more documentation, license info [philm]
file rack-coderay.gemspec Thu Sep 03 21:27:20 -0700 2009 updated gemspec [philm]
directory resources/ Fri Aug 28 00:55:10 -0700 2009 added copy of coderay.css [philm]
directory test/ Thu Sep 03 21:25:28 -0700 2009 Removed rubygems and gem references per recomme... [philm]
README.rdoc

CodeRay Syntax Highlighter for Rack

Rack::Coderay parses text/html markup and replaces code with output from the CodeRay gem (coderay.rubychan.de/), producing syntax highlighting. By default, this component looks for <pre lang="xxxx">…</pre> blocks, where ‘xxxx’ is any of the languages supported by CodeRay (e.g. ‘ruby’). See coderay.rubychan.de/doc/classes/CodeRay/Scanners.html

For more information about the Rack specification, check out rack.rubyforge.org

Installation

Prerequisites:

  -Rack gem (sudo gem install rack)
  -CodeRay gem (sudo gem install coderay)

From Gem:

  $ sudo gem install webficient-rack-coderay

With a local working copy:

  $ git clone git://github.com/webficient/rack-coderay.git
  $ rake build && sudo rake install

Usage

Basic Usage


Rack::Coderay is implemented as a piece of Rack middleware and can be used with any Rack-based application. If your application includes a rackup (`.ru`) file or uses Rack::Builder to construct the application pipeline, simply require and use as follows:

  require 'rack/coderay'

  use Rack::Coderay
  run app

Using with Rails


Add this to your `config/environment.rb`:

  # above Rails::Initializer block
  require 'rack/coderay'

  # inside Rails::Initializer block
  config.middleware.use Rack::Coderay

You should now see `Rack::Coderay` listed in the middleware pipeline:

  rake middleware

Configuration Options


To override the default markup trigger (<pre lang="xxxx">), you can pass in a css or xpath selector as the second argument:

  # Rails example
  config.middleware.use Rack::Coderay, "//div[@lang]"

To set additional CodeRay gem options, pass a hash as the third argument:

  # Rails example
  config.middleware.use Rack::Coderay,
    "//pre[@lang]",
    :line_numbers => :table

Stylesheet


You can grab the latest CSS from the CodeRay site at coderay.rubychan.de/stylesheets/coderay.css.

A copy has been embedded in the Rack::Coderay gem under the /resources directory for your convenience.

Copyright

Copyright © 2009 Phil Misiowiec, Webficient LLC. See MIT-LICENSE for details.