MCPcopy
hub / github.com/GitbookIO/gitbook / renderTemplate

Function renderTemplate

lib/templating/render.js:15–42  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

13 * @return {Promise<TemplateOutput>}
14 */
15function 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
44module.exports = renderTemplate;

Callers 2

conrefsLoader.jsFile · 0.85
postRender.jsFile · 0.85

Calls 1

replaceShortcutsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…