diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-04-25 14:29:51 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-04-25 14:29:51 +0200 |
commit | ac2ad8d8b5b539cc86c13229d230caa2dd461afa (patch) | |
tree | 78f2703d3d53922495815e7f6e60ce02cd8fc492 /lib/templating/renderFile.js | |
parent | 14ce495e9e6f162a74ef1e202fef62855da2a5fc (diff) | |
download | gitbook-ac2ad8d8b5b539cc86c13229d230caa2dd461afa.zip gitbook-ac2ad8d8b5b539cc86c13229d230caa2dd461afa.tar.gz gitbook-ac2ad8d8b5b539cc86c13229d230caa2dd461afa.tar.bz2 |
Add conrefs loader for templating
Diffstat (limited to 'lib/templating/renderFile.js')
-rw-r--r-- | lib/templating/renderFile.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/templating/renderFile.js b/lib/templating/renderFile.js new file mode 100644 index 0000000..13a9c5b --- /dev/null +++ b/lib/templating/renderFile.js @@ -0,0 +1,27 @@ +var Promise = require('../utils/promise'); + +var replaceShortcuts = require('./replaceShortcuts'); + +/** + Render a template + + @param {TemplateEngine} engine + @param {String} filePath + @param {String} content + @param {Object} ctx + @return {Promise<String>} +*/ +function renderTemplateFile(engine, filePath, content, context) { + context = context || {}; + var env = engine.toNunjucks(); + + content = replaceShortcuts(engine, filePath, content); + + return Promise.nfcall( + env.render.bind(env), + content, + context + ); +} + +module.exports = renderTemplateFile; |