Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with express #53

Open
smebberson opened this issue Jun 4, 2013 · 4 comments
Open

Integration with express #53

smebberson opened this issue Jun 4, 2013 · 4 comments

Comments

@smebberson
Copy link

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.

@RangerMauve
Copy link

I think one of the issues with this is that you're losing the streaming capability that Mu provides.

@smebberson
Copy link
Author

From what I can see, the express rendering interface doesn't accept a stream though, just a string?

@RangerMauve
Copy link

That's exactly the problem. I ended up creating my own implementation of res.render() that has the same API and uses the same express features (app.locals, app.set("views"), etc), but does streaming instead of rendering a single string.

@raycmorgan
Copy link
Owner

I am not sure I want to expose a non-streaming API. I do have an express engine wrapper around Twitter's Mustache (non-streaming) Hogan here: https://github.com/raycmorgan/hogan-engine

I use that one when I am just making simple Express apps and don't care much about streaming/performance. There are a few differences between Hogan/Mu from my experimenting with it, so maybe a mu-engine module that simply wraps Mu into what Express needs would be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants