The Pug Automatic

Haml::Template options in Merb

Written February 5, 2008. Tagged Ruby, Haml, Merb.

I'm rewriting a toy project in Merb (0.5).

Though Merb supports Haml out of the box, I was unable to find a simple way of changing the Haml options, e.g. to wrap attributes in double-quotes instead of the default single-quotes.

In Rails, you can set them in the Haml::Template.options hash, but that doesn't work in Merb; that class is closely tied to Rails.

You can also pass options to the Haml::Engine constructor (which is what Template does). Merb doesn't seem to offer a simple way of doing this, but Ruby itself does.

Stick this in config/merb_init.rb:

# Haml template configuration

class Haml::Engine
alias_method :old_initialize, :initialize
def initialize(template, options = {})
:attr_wrapper => %{"}
old_initialize(template, options)

And that's it.