title: Using layouts in HAML files independently of Rails
body: <p>My end goal is to create several static HTML files for hand-off to other folks.</p>
  
  <p>But for my workflow, I'd like to have HAML as the basic source files. In doing so, I'd hope to DRY up the process at least on my side.</p>
  
  <p>Now I have a lot of pages that will ultimately be sharing a common layout, and I'm wondering how to incorporate the layouts.</p>
  
  <p>Here's my current code:</p>
  
  <h2>./compile.rb</h2>
  
  <pre><code>#!/usr/bin/env ruby
  
  require 'rubygems'
  require 'rake'
  require 'haml'
  
  FileList.new('./src/*.html.haml').each do |filename|
    if filename =~ /([^\/]+)\.haml$/
      File.open($1, 'w') do |f|
        f.write Haml::Engine.new(File.read(filename)).render
      end
    end
  end
  </code></pre>
  
  <h2>./src/layout.html.haml</h2>
  
  <pre><code>!!!
  %html
    %head
      %title Yay
    %body
      = yield
  </code></pre>
  
  <h2>./src/home.html.haml</h2>
  
  <pre><code>= render :layout =&gt; 'header' do
    %p This is awesome
  </code></pre>
  
  <p>Now this clearly doesn't work because the render method is undefined out of the context of Rails, but I hope it gets the point across what I'm trying to do.</p>
  
  <p>Any suggestions?</p>