@this {object}
(content, templateLang, options = {})
| 18 | |
| 19 | /** @this {object} */ |
| 20 | async function compile(content, templateLang, options = {}) { |
| 21 | let { templateConfig, extensionMap } = options; |
| 22 | let strictMode = options.strictMode ?? false; |
| 23 | |
| 24 | if (!templateConfig) { |
| 25 | templateConfig = new TemplateConfig(null, false); |
| 26 | templateConfig.setDirectories(new ProjectDirectories()); |
| 27 | await templateConfig.init(); |
| 28 | } |
| 29 | |
| 30 | // Breaking change in 2.0+, previous default was `html` and now we default to the page template syntax |
| 31 | if (!templateLang) { |
| 32 | templateLang = this.page.templateSyntax; |
| 33 | } |
| 34 | |
| 35 | if (!extensionMap) { |
| 36 | if (strictMode) { |
| 37 | throw new Error("Internal error: missing `extensionMap` in RenderPlugin->compile."); |
| 38 | } |
| 39 | extensionMap = new EleventyExtensionMap(templateConfig); |
| 40 | extensionMap.engineManager = new TemplateEngineManager(templateConfig); |
| 41 | } |
| 42 | let tr = new TemplateRender(templateLang, templateConfig); |
| 43 | tr.extensionMap = extensionMap; |
| 44 | |
| 45 | if (templateLang) { |
| 46 | await tr.setEngineOverride(templateLang); |
| 47 | } else { |
| 48 | await tr.init(); |
| 49 | } |
| 50 | |
| 51 | // TODO tie this to the class, not the extension |
| 52 | if ( |
| 53 | tr.engine.name === "11ty.js" || |
| 54 | tr.engine.name === "11ty.cjs" || |
| 55 | tr.engine.name === "11ty.mjs" |
| 56 | ) { |
| 57 | throw new Error( |
| 58 | "11ty.js is not yet supported as a template engine for `renderTemplate`. Use `renderFile` instead!", |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | return tr.getCompiledTemplate(content); |
| 63 | } |
| 64 | |
| 65 | // No templateLang default, it should infer from the inputPath. |
| 66 | async function compileFile(inputPath, options = {}, templateLang) { |
no test coverage detected