forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnunjucks.d.ts
133 lines (108 loc) · 4.93 KB
/
nunjucks.d.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
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
// Type definitions for nunjucks
// Project: http://mozilla.github.io/nunjucks/
// Definitions by: Ruben Slabbert <https://github.com/RubenSlabbert/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "nunjucks" {
namespace Nunjucks {
function render(name: string, context?: Object): string;
function render(name: string, context?: Object, callback?: (err: any, res: string) => any): void;
function renderString(src: string, context: Object): string;
function renderString(src: string, context: Object, callback?: (err: any, res: string) => any): void;
function compile(src: string, env?: Environment): Template;
function compile(src: string, env?: Environment, callback?: (err: any, res: Template) => any): Template;
function precompile(path: string, opts?: PrecompileOptions): string;
function precompileString(src: string, opts?: PrecompileOptions): string;
interface PrecompileOptions {
name?: string;
asFunction?: boolean;
force?: boolean;
env?: Environment;
include?: string[];
exclude?: string[];
wrapper?(templates: { name: string, template: string }, opts: PrecompileOptions): string;
}
class Template {
constructor(src: string, env?: Environment, eagerCompile?: boolean);
render(context?: Object): string;
render(context?: Object, callback?: (err: any, res: string) => any): void;
}
function configure(options: ConfigureOptions): Environment;
function configure(path: string, options?: ConfigureOptions): Environment;
interface ConfigureOptions {
autoescape?: boolean;
throwOnUndefined?: boolean;
trimBlocks?: boolean;
lstripBlocks?: boolean;
watch?: boolean;
noCache?: boolean;
web?: {
useCache?: boolean,
async?: boolean
};
express?: Object;
tags?: {
blockStart?: string,
blockEnd?: string,
variableStart?: string,
variableEnd?: string,
commentStart?: string,
commentEnd?: string
};
}
class Environment {
options: {
autoescape: boolean;
};
constructor(loader: ILoader, opts?: ConfigureOptions);
constructor(loaders: ILoader[], opts?: ConfigureOptions);
render(name: string, context?: Object): string;
render(name: string, context?: Object, callback?: (err: any, res: string) => any): void;
renderString(name: string, context: Object): string;
renderString(name: string, context: Object, callback?: (err: any, res: string) => any): void;
addFilter(name: string, func: (...args: any[]) => any, async?: boolean): void;
getFilter(name: string): void;
addExtension(name: string, ext: Extension): void;
removeExtension(name: string): void;
getExtension(name: string): Extension;
hasExtension(name: string): void;
addGlobal(name: string, value: any): void;
getTemplate(name: string, eagerCompile?: boolean): Template;
getTemplate(name: string, eagerCompile?: boolean, callback?: (err: any, templ: Template) => Template): void;
express(app: Object): void;
}
interface Extension {
tags: string[];
// Parser API is undocumented it is suggested to check the source: https://github.com/mozilla/nunjucks/blob/master/src/parser.js
parse(parser: any, nodes: any, lexer: any): any;
}
function installJinjaCompat(): void;
interface ILoader {
async?: boolean;
getSource(name: string): LoaderSource;
extend?(extender: ILoader): ILoader;
}
// Needs both Loader and ILoader since nunjucks uses a custom object system
// Object system is also responsible for the extend methods
class Loader {
on(name: string, func: (...args: any[]) => any): void;
emit(name: string, ...args: any[]): void;
resolve(from: string, to: string): string;
isRelative(filename: string): boolean;
extend(toExtend: ILoader): ILoader;
}
interface LoaderSource {
src: string;
path: string;
noCache: boolean;
}
class FileSystemLoader extends Loader implements ILoader {
init(searchPaths: string[], opts: any): void;
getSource(name: string): LoaderSource;
}
class PrecompiledLoader extends Loader implements ILoader {
init(searchPaths: string[], opts: any): void;
getSource(name: string): LoaderSource;
}
}
export = Nunjucks;
}