Alexey Verkhovsky wrote:
> Returning our programming back to the epic struggle with typos :)
> 
> I am playing quite a bit with Rails these days, and I keep wondering if
> there is any tool to perform static checking of eruby files?
> 
> Ideally, I would love to have something that validates them against
> XHTML 1.0 DTD (keeping in mind that with Rails layout construct actual
> eRuby sources may not have <html /> as the root tag. 
> 
> I would even settle for something that validates them as well-formed
> XML. Of course, eRuby is well-formed XML only after you remove <% %>
> tags.

Which is one problem I have with HTML templating systems that don't use 
SGML/XML syntax for template markers.  They don't always play well with 
markup editors and validators.

> 
> For now, I just put assertions in the functional tests that HTML output
> is a well-formed XML conforming with XHTML Strict DTD. The downside of
> this approach is having to track any violation from HTML back to the
> offending .rhtml. At times it is a bit tedious. I want to find a faster
> way to clean the simple problems.

The issues I run into with dynamically building XHTML usually concern 
some specific segment of a page, not the page as a whole (though of 
course a local validation error fails the whole page).

For example, dynamically building links but neglecting to encode certain 
characters.  Little things, such as places where the DTD is picky about 
child elements (e.g., block-level elements placed inside inline elements).

Very little validation requires you to have the entire final page ready 
(an exception would be when checking that all element IDs are unique, or 
if you are using id  and idref).  So unit tests may be able to use a 
stock xhtml template where you can just plug in a segment of generated 
markup.  If the resulting page fails validation you know where the 
problem is.

As for doing the actual validation against a DTD, I find rxp very good. 
  I'm unaware of any Ruby bindings for it, though.

http://www.cogsci.ed.ac.uk/~richard/rxp.html

There is also, I believe, some RELAX-NG support in REXML.


James