* Render a template * * @param {TemplateEngine} engine * @param {String} filePath: absolute path for the loader * @param {String} content * @param {Object} context (optional) * @return {Promise }
(engine, filePath, content, context)
| 13 | * @return {Promise<TemplateOutput>} |
| 14 | */ |
| 15 | function renderTemplate(engine, filePath, content, context) { |
| 16 | context = context || {}; |
| 17 | |
| 18 | // Mutable objects to contains all blocks requiring post-processing |
| 19 | var blocks = {}; |
| 20 | |
| 21 | // Create nunjucks environment |
| 22 | var env = engine.toNunjucks(blocks); |
| 23 | |
| 24 | // Replace shortcuts from plugin's blocks |
| 25 | content = replaceShortcuts(engine.getBlocks(), filePath, content); |
| 26 | |
| 27 | return timing.measure( |
| 28 | 'template.render', |
| 29 | |
| 30 | Promise.nfcall( |
| 31 | env.renderString.bind(env), |
| 32 | content, |
| 33 | context, |
| 34 | { |
| 35 | path: filePath |
| 36 | } |
| 37 | ) |
| 38 | .then(function(content) { |
| 39 | return TemplateOutput.create(content, blocks); |
| 40 | }) |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | module.exports = renderTemplate; |
no test coverage detected
searching dependent graphs…