mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
31 lines
653 B
JavaScript
31 lines
653 B
JavaScript
var Promise = require('../utils/promise');
|
|
|
|
var replaceShortcuts = require('./replaceShortcuts');
|
|
|
|
/**
|
|
Render a template
|
|
|
|
@param {TemplateEngine} engine
|
|
@param {String} filePath
|
|
@param {String} content
|
|
@param {Object} context
|
|
@return {Promise<String>}
|
|
*/
|
|
function renderTemplate(engine, filePath, content, context) {
|
|
context = context || {};
|
|
var env = engine.toNunjucks();
|
|
|
|
content = replaceShortcuts(engine, filePath, content);
|
|
|
|
return Promise.nfcall(
|
|
env.renderString.bind(env),
|
|
content,
|
|
context,
|
|
{
|
|
path: filePath
|
|
}
|
|
);
|
|
}
|
|
|
|
module.exports = renderTemplate;
|