1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | export type TemplateCallback<T> = (err: lib.TemplateError | null, res: T | null) => void;
|
8 | export type Callback<E, T> = (err: E | null, res: T | null) => void;
|
9 |
|
10 | export function render(name: string, context?: object): string;
|
11 | export function render(name: string, context?: object, callback?: TemplateCallback<string>): void;
|
12 |
|
13 | export function renderString(src: string, context: object): string;
|
14 | export function renderString(src: string, context: object, callback?: TemplateCallback<string>): void;
|
15 |
|
16 | export function compile(src: string, env?: Environment, callback?: TemplateCallback<Template>): Template;
|
17 |
|
18 | export function precompile(path: string, opts?: PrecompileOptions): string;
|
19 | export function precompileString(src: string, opts?: PrecompileOptions): string;
|
20 |
|
21 | export interface PrecompileOptions {
|
22 | name?: string | undefined;
|
23 | asFunction?: boolean | undefined;
|
24 | force?: boolean | undefined;
|
25 | env?: Environment | undefined;
|
26 | include?: string[] | undefined;
|
27 | exclude?: string[] | undefined;
|
28 | wrapper?(templates: { name: string; template: string }, opts: PrecompileOptions): string;
|
29 | }
|
30 |
|
31 | export class Template {
|
32 | constructor(src: string, env?: Environment, path?: string, eagerCompile?: boolean);
|
33 | render(context?: object): string;
|
34 | render(context?: object, callback?: TemplateCallback<string>): void;
|
35 | }
|
36 |
|
37 | export function configure(options: ConfigureOptions): Environment;
|
38 | export function configure(path: string | string[], options?: ConfigureOptions): Environment;
|
39 |
|
40 | export interface ConfigureOptions {
|
41 | autoescape?: boolean | undefined;
|
42 | throwOnUndefined?: boolean | undefined;
|
43 | trimBlocks?: boolean | undefined;
|
44 | lstripBlocks?: boolean | undefined;
|
45 | watch?: boolean | undefined;
|
46 | noCache?: boolean | undefined;
|
47 | dev?: boolean | undefined;
|
48 | web?:
|
49 | | {
|
50 | useCache?: boolean | undefined;
|
51 | async?: boolean | undefined;
|
52 | }
|
53 | | undefined;
|
54 | express?: object | undefined;
|
55 | tags?:
|
56 | | {
|
57 | blockStart?: string | undefined;
|
58 | blockEnd?: string | undefined;
|
59 | variableStart?: string | undefined;
|
60 | variableEnd?: string | undefined;
|
61 | commentStart?: string | undefined;
|
62 | commentEnd?: string | undefined;
|
63 | }
|
64 | | undefined;
|
65 | }
|
66 |
|
67 | export class Environment {
|
68 | options: {
|
69 | autoescape: boolean;
|
70 | };
|
71 |
|
72 | constructor(loader?: ILoaderAny | ILoaderAny[] | null, opts?: ConfigureOptions);
|
73 | render(name: string, context?: object): string;
|
74 | render(name: string, context?: object, callback?: TemplateCallback<string>): void;
|
75 |
|
76 | renderString(name: string, context: object): string;
|
77 | renderString(name: string, context: object, callback?: TemplateCallback<string>): void;
|
78 |
|
79 | addFilter(name: string, func: (...args: any[]) => any, async?: boolean): Environment;
|
80 | getFilter(name: string): (...args: any[]) => any;
|
81 |
|
82 | addExtension(name: string, ext: Extension): Environment;
|
83 | removeExtension(name: string): void;
|
84 | getExtension(name: string): Extension;
|
85 | hasExtension(name: string): boolean;
|
86 |
|
87 | addGlobal(name: string, value: any): Environment;
|
88 | getGlobal(name: string): any;
|
89 |
|
90 | getTemplate(name: string, eagerCompile?: boolean): Template;
|
91 | getTemplate(name: string, eagerCompile?: boolean, callback?: Callback<Error, Template>): void;
|
92 |
|
93 | express(app: object): void;
|
94 |
|
95 | on(
|
96 | event: 'load',
|
97 | fn: (name: string, source: { src: string; path: string; noCache: boolean }, loader: Loader) => void,
|
98 | ): void;
|
99 | }
|
100 |
|
101 | export interface Extension {
|
102 | tags: string[];
|
103 |
|
104 | parse(parser: any, nodes: any, lexer: any): any;
|
105 | }
|
106 |
|
107 | export function installJinjaCompat(): void;
|
108 |
|
109 |
|
110 | export type ILoaderAny = ILoader | ILoaderAsync | WebLoader;
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | export interface ILoader {
|
116 | async?: false | undefined;
|
117 |
|
118 | getSource: (name: string) => LoaderSource;
|
119 | }
|
120 |
|
121 |
|
122 | export interface ILoaderAsync {
|
123 | async: true;
|
124 |
|
125 | getSource: (name: string, callback: Callback<Error, LoaderSource>) => void;
|
126 | }
|
127 |
|
128 |
|
129 |
|
130 | export class Loader {
|
131 | on(name: string, func: (...args: any[]) => any): void;
|
132 | emit(name: string, ...args: any[]): void;
|
133 | resolve(from: string, to: string): string;
|
134 | isRelative(filename: string): boolean;
|
135 | static extend<LoaderClass extends typeof Loader>(this: LoaderClass, toExtend: ILoaderAny): LoaderClass;
|
136 | }
|
137 |
|
138 | export interface LoaderSource {
|
139 | src: string;
|
140 | path: string;
|
141 | noCache: boolean;
|
142 | }
|
143 |
|
144 | export interface LoaderOptions {
|
145 |
|
146 | watch?: boolean;
|
147 |
|
148 |
|
149 | noCache?: boolean;
|
150 | }
|
151 |
|
152 | export type FileSystemLoaderOptions = LoaderOptions;
|
153 | export type NodeResolveLoaderOptions = LoaderOptions;
|
154 |
|
155 | export class FileSystemLoader extends Loader implements ILoader {
|
156 | constructor(searchPaths?: string | string[], opts?: FileSystemLoaderOptions);
|
157 | getSource(name: string): LoaderSource;
|
158 | }
|
159 |
|
160 | export class NodeResolveLoader extends Loader implements ILoader {
|
161 | constructor(searchPaths?: string | string[], opts?: NodeResolveLoaderOptions);
|
162 | getSource(name: string): LoaderSource;
|
163 | }
|
164 |
|
165 | export interface WebLoaderOptions {
|
166 | useCache?: boolean;
|
167 | async?: boolean;
|
168 | }
|
169 |
|
170 | export class WebLoader extends Loader {
|
171 | constructor(baseUrl?: string, opts?: WebLoaderOptions);
|
172 | async: boolean;
|
173 |
|
174 | getSource: (name: string, callback: Callback<Error, LoaderSource>) => LoaderSource;
|
175 | }
|
176 |
|
177 | export class PrecompiledLoader extends Loader implements ILoader {
|
178 | constructor(compiledTemplates?: any[]);
|
179 | getSource(name: string): LoaderSource;
|
180 | }
|
181 |
|
182 | export namespace runtime {
|
183 | class SafeString {
|
184 | constructor(val: string);
|
185 | val: string;
|
186 | length: number;
|
187 | valueOf(): string;
|
188 | toString(): string;
|
189 | }
|
190 | }
|
191 |
|
192 | export namespace lib {
|
193 | class TemplateError extends Error {
|
194 | constructor(message: string, lineno: number, colno: number);
|
195 |
|
196 | name: string; // always 'Template render error'
|
197 | message: string;
|
198 | stack: string;
|
199 |
|
200 | cause?: Error | undefined;
|
201 | lineno: number;
|
202 | colno: number;
|
203 | }
|
204 | }
|