Giter Club home page Giter Club logo

rack-tidy's Introduction

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 © 2009 Phil Misiowiec, Webficient LLC. See MIT-LICENSE for details.

rack-tidy's People

Contributors

philm avatar rbialek avatar

Watchers

James Cloos avatar Surender Thillainathan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.