Topic: clean up html output with a filter?

A typical view in my app is rendered with several partials, a layout, helpers, etc etc. All of this code is written to be maintainable from the source code perspective. So for example a partial will start its first tag at the first level, it's first nested tag with one indent, etc etc.

This ultimately leads to html that is sent to the browser that is very messy. Generally I don't care about this output being messy, especially since the source itself is very clean. But I am now wanting to make my entire site's layout be done with CSS, and I want to inspect my outputted HTML to ensure no little style attributes, bgcolor attributes, bold, br, etc are sneaking in.

I'm hoping to find or write a filter that will take the entire output and format it nicely just before sending to the client. But it appears after_filter happens after the view has already been rendered. I have noticed rails also has around_filter, but haven't found much on what it really does.

Surely this can't be an uncommon desire. Anyone done this?

Last edited by tortoise (2007-01-27 14:33:41)

Re: clean up html output with a filter?

See this post.

Railscasts - Free Ruby on Rails Screencasts

Re: clean up html output with a filter?

thanks, that worked great! now my site is on the homestretch, heading towards the finish line smile

Re: clean up html output with a filter?

Just a heads up for anyone else thay may do this.

If you apply tidy as an after_filter, it will filter *all* responses, that includes binary (images) and rjs responses. I found tidy was the source of anything that isn't HTML breaking in my app. So only apply the filter to html responses smile