tags:

views:

698

answers:

2

I'm using HAML to generate some static html pages for a site, and I was wanting to split out common components into partials that I can include in multiple pages, just like in Rails. However I don't want to use the whole Rails stack to do this as it seems like overkill.

I've looked around on the Internet but haven't found anything, better than just doing something like:

Haml::Engine.new(IO.read("header.haml")).render

Is there a nicer way of including so-called partials from within HAML? An existing filter or command that I'm missing?

+1  A: 

Darn, your right there isn't a built in way. I've used helpers with the haml command line, but alway ones whose output was already HTML formatted.

My best suggestion is to write a partial() method and require it. It appear you have already started down this path. I would suggest anyone writing such a function consider keeping the original binding around in some way Haml::Helpers#capture_hame looks to be the easiest way to make this happen. If execution speed is an issue, it might also be a good idea to cache some the parsed template a la Merb.

If someone does get some code working, please put it up on GitHub and make a comment here.

John F. Miller
+2  A: 

It's best to combine haml & sass with a tool for building static websites. Here's some links:

I'm using jekyll for my blog, but if you're not building a blog it's probably not appropriate for your needs.

chriseppstein
Although Jekyll looks nice, it's pretty much made for blogs. Though StaticMatic seems to be just what I want. I was thinking of implementing something similar myself (i.e. use Erb as a pre/post-processor for Haml templates, like C compilers worl).Thanks
Daemin