public
Description: Rack middleware for automatically cleaning markup using Tidy
Homepage:
Clone URL: git://github.com/webficient/rack-tidy.git
name age message
file .document Mon Aug 17 23:18:59 -0700 2009 Initial commit to rack-tidy. [philm]
file .gitignore Mon Aug 17 23:18:59 -0700 2009 Initial commit to rack-tidy. [philm]
file MIT-LICENSE Wed Aug 19 21:19:57 -0700 2009 baseline version [philm]
file README.rdoc Fri Aug 28 00:49:49 -0700 2009 minor edit [philm]
file Rakefile Thu Sep 03 21:16:04 -0700 2009 Removed rubygems and gem references per recomme... [philm]
file VERSION Thu Sep 03 21:16:32 -0700 2009 Version bump to 0.2.0 [philm]
directory lib/ Thu Aug 20 12:19:22 -0700 2009 fixed an issue related to ignored paths [philm]
file rack-tidy.gemspec Thu Sep 03 21:18:30 -0700 2009 updated gemspec [philm]
directory test/ Thu Sep 03 21:16:04 -0700 2009 Removed rubygems and gem references per recomme... [philm]
README.rdoc

Tidy Markup Cleaner for Rack

Rack::Tidy cleans text/html markup by automatically indenting and reformatting content. Best results are achieved with valid markup, when you simply want to use this component to produce clean (X)HTML rendered by templating systems such as ERb.

Rack::Tidy relies on the power of the Tidy gem and defaults to settings based on convention. However, you can override these through configuration.

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

Installation

Prerequisites:

  -Rack gem (sudo gem install rack)
  -Tidy gem (sudo gem install tidy)

From Gem:

  $ sudo gem install webficient-rack-tidy

With a local working copy:

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

Usage

Basic Usage


Rack::Tidy 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/tidy'

  use Rack::Tidy
  run app

Using with Rails


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

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

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

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

  rake middleware

Configuration Options


The Tidy gem requires setting an internal path variable that points to the Tidy library, which will differ per platform. Rack::Tidy defaults to ’/usr/lib/libtidy.A.dylib’ which is the default location for the Tidy gem on Mac Leopard. To override the constant, simply define it in your application’s configuration file:

  TIDY_LIB = '/usr/lib/tidylib.so'

Need Rack::Tidy to ignore certain paths? In your config, pass in an optional array of paths:

  # Rails example
  config.middleware.use Rack::Tidy,
    :ignore_paths => ['/admin', '/cms']

Rack::Tidy relies on convention with regard to Tidy’s configuration (see Rack::Tidy::Cleaner for details). If you want to override/set attributes supported by the Tidy gem, declare them in your configuration as an optional hash:

  # Rails example
  config.middleware.use Rack::Tidy,
    'indent-spaces' => 4

See tidy.sourceforge.net/docs/quickref.html for Tidy gem config options

Copyright

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