RailsTidy 0.1 review

Download
by rbytes.net on

RailsTidy project is a plugin for Ruby On Rails. Here are some key features of "RailsTidy": · validate your rhtml templates, · v

License: MIT/X Consortium License
File size: 11K
Developer: Damien Merenne
0 stars award from rbytes.net

RailsTidy project is a plugin for Ruby On Rails.

Here are some key features of "RailsTidy":
validate your rhtml templates,
validate the html output of your functional tests,
clean the html generated by rails.

Requirements:
Tidy, the popular HTML validator and
RubyTidy, Ruby bindings for Tidy.

Installation:

Unpack into the vendor/plugin and that should be it. Ruby bindings for libtidy need to know the path to the file libtidy.so. It is assumed to be found at /usr/lib/libtidy.so . If this is not the case, add

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

to your environment file.

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.

Usage:

Validating templates

Simply use

$ rake test_templates

By default, the plugin will parse all *.rhtml files in your app/views directory. 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

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

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

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.

RailsTidy 0.1 search tags