summaryrefslogtreecommitdiffstats
path: root/lib/models/templateEngine.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/templateEngine.js')
-rw-r--r--lib/models/templateEngine.js22
1 files changed, 6 insertions, 16 deletions
diff --git a/lib/models/templateEngine.js b/lib/models/templateEngine.js
index 114aa73..0d0a015 100644
--- a/lib/models/templateEngine.js
+++ b/lib/models/templateEngine.js
@@ -2,10 +2,10 @@ var nunjucks = require('nunjucks');
var Immutable = require('immutable');
var TemplateEngine = Immutable.Record({
- // List of {TemplateBlock}
- blocks: Immutable.List(),
+ // Map of {TemplateBlock}
+ blocks: Immutable.Map(),
- // List of Extension
+ // Map of Extension
extensions: Immutable.Map(),
// Map of filters: {String} name -> {Function} fn
@@ -68,12 +68,12 @@ TemplateEngine.prototype.getBlock = function(name) {
@return {Nunjucks.Environment}
*/
TemplateEngine.prototype.toNunjucks = function() {
- var that = this;
var loader = this.getLoader();
var blocks = this.getBlocks();
var filters = this.getFilters();
var globals = this.getGlobals();
var extensions = this.getExtensions();
+ var context = this.getContext();
var env = new nunjucks.Environment(
loader,
@@ -95,13 +95,13 @@ TemplateEngine.prototype.toNunjucks = function() {
// Add filters
filters.forEach(function(filterFn, filterName) {
- env.addFilter(filterName, that.bindToContext(filterFn));
+ env.addFilter(filterName, filterFn.bind(context));
});
// Add blocks
blocks.forEach(function(block) {
var extName = block.getExtensionName();
- var Ext = block.toNunjucksExt();
+ var Ext = block.toNunjucksExt(context);
env.addExtension(extName, new Ext());
});
@@ -120,16 +120,6 @@ TemplateEngine.prototype.toNunjucks = function() {
};
/**
- Bind a function to the context
-
- @param {Function} fn
- @return {Function}
-*/
-TemplateEngine.prototype.bindToContext = function(fn) {
- return fn.bind(this.getContext());
-};
-
-/**
Create a template engine
@param {Object} def