Written by: steve ross on March 30th 2007

Obsolescence Notice: This plugin is no longer in existence. It was incorporated as a patch into Rails, and now pretty much any templating engine works.

For the record:

Haml has made my Rails development far more precise and the number of display glitches far fewer. But, templating emails remained the exclusive domain of rhtml and its ilk. The challenge has been how to get ActionMailer to recognize what ActionView already did: That other templating languages besides rhtml, rxml, erb, and builder exist. Turns out the hard-coding was recognized and flagged as a TODO in the code.

I put together a patch (see the patch) for Rails, and good news it looks like it was accepted. I was overjoyed. Now I could write email templates in Haml! Right? I thought so, but it appears the patch was not committed -- at least in trunk as of this writing (poke, poke, prod, prod). Not one to easily give up, I adopted a different strategy: A plugin.

So, here it is: TemplatedMailer!

You can get it via svn at:

  
    http://svn.calicowebdev.com/plugins/templated_mailer
  

or the normal plugin installation process:

  
    ruby script/plugin install http://svn.calicowebdev.com/plugins/templated_mailer
  

h2. Where Are the Docs?

Well, there really aren't any, but you can run rake doc:plugins to generate an rdoc version of this (and all your other plugins). Here it is in a nutshell.

  1. Install the plugin
  2. In your environment.rb, add this line at the bottom:
  
    ActionMailer::Base.register_template_extension('haml')
  

And that's it. Whenever you are tempted to type "rhtml" stop. Type "haml". The view file for the contact mailer for this page is: moderation_ping.plain.text.haml. Yes, I even use it myself.