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.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/models/templateEngine.js b/lib/models/templateEngine.js
index 1f93879..aaa70fd 100644
--- a/lib/models/templateEngine.js
+++ b/lib/models/templateEngine.js
@@ -1,6 +1,8 @@
var nunjucks = require('nunjucks');
var Immutable = require('immutable');
+var Promise = require('../utils/promise');
+
var TemplateEngine = Immutable.Record({
// List of {TemplateBlock}
blocks: Immutable.List(),
@@ -16,7 +18,7 @@ var TemplateEngine = Immutable.Record({
// Nunjucks loader
loader: nunjucks.FileSystemLoader('views')
-});
+}, 'TemplateEngine');
TemplateEngine.prototype.getBlocks = function() {
return this.get('blocks');
@@ -103,4 +105,26 @@ TemplateEngine.prototype.bindToContext = function(fn) {
return fn.bind(this.getContext());
};
+/**
+ Render a template
+
+ @param {String} filePath
+ @param {String} content
+ @param {Object} ctx
+ @return {Promise<String>}
+*/
+TemplateEngine.prototype.render = function renderTemplate(filePath, content, context) {
+ context = context || {};
+ var env = this.toNunjucks();
+
+ return Promise.nfcall(
+ env.renderString.bind(env),
+ content,
+ context,
+ {
+ path: filePath
+ }
+ );
+};
+
module.exports = TemplateEngine;