-
Notifications
You must be signed in to change notification settings - Fork 13
/
mod.ts
54 lines (49 loc) · 1.56 KB
/
mod.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Environment } from "./src/environment.ts";
import { FileLoader, Loader } from "./src/loader.ts";
import ifTag from "./plugins/if.ts";
import forTag from "./plugins/for.ts";
import includeTag from "./plugins/include.ts";
import setTag from "./plugins/set.ts";
import jsTag from "./plugins/js.ts";
import layoutTag from "./plugins/layout.ts";
import functionTag from "./plugins/function.ts";
import importTag from "./plugins/import.ts";
import exportTag from "./plugins/export.ts";
import echoTag from "./plugins/echo.ts";
import escape from "./plugins/escape.ts";
import unescape from "./plugins/unescape.ts";
import trim from "./plugins/trim.ts";
export interface Options {
includes?: string | Loader;
/** @deprecated Use autoDataVarname */
useWith?: boolean;
autoDataVarname?: boolean;
dataVarname?: string;
autoescape?: boolean;
}
export default function (options: Options = {}): Environment {
const loader = typeof options.includes === "object"
? options.includes
: new FileLoader(options.includes || Deno.cwd());
const env = new Environment({
loader,
dataVarname: options.dataVarname || "it",
autoescape: options.autoescape ?? false,
autoDataVarname: options.autoDataVarname ?? options.useWith ?? true,
});
// Register basic plugins
env.use(ifTag());
env.use(forTag());
env.use(jsTag());
env.use(includeTag());
env.use(setTag());
env.use(layoutTag());
env.use(functionTag());
env.use(importTag());
env.use(exportTag());
env.use(echoTag());
env.use(escape());
env.use(unescape());
env.use(trim());
return env;
}