public
Description: Plugin for Rails to render HTML tags instead of XHTML tags.
Homepage:
Clone URL: git://github.com/napcs/html_tags.git
README.rdoc

html_tags

Makes Rails helpers generate tags in HTML syntax instead of the XHTML 1.0 syntax it uses.

Why whould I want to do this?

The reasons for using HTML 4.01 Strict instead of XHTML 1.0 Transitional or XHTML 1.0 Strict are well-documented, but here are some reasons for using HTML:

  • The W3C currently recommends serving web page documents as HTML 4.01 Strict, due to several probelsm with XHTML.
  • Most web servers serve XHTML documents as text/html rather than application/xhtml+xml. This is often done because, unfortunately, Microsoft Internet Explorer 6, 7, and 8 cannot accept the media type application/xhtml+xml.
  • When you serve your XHTML syntax based documents as text/html they will be treated as HTML by the browser. The browser sees tag soup, and has to fix it on the fly. Even though your document is valid, it doesn’t matter to the browser. This wastes users’ time.

XHTML provides no real benefits to those developing web-based applications, and can in some cases create some serious headaches. Solutions like content negotiation, browser detection, etc are unnecessary if you simply serve valid, strict HTML.

This also prepares us for HTML 5, which is quite nice.

Further reading

Usage

Just install the plugin.

  ruby script/plugin install git://github.com/napcs/html_tags

The helpers are overridden to generate appropriate HTML syntax. Generally, this means no self-closing tags.

  • input no longer self-closes
  • img no longer self-closes
  • link no longer self-closes

Issues

I haven’t created tests for every possible tag case yet, but we have a start.

I’m also a little uncomfortable with the way this hacks the internals of Rails. I’ll keep looking for better ways. Please fork, patch, and send back!

Copyright © 2009 Brian Hogan, released under the MIT license