README

Path: README
Last Update: Thu Apr 27 15:51:17 +0200 2006

RailsTidy

This plugin allows html validation of templates and the response body of functional tests.

1. Requirements

WARNING: there is a bug in tidy for ruby.

The line separator is hard-encoded instead of using the $/ magic variable, so it breaks on unix platforms. Apply the tidy.patch patch file to your tidy installation to work arround the bug.

To apply the patch, go into your tidy for ruby installation directory (mine is /usr/lib/ruby/gems/1.8/gems/tidy-1.1.2) and run

  $ patch -p 2   < /path/to/tidy.patch

You maybe need to su as root for the patch to apply.

2. Installation

Unpack into the vendor/plugin and that should be it. Ruby bindings for libtidy need to know the path to the file dynamic library file for tidy. It is assumed to be found at /usr/lib/libtidy.so for Linux, /usr/lib/libtidy.dylib for Darwin and /usr/bin/cygtidy-0-99-0.dll for cygwin. If this is not the case add

  RailsTidy.tidy_path = "/path/to/your/libtidy.so"

to your environment file.

3. Configuration

If the file config/tidy.rc exists, it will use it to configure Tidy. If you want to use another file, put

RailsTidy.tidy_configuration = "/path/to/a/tidy/configuration/file"

to your environment file. See tidy.sourceforge.net/docs/quickref.html for tidy available configuration options.

4. Usage

4.1 Validating templates

Simply use

  $ rake test:templates

By default, the plugin will parse all *.rhtml files in your app/views directory. For each files that does not validate, it will create a .errors file which will contain the error messages from tidy for that file.

If you want to validate only one file, use

  $ rake test:templates FILE="path/to/the/file"

If $FILE is a directory, it will search for all *.rhtml file in it and try to validates them. If $FILE is a regular file it will be validated. If $FILE does not exists it will try with:

  • ".rhtml" appended to $FILE,
  • the app/view directory prepended to $FILE,
  • the app/view directory prepended and ".rhtml" appended to $FILE

4.2 Validating html output

The plugin adds a new assert_tidy method to the Test::Unit::TestCase class. You can use it in your class by simply call it with no arguments. It will validate the last response returned by a test. For example:

  get :index
  assert_sucess
  assert_tidy

4.3 Cleaning rails html output

The plugin allows you to clean the html produced by rails. To enable it, use an after filter in your app/controller/application.rb file

  class ApplicationController < ActionController::Base
    after_filter :tidy
    def tidy
      RailsTidy.filter(response)
    end
  end

To configure tidy output, see "3. Configuration"

WARNING: THIS IS CERTAINLY A RESOURCE HOG. I‘m not interrested in this feature so I didn‘t benchmarked it but at first sight rendering is at least 2 times slower with the filter enabled.

5. License

This plugin is licensed under the MIT license. Complete license text is included in the MIT-LICENSE file.

6. Author

This plugin was created by Damien Merenne <dam@cosinux.org> and is located at blog.cosinux.org/pages/rails-tidy.

[Validate]