forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swig.d.ts
158 lines (147 loc) · 6.21 KB
/
swig.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
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
// Type definitions for swig
// Project: http://github.com/paularmstrong/swig
// Definitions by: Peter Harris <https://github.com/CodeAnimal>, Carlos Ballesteros Velasco <https://github.com/soywiz>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// API Documentation : http://paularmstrong.github.io/swig/docs/api/
declare module "swig" {
export class Swig {
constructor(options?: SwigOptions);
setFilter(
name: string,
method: (input: any, ...args: any[]) => string
): void;
setTag(
name: string,
parse: (str?: string, line?: string, parser?: Object, types?: lexer.TYPES, stack?: any, opts?: Object, swig?: Swig) => boolean,
compile: (compiler?: (content?: string, parents?: any, options?: any, blockName?: string) => string, args?: any[], content?: string, parents?: any, options?: any, blockName?: string) => string,
ends?: boolean,
blockLevel?: boolean
): void;
setExtension(name: string, object: any): void;
parseFile(pathName: string, options?: any): parser.ParseReturn;
precompile(source: string, options?: SwigOptions): any;
compile(source: string, options?: SwigOptions): (locals?: any) => string;
compileFile(pathname: string, options: SwigOptions, cb: (err: Error, compiledRender: (locals?: any) => string) => void): void;
compileFile(pathname: string, options?: SwigOptions): (locals?: any) => string;
render(source: string, options?: SwigOptions): string;
renderFile(pathName: string, locals: any, cb: (err: Error, output: string) => void): void;
renderFile(pathName: string, locals?: any): string;
run(templateFn: Function, locals?: any, filePath?: string): string;
invalidateCache(): void;
loaders: typeof loaders;
}
export module lexer {
export enum TYPES {
/** Whitespace */
WHITESPACE = 0,
/** Plain string */
STRING = 1,
/** Variable filter */
FILTER = 2,
/** Empty variable filter */
FILTEREMPTY = 3,
/** Function */
FUNCTION = 4,
/** Function with no arguments */
FUNCTIONEMPTY = 5,
/** Open parenthesis */
PARENOPEN = 6,
/** Close parenthesis */
PARENCLOSE = 7,
/** Comma */
COMMA = 8,
/** Variable */
VAR = 9,
/** Number */
NUMBER = 10,
/** Math operator */
OPERATOR = 11,
/** Open square bracket */
BRACKETOPEN = 12,
/** Close square bracket */
BRACKETCLOSE = 13,
/** Key on an object using dot-notation */
DOTKEY = 14,
/** Start of an array */
ARRAYOPEN = 15,
/** End of an array
* Currently unused
ARRAYCLOSE = 16, */
/** Open curly brace */
CURLYOPEN = 17,
/** Close curly brace */
CURLYCLOSE = 18,
/** Colon (:) */
COLON = 19,
/** JavaScript-valid comparator */
COMPARATOR = 20,
/** Boolean logic */
LOGIC = 21,
/** Boolean logic "not" */
NOT = 22,
/** true or false */
BOOL = 23,
/** Variable assignment */
ASSIGNMENT = 24,
/** Start of a method */
METHODOPEN = 25,
/** End of a method
* Currently unused
METHODEND = 26, */
/** Unknown type */
UNKNOWN = 100
}
export function read(str: string): string[];
}
export module parser {
interface ParseReturn {
name: string;
parent: any;
tokens: any[];
blocks: any;
}
}
export interface SwigOptions {
autoescape?: boolean;
cache?: any;
cmtControls?: string[];
loader?: TemplateLoader;
locals?: any;
tagControls?: string[];
varControls?: string[];
}
export interface TemplateLoader {
resolve(to: string, from: string): string;
load(identifier: string, callback?: (err: Error, data: any) => void): void;
load(identifier:string): any;
}
export module loaders {
export function fs(basepath?: string, encoding?: string): TemplateLoader;
export function memory(mapping: any, basepath?: string): TemplateLoader;
}
export var version: string;
export function setDefaults(options: SwigOptions): void;
export function setDefaultTZOffset(offset: number): void;
export function setFilter(
name: string,
method: (input: any, ...args: any[]) => string
): void;
export function setTag(
name: string,
parse: (str?: string, line?: string, parser?: Object, types?: lexer.TYPES, stack?: any, opts?: Object, swig?: Swig) => boolean,
compile: (compiler?: (content?: string, parents?: any, options?: any, blockName?: string) => string, args?: any[], content?: string, parents?: any, options?: any, blockName?: string) => string,
ends?: boolean,
blockLevel?: boolean
): void;
export function setExtension(name: string, object: any): void;
export function parseFile(pathName: string, options?: any): parser.ParseReturn;
export function precompile(source: string, options?: SwigOptions): any;
export function compile(source: string, options?: SwigOptions): (locals?: any) => string;
export function compileFile(pathname: string, options: SwigOptions, cb: (err: Error, compiledRender: (locals?: any) => string) => void): void;
export function compileFile(pathname: string, options?: SwigOptions): (locals?: any) => string;
export function render(source: string, options?: SwigOptions): string;
export function renderFile(pathName: string, locals: any, cb: (err: Error, output: string) => void): void;
export function renderFile(pathName: string, locals?: any): string
export function run(templateFn: Function, locals?: any, filePath?: string): string;
export function invalidateCache(): void;
}