-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
36 lines (32 loc) · 1.09 KB
/
index.ts
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
34
35
36
import * as pug from "pug";
import { Input, Output, ActionStep } from "@shanzhai/interfaces";
/**
* An {@link ActionStep} which renders a previously parsed Pug template.
*/
export class RenderPugStep extends ActionStep {
/**
* @param name A description of the operation being performed.
* @param template An {@link Input} from which to retrieve the previously
* parsed Pug template
* @param locals An {@link Input} from which to retrieve the locals object
* to provide to the template.
* @param output An {@link Output} to which to provide the rendered HTML.
*/
constructor(
public readonly name: string,
public readonly template: Input<pug.compileTemplate>,
public readonly locals: Input<pug.LocalsObject>,
public readonly output: Output<string>
) {
super(name, output.effects);
}
/**
* @inheritdoc
*/
async execute(): Promise<void> {
const template = await this.template.get();
const locals = await this.locals.get();
const rendered = template(locals);
await this.output.set(rendered);
}
}