gulp-nunjucks-with-env
Use Nunjucks Environment Class to get more control
Issues with the output should be reported on the Nunjucks issue tracker.
Install
Install with npm
npm install --save-dev gulp-nunjucks-with-env
Example : Using Environment Class
var gulp = ;var nunjucksRender = ; var environment = nunjucksRendernunjucks;environment;nunjucksRender = nunjucksRender; gulp;
Check Nunjucks API for more information on Environment Class
Note: To keep Nunjucks render from eating up all your ram, make sure to specify your watch path. nunjucksRender.nunjucks.configure(['src/path/to/templates/']);
This will also allow you to define your paths relatively.
Example : Using with gulp data
var gulp = ;var nunjucksRender = ;var data = ; { return example: 'data loaded for ' + filerelative ;} gulp;
Example : Using with pass by reference globals
var gulp = ;var nunjucksRender = ; var environment = nunjucksRendernunjucks;environment;var files = widgetFiles : ;templateEngine = templateEngine; gulp; gulp;
API
nunjucksRender(environment, context, passByReferenceGlobals)
environment (optional) Environment Class
:
Environment Class
context (optional) Object
:
Same context as nunjucks.render()
Note : You will have to pass empty object {}, if you want to use passByReferenceGlobals
passByReferenceGlobals (optional) Object
:
Parameters from this object will be added to context through pass by reference rather than pass by value
Example :
nunjucksRender(environment,{css_path: 'http://company.com/css/'});
or
nunjucksRender({css_path: 'http://company.com/css/'});
For the following template
<link rel="stylesheet" href="{{ css_path }}test.css" />
Would render
<link rel="stylesheet" href="http://company.com/css/test.css" />
License
MIT © AvcS
Shout-outs
Sindre Sorhus who wrote the original gulp-nunjucks for precompiling Nunjucks templates.
Carlos G. Limardo updated this to render instead of precompile in gulp-nunjucks-render
I updated this to facilitate using of Environment Class for more control