-
Notifications
You must be signed in to change notification settings - Fork 143
/
index.d.ts
59 lines (49 loc) · 2.03 KB
/
index.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
export interface Velocity {
parse(vmString: string, blocks?: { [blockName: string]: boolean }, ignoreSpace?: boolean): Array<VELOCITY_AST>
render(vmString: string, context?: RenderContext, macros?: Macros, config?: CompileConfig): string
Compile: Compile
Helper: Helper
}
interface Compile {
new (asts: Array<VELOCITY_AST>, config?: CompileConfig): Compile
render(context?: RenderContext, macros?: Macros, silence?: boolean): string
cost: number // render cost time
}
interface Helper {
getRefText(ast: VELOCITY_AST): string
}
type Macros = Object | { [macro: string]: Function }
type RenderContext = Object | {
[contextKey: string]: Function,
eval(vmString: string, context?: RenderContext): string
}
export type AST_TYPE = 'set' | 'elseif' | 'if' | 'else' | 'end' | 'foreach' | 'define' | 'content' | 'comment'
| 'macro' | 'macro_call' | 'math' | 'references' | 'method' | 'index' | 'property'
| 'bool' | 'interger' | 'decimal' | 'string' | 'array' | 'map'
export interface VELOCITY_AST {
type: AST_TYPE
value: any
id: string
pos: { first_line: number, first_column: number }
}
export interface CompileConfig {
escape?: boolean // escape variable
unescape?: { [varName: string]: boolean } // unescape var config
// @see https://github.com/shepherdwind/velocity.js/pull/105
valueMapper?: (value: any) => any
customMethodHandlers?: Array<{
// uid for method handler, use in debug log only
uid: string;
// the function to judge which method should be handler
// for example, we want handler the get method like Java
// $foo.get('bar')
// @see https://github.com/shepherdwind/velocity.js/pull/146/files#diff-87cd4af0a4775dde2b789b29008ff702828b17afc38d419ffc0772ce4272f5ffR68
match: (payload: { property: string; context: any; params: any[] }) => boolean;
// the function to handler custom logic
resolve: (payload: { property: string; context: any; params: any[] }) => any;
}>;
}
declare module 'velocityjs' {
var velocityjs: Velocity;
export = velocityjs
}