/
README
executable file
·118 lines (72 loc) · 3.38 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
= RailsTidy
This plugin allows html validation of templates and the response body
of functional tests.
== 1. Requirements
- tidylib: http://tidy.sourceforge.net
- tidy for ruby: link:http://rubyforge.org/projects/tidy (gem install tidy)
<em>WARNING:</em> there is a bug in tidy for ruby.
The line separator is hard-encoded instead of using the <tt>$/</tt> magic
variable, so it breaks on unix platforms. Apply the tidy.patch[link:files/tidy_patch.html]
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 <tt>/usr/lib/ruby/gems/1.8/gems/tidy-1.1.2</tt>) 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 <tt>vendor/plugin</tt> 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 <tt>/usr/lib/libtidy.so</tt> for
Linux, <tt>/usr/lib/libtidy.dylib</tt> for Darwin and
<tt>/usr/bin/cygtidy-0-99-0.dll</tt> 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 <tt>config/tidy.rc</tt> 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
http://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 <tt>*.rhtml</tt> 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 <tt>*.rhtml</tt> file in it and
try to validates them. If <tt>$FILE</tt> is a regular file it will be
validated. If $FILE does not exists it will try with:
- ".rhtml" appended to <tt>$FILE</tt>,
- the app/view directory prepended to <tt>$FILE</tt>,
- the app/view directory prepended and ".rhtml" appended to <tt>$FILE</tt>
=== 4.2 Validating html output
The plugin adds a new assert_tidy method to the <tt>Test::Unit::TestCase</tt>
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 <tt>app/controller/application.rb</tt> file
class ApplicationController < ActionController::Base
after_filter :tidy
def tidy
RailsTidy.filter(response)
end
end
To configure tidy output, see "3. Configuration"
<em>WARNING</em>: 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[link:files/MIT-LICENSE.html] file.
== 6. Author
This plugin was created by Damien Merenne <dam@cosinux.org> and is
located at http://blog.cosinux.org/pages/rails-tidy.