deno.land / x / eta@v1.12.3 / config.ts

config.ts
View Documentation
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import { templates } from "./containers.ts";import { copyProps, XMLEscape } from "./utils.ts";import EtaErr from "./err.ts";
/* TYPES */
import type { TemplateFunction } from "./compile.ts";import type { Cacher } from "./storage.ts";
type trimConfig = "nl" | "slurp" | false;
export interface EtaConfig { /** Whether or not to automatically XML-escape interpolations. Default true */ autoEscape: boolean;
/** Configure automatic whitespace trimming. Default `[false, 'nl']` */ autoTrim: trimConfig | [trimConfig, trimConfig];
/** Compile to async function */ async: boolean;
/** Whether or not to cache templates if `name` or `filename` is passed */ cache: boolean;
/** XML-escaping function */ e: (str: string) => string;
/** Parsing options */ parse: { /** Which prefix to use for evaluation. Default `""` */ exec: string;
/** Which prefix to use for interpolation. Default `"="` */ interpolate: string;
/** Which prefix to use for raw interpolation. Default `"~"` */ raw: string; };
/** Array of plugins */ plugins: Array< { processFnString?: Function; processAST?: Function; processTemplate?: Function; } >;
/** Remove all safe-to-remove whitespace */ rmWhitespace: boolean;
/** Delimiters: by default `['<%', '%>']` */ tags: [string, string];
/** Holds template cache */ templates: Cacher<TemplateFunction>;
/** Name of the data object. Default `it` */ varName: string;
/** Absolute path to template file */ filename?: string;
/** Holds cache of resolved filepaths. Set to `false` to disable */ filepathCache?: Record<string, string> | false;
/** A filter function applied to every interpolation or raw interpolation */ filter?: Function;
/** Function to include templates by name */ include?: Function;
/** Function to include templates by filepath */ includeFile?: Function;
/** Name of template */ name?: string;
/** Where should absolute paths begin? Default '/' */ root?: string;
/** Make data available on the global object instead of varName */ useWith?: boolean;
/** Whether or not to cache templates if `name` or `filename` is passed: duplicate of `cache` */ "view cache"?: boolean;
/** Directory or directories that contain templates */ views?: string | Array<string>;
[index: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any}
export interface EtaConfigWithFilename extends EtaConfig { filename: string;}
export type PartialConfig = Partial<EtaConfig>;
/* END TYPES */
/** * Include a template based on its name (or filepath, if it's already been cached). * * Called like `include(templateNameOrPath, data)` */
function includeHelper( this: EtaConfig, templateNameOrPath: string, data: object,): string { const template = this.templates.get(templateNameOrPath); if (!template) { throw EtaErr('Could not fetch template "' + templateNameOrPath + '"'); } return template(data, this);}
/** Eta's base (global) configuration */const config: EtaConfig = { async: false, autoEscape: true, autoTrim: [false, "nl"], cache: false, e: XMLEscape, include: includeHelper, parse: { exec: "", interpolate: "=", raw: "~", }, plugins: [], rmWhitespace: false, tags: ["<%", "%>"], templates: templates, useWith: false, varName: "it",};
/** * Takes one or two partial (not necessarily complete) configuration objects, merges them 1 layer deep into eta.config, and returns the result * * @param override Partial configuration object * @param baseConfig Partial configuration object to merge before `override` * * **Example** * * ```js * let customConfig = getConfig({tags: ['!#', '#!']}) * ``` */
function getConfig(override: PartialConfig, baseConfig?: EtaConfig): EtaConfig { // TODO: run more tests on this
const res: PartialConfig = {}; // Linked copyProps(res, config); // Creates deep clone of eta.config, 1 layer deep
if (baseConfig) { copyProps(res, baseConfig); }
if (override) { copyProps(res, override); }
return res as EtaConfig;}
/** Update Eta's base config */
function configure(options: PartialConfig): Partial<EtaConfig> { return copyProps(config, options);}
export { config, configure, getConfig };
eta
Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript
DocumentationDocumentation
GitHub Repositoryeta-dev/eta
GitHub Stars
527

Version Info

Tagged at
10 months ago

External Dependencies

1 external dependency