Skip to content

Integration with express #53

@smebberson

Description

@smebberson

I've recently integrated Mu with express as the default templating engine for HTML files. I used the following module to achieve it:

var mu = require('mu2');

exports.__express = function (path, options, callback) {

    var result = '';

    var stream = mu.compileAndRender(path, options)
    .on('data', function (data) {
        result += data.toString();
    })
    .on('end', function () {
        callback(null, result);
    });

}

I wonder if you'd consider integrating something like the above into Mu? It needs a little more work, because you should be able to control caching within the options handle which I haven't wired up. But the above code works along with the following to integrate it into express:

app.set('views', __dirname + '/layouts');   // tell express where my views are
app.engine('html', muexpress.__express);    // register the mu templating engine (using my mu-express gateway)
app.set('view engine', 'html');             // register the default template engine as html

If you integrate it, I'd be keen to add a patch to https://github.com/visionmedia/consolidate.js/ so that you can use Mu with express quite simply.

Let me know your thoughts. I'd be happy to integrate it into Mu myself and send through a pull request.

cheers,
Scott.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions