Add basic support for the Express framework #55

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
6 participants

acstll commented Dec 31, 2012

I added a single function to the node module (index.js) to support the Express framework.

No dependencies. The main doT.js remains untouched.

I guess there's reasons for this to be in its own module/repo, as in https://github.com/cstigler/express-dot and also reasons for this to be included in doT.

You could also have an express.js file in the repo with some more functionality (like cache support) and require it in index.js

I think it's useful to just include the doT module in for project and use it right away with Express,
which seems to be widely adopted (I don't know statistically). I've been using it like that for a while.

Usage in an Express app is simple, as expected:

app.set('view engine', 'dot');

if you're using .dot files. Or:

app.engine('html', require('dot').__express);
app.use('view engine', 'html');

if you want to use any other extension.

I hope this is useful if it makes sense to you.

Happy new year.

@olado it would be great to get this support into doT.js - @acstll perhaps you could extend the README with the example you've provided above for other users to know how to use this with express 3.

acstll commented Mar 1, 2013

@sebowles51 my doT fork is outdated, so it makes little sense to update the README.md file now. Plus I'm no longer using doT for templates on my node projects. I'm sorry.

However, the usage is as explained on the Express docs for any template engine supporting it.

The best option in my opinion would be to add doT to the consolidate module: https://github.com/visionmedia/consolidate.js/

(I think someone tried once to do it but there were some errors and the pull request didn't make it.)

@acstll for some reason I would like to just require dot and have the functionality needed instead of needing to use express-dot (like I am at the moment) or consolidate?

Just rechecked consolidate - it looks like it does now have doT support! https://github.com/visionmedia/consolidate.js/blob/master/lib/consolidate.js#L678

With a fix 6 days ago.

Now, consolidate vs express-dot? Something to ponder later.

Danetag commented Sep 10, 2014

At this time, consolidate.js doesn't support dot, still have to use express-dot :/ Any update?

olado added the needs review label Nov 24, 2014

Owner

olado commented Dec 2, 2014

Consolidate has support for doT btw, it is just not listed, but it does support it.
I added an example for best use with express which does not involve consolidate:
https://github.com/olado/doT/tree/master/examples/express

I have used the function written by @acstll for express support, and it works perfectly. Please consider merging the changes in the master branch.

express-dot works well for me. The only issue I have with it is it doesn't expose the doT object so I can do precompiling. I fixed that by adding the doT object to the exports of express-dot like so:

exports.__doT = doT;

This enabled preprocessing in my express app.js like this:

var dots = {
    molecules: doT.__doT.process({ path: view + "/molecules"})
};

Then using the extend module, I can render a page like so with doT methods available:

var data = { some: 'data' };
res.render('index.html', extend({}, dots, data));

Then inside index.html, I have all the methods from the dots object available from the 'it' object.

Owner

olado commented May 8, 2015

Here is an example for using doT with express without any additional modules
https://github.com/olado/doT/blob/master/examples/express/lib/app.js

acstll commented May 9, 2015

I'm closing this PR because I no longer think this should be merge into the doT library, which shouldn't care about framework implementations, imo.

There's nothing wrong in using express-dot or any other module that hooks doT (or any other template engine) with your framework of choice.

Use @olado 's example, consolidate or roll your own solution.

acstll closed this May 9, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment