Using Slim or Haml & Sass / SCSS with Node.js?


I have a rather robust project that has all of its templates implemented in Slim and a little Haml. I'm considering moving the project over to a Node.js based structure (probably built atop Tower.js or something similar; maybe Meteor), however I would like to continue using Slim or Haml for the templates rather than shifting over to another template engine.

Has anyone done this or spent the time to figure out how to accomplish this so far, and if so, what were your findings?

1/29/2018 11:37:47 PM

Tower.js wraps the express.js template engine system, so you should be able to use any express.js template engine by adding the following to the configuration Tower.View.engine = "haml"

Tower.js uses mint, which has HAML built in, so you just need the haml module in your directory.

Slim is problematic though. First its not within mint.js directly, so you'll need to register a new template engine. Todo that you'll need to

  1. create a function customAdapter that mint.js can use, you can look at the mint.js sourcecode. Heres an example of the haml adapter function:

    function(content, options, callback) {
      var result;
      result = require('hamljs').render(content, options || {});
      if (callback) {, null, result);
      return result;
  2. you'll need to add the adapter to mint.js by doing require("mint").engines.slim = customAdapter

But there's no express.js engine for Slim, and since Slim contains ruby code snippets, it isn't likely there will be.
If you really want to do it so you'll need to create your own javascript parser for the template files (probably using something like , though with no specific ruby libraries), and then create an express.js engine (which I don't know how to).

I doubt it will be a very fruitful exercise.
I suggest you either convert your Slim files to haml (or jade, or any template engine that can be used by express.js) or don't make the move.
I could also not find any way to automatically convert Slim to haml or any other template engine (probably due to the fact that it contains ruby code), so you will have to do the conversion entirely manually.

4/22/2013 9:59:20 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow