ee-templates
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -9,24 +9,15 @@ "use strict"; | ||
/** | ||
* | ||
* todo: add cache | ||
*/ | ||
var Factory = { | ||
rendererCache: null | ||
dataPropertyName: null | ||
, container: null | ||
, environments: null | ||
, init: function initialize(container) { | ||
this.container = container; | ||
this.rendererCache = { | ||
items: {} | ||
, get: function(key){ | ||
return this.has(key) ? this.items[key] : null; | ||
} | ||
, set: function(key, value){ | ||
this.items[key] = value; | ||
} | ||
, has: function(key){ | ||
return this.items.hasOwnProperty(key); | ||
} | ||
}; | ||
, init: function initialize(container, dataPropertyName) { | ||
this.dataPropertyName = dataPropertyName || 'data'; | ||
this.container = container; | ||
} | ||
@@ -74,3 +65,3 @@ | ||
var host = request.hostname; | ||
return new HTMLRenderer(this.container.get(host)); | ||
return new HTMLRenderer(this.container.get(host), this.dataPropertyName); | ||
} | ||
@@ -77,0 +68,0 @@ }; |
@@ -6,6 +6,8 @@ "use strict"; | ||
var HTMLRenderer = { | ||
env: null | ||
, init: function initialize(env) { | ||
, init: function initialize(env, dataPropertyName) { | ||
this.env = env; | ||
this.propertyName = dataPropertyName; | ||
} | ||
@@ -16,5 +18,13 @@ | ||
* todo: remove the try catch block as soon as we are sure the rendering does not throw errors anymore (nunjucks) | ||
* todo: try to find a better solution for the data assignment!! | ||
*/ | ||
var ctx = {}; | ||
if(!!this.propertyName){ | ||
ctx[this.propertyName] = data.content; | ||
} else { | ||
ctx = data.content; | ||
} | ||
try { | ||
this.env.render(data.template, data.content, function(err, content){ | ||
this.env.render(data.template, ctx, function(err, content){ | ||
return callback(err, content, 'text/html'); | ||
@@ -21,0 +31,0 @@ }); |
{ | ||
"name" : "ee-templates" | ||
, "description" : "Templating integration for the ee-soa-transport-rest based on Nunjucks" | ||
, "version" : "0.2.0" | ||
, "version" : "0.2.1" | ||
, "license" : "MIT" | ||
@@ -6,0 +6,0 @@ , "author" : "Michael Rüfenacht <ruefe@rcky.ch> (http://www.rcky.ch)" |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
567
0
24366
22