summaryrefslogtreecommitdiff
path: root/node_modules/@11ty/eleventy/src/Engines/Html.js
blob: a0f410190d449bb74da4e7e7f0c573d5eb5bfc04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import TemplateEngine from "./TemplateEngine.js";

export default class Html extends TemplateEngine {
	constructor(name, eleventyConfig) {
		super(name, eleventyConfig);
	}

	get cacheable() {
		return true;
	}

	async #getPreEngine(preTemplateEngine) {
		return this.engineManager.getEngine(preTemplateEngine, this.extensionMap);
	}

	async compile(str, inputPath, preTemplateEngine) {
		if (preTemplateEngine) {
			let engine = await this.#getPreEngine(preTemplateEngine);
			let fnReady = engine.compile(str, inputPath);

			return async function (data) {
				let fn = await fnReady;

				return fn(data);
			};
		}

		return function () {
			// do nothing with data if preTemplateEngine is falsy
			return str;
		};
	}
}