1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const Handlebars = require("handlebars");
|
4 | const fs_1 = require("../../../utils/fs");
|
5 | const stack_1 = require("./stack");
|
6 | class Template extends stack_1.Resource {
|
7 | getTemplate() {
|
8 | if (!this.template) {
|
9 | const raw = fs_1.readFile(this.fileName);
|
10 | this.template = Handlebars.compile(raw, {
|
11 | preventIndent: true
|
12 | });
|
13 | }
|
14 | return this.template;
|
15 | }
|
16 | render(context, options) {
|
17 | const template = this.getTemplate();
|
18 | return template(context, options);
|
19 | }
|
20 | }
|
21 | exports.Template = Template;
|
22 | class TemplateStack extends stack_1.ResourceStack {
|
23 | constructor() {
|
24 | super(Template, /\.hbs$/);
|
25 | }
|
26 | }
|
27 | exports.TemplateStack = TemplateStack;
|
28 | class PartialStack extends TemplateStack {
|
29 | constructor() {
|
30 | super(...arguments);
|
31 | this.registeredNames = [];
|
32 | }
|
33 | activate() {
|
34 | if (!super.activate()) {
|
35 | return false;
|
36 | }
|
37 | const resources = this.getAllResources();
|
38 | for (let name in resources) {
|
39 | if (this.registeredNames.includes(name)) {
|
40 | continue;
|
41 | }
|
42 | this.registeredNames.push(name);
|
43 | const partial = resources[name];
|
44 | const template = partial.getTemplate();
|
45 | Handlebars.registerPartial(name, template);
|
46 | }
|
47 | return true;
|
48 | }
|
49 | deactivate() {
|
50 | if (!super.deactivate()) {
|
51 | return false;
|
52 | }
|
53 | for (let name of this.registeredNames) {
|
54 | Handlebars.unregisterPartial(name);
|
55 | }
|
56 | this.registeredNames = [];
|
57 | return true;
|
58 | }
|
59 | }
|
60 | exports.PartialStack = PartialStack;
|
61 |
|
\ | No newline at end of file |