"Rack middleware using HTML Tidy"
May 10, 2009
Did you waste some time trying to spot the problem in html markup in your ruby web app? Are you strict validation freak? If yes, then read on.
I had several situations when something disappeared from the page or layout broke and the problem was in some missing closing tags or invalid nesting of elements. As I recently do my web development in Merb and Sinatra (this blog actually runs on Sinatra) and both of them are built on top of Rack I thought that I could write a middleware which can show me the problems in my markup.
So here it is. It uses well known Tidy tool to check for markup errors in actions output. Following code snippet shows the middleware class and its use in the simplest Sinatra app.
After running this tiny webapp and opening root url in your browser you will get following output in terminal:
It prints any warning and error messages to the console so you can easily spot any minor and major problems in the markup.