Skip to content

Commit

Permalink
Merge pull request #156 from harsha-mudi/master
Browse files Browse the repository at this point in the history
Loader support for nunjucks
  • Loading branch information
tj committed May 23, 2014
2 parents db55870 + df7325b commit 84c691a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Readme.md
Expand Up @@ -24,6 +24,7 @@
- [liquor](https://github.com/chjj/liquor)
- [lodash](https://github.com/bestiejs/lodash) [(website)](http://lodash.com/)
- [mustache](https://github.com/janl/mustache.js)
- [nunjucks](https://mozilla.github.io/nunjucks)
- [QEJS](https://github.com/jepso/QEJS)
- [ractive](https://github.com/Rich-Harris/Ractive)
- [swig](https://github.com/paularmstrong/swig) [(website)](http://paularmstrong.github.com/swig/)
Expand Down Expand Up @@ -119,6 +120,12 @@ app.listen(3000);
console.log('Express server listening on port 3000');
```

## Notes

* You can pass **partials** with `options.partials`
* For using **template inheritance** with nunjucks, you can pass a loader
with `options.loader`.

## Running tests

Install dev deps:
Expand Down
14 changes: 12 additions & 2 deletions lib/consolidate.js
Expand Up @@ -761,6 +761,16 @@ exports.nunjucks = fromStringRenderer('nunjucks');
*/

exports.nunjucks.render = function(str, options, fn) {
var engine = requires.nunjucks || (requires.nunjucks = require('nunjucks'));
engine.renderString(str, options, fn);
try {
var engine = requires.nunjucks || (requires.nunjucks = require('nunjucks'));
var loader = options.loader;
if (loader) {
var env = new engine.Environment(new loader(options));
env.renderString(str, options, fn);
} else {
engine.renderString(str, options, fn);
}
} catch (err) {
throw fn(err);
}
};

0 comments on commit 84c691a

Please sign in to comment.