Skip to content

Use HAML to render your layout and pages

ariejan edited this page Sep 13, 2010 · 4 revisions

Using HAML with Toto is quite easy.

1. Require ‘haml’ in your config.ru

2. Add the following snippet to your Toto::Server block:

  set :to_html,     lambda {|path, page, ctx|
    ::Haml::Engine.new(File.read("#{path}/#{page}.haml"), :format => :html5, :ugly => true).render(ctx)
  }

Note: the :ugly parameter prevents Haml from indenting pre blocks. It also gives better performance.

3. Set error codes to be rendered with HAML as well:

  set :error do |code|
    ::Haml::Engine.new(File.read("templates/pages/#{code}.haml"), :format => :html5, :ugly => true).render(@context)
  end

You may be interested in this erb2haml converter.

Clone this wiki locally