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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
-- SPDX-License-Identifier: MIT
---@meta minijinja
local minijinja =
--- Minijinja types
---
---@alias minijinja.Types
---| "environment"
---| "state"
---| "none"
--- Determines how undefined values are handled.
---
--- Can be provided to [`Environment.undefined_behavior`](minijinja.Environment.undefined_behavior).
---
---@alias minijinja.UndefinedBehavior
--- printing: empty string
--- iteration: empty array
--- attributes: fails
--- test: falsey
---| "lenient"
--- printing: empty string
--- iteration: empty array
--- attributes: undefined
--- test: falsey
---| "chainable"
--- printing: fails
--- iteration: fails
--- attributes: fails
--- test: falsey
---| "semi-strict"
--- printing: fails
--- iteration: fails
--- attributes: fails
--- test: fails
---| "strict"
--- Determines how autoescaping is applied.
---
---@alias minijinja.AutoEscape
---| "html"
---| "json"
---| "none"
--- A minijinja callback.
---
--- It takes a [`State`](minijinja.State) as the first paramter followed by any number of args.
---
---@alias minijinja.Callback fun(state: minijinja.State, ...): any
--- A stateless minijinja callback.
---
--- Similar to a [`Callback`](minijinja.Callback), but it is not passed a [`State`](minijinja.State).
---
---@alias minijinja.CallbackStateless fun(...): any
--- A minijinja global variable.
---
--- This type can be provided to [`Environment:add_global()`](minijinja.Environment.add_global)
---
---@alias minijinja.Global any|minijinja.Callback|minijinja.CallbackStateless
--- A minijinja filter function.
---
--- This type of function can be provided to [`Environment:add_filter()`](minijinja.Environment.add_filter)
---
---@alias minijinja.Filter minijinja.Callback|minijinja.CallbackStateless
--- A minijinja test function.
---
--- This type of function can be provided to [`Environment:add_test()`](minijinja.Environment.add_test)
---
---@alias minijinja.Test minijinja.Callback|minijinja.CallbackStateless
--- A template loader callback.
---
--- It takes the name of a template and returns the source or `nil` if no template could be found.
---
--- This type of function can be provided to [`Environment:set_loader()`](minijinja.Environment.set_loader) to load templates from a filesystem.
---
---@alias minijinja.LoaderCallback fun(name: string): string|nil
--- A path join callback
---
--- It takes the name of a template and the parent path and returns a new derived path.
---
--- This type of function can be provided to [`Environment:set_path_join_callback()`](minijinja.Environment.set_path_join_callback) to implement relative path resolution between templates.
---
---@alias minijinja.PathJoinCallback fun(name: string, parent: string): string
--- A callback invoked for unknown methods on objects.
---
--- It takes a [`State`](minijinja.State), the object which the method was called on, the name of the method, and any arguments passed and returns any value.
---
--- This type of function can be provided to [`Environment:set_unknown_method_callback()`](minijinja.Environment.set_unknown_method_callback) to implement compatibility with python methods.
---
---@alias minijinja.UnknownMethodCallback fun(state: minijinja.State, value: any, method: string, args: any[]): any
--- A callback to select the default auto escaping.
---
--- It takes the name of a template and returns an [`AutoEscape`](minijinja.AutoEscape) variant.
---
--- This type of function can be provided to [`Environment:set_auto_escape_callback()`](minijinja.Environment.set_auto_escape_callback).
---
---@alias minijinja.AutoEscapeCallback fun(name: string): minijinja.AutoEscape
--- A callback to control how values are formatted.
---
--- It takes a [`State`](minijinja.State) and a value to be formatted, and it returns the formatted value as a string.
---
--- This type of function can be provided to [`Environment:set_formatter()`](minijinja.Environment.set_formatter).
---
---@alias minijinja.FormatterCallback fun(state: minijinja.State, value: any): string
--- This value can be used in place of `nil` to indicate intentionally null values.
---
--- It maps to the `minijinja` `None` value.
---
---@alias minijinja.None userdata
--- Configure the syntax for the environment.
---
---@class (exact) minijinja.SyntaxConfig
---
---@field block_delimiters? [string, string] Start and end delimiters
---@field variable_delimiters? [string, string] Start and end delimiters
---@field comment_delimiters? [string, string] Start and end delimiters
---@field line_statement_prefix? string
---@field line_comment_prefix? string
--- A minijinja environment.
---
---@class (exact) minijinja.Environment: userdata
---
---@field reload_before_render boolean Reload templates before each render.
---@field keep_trailing_newline boolean Preserve trailing newlines at the end of templates.
---@field trim_blocks boolean Remove the first newline after a block.
---@field lstrip_blocks boolean Remove leading spaces and tabs from the start of a line to a block.
---@field debug boolean Enable debug behavior.
---@field fuel number|nil Sets the fuel of the engine. If `nil`, fuel usage is disabled.
---@field recursion_limit number Reconfigures the runtime recursion limit. Default is 500.
---@field undefined_behavior minijinja.UndefinedBehavior Changes the undefined behavior. Default is [`lenient`](minijinja.UndefinedBehavior.lenient).
minijinja. =
--- Create a new environment.
---
---@return minijinja.Environment
--- Create an empty environment.
---
--- This environment has no default filters, tests, or globals.
---
---@return minijinja.Environment
--- Add a template.
---
---@param name string The name of the template.
---@param source string The template source contents.
--- Remove a template.
---
---@param name string The name of the template.
--- Remove all templates.
--- Return a table of all undeclared variables in a template.
---
---@param name string The name of the template.
---@param nested? boolean If `true`, nested trivial attribute lookups are also returned.
---
---@return table
--- Sets a callback to load template sources.
---
---@param callback minijinja.LoaderCallback
--- Sets a callback to join template paths.
---
---@param callback minijinja.PathJoinCallback
--- Sets a callback invoked for unknown methods on objects.
---
---@param callback minijinja.UnknownMethodCallback
--- Sets a callback to select the default auto escaping behavior.
---
---@param callback minijinja.AutoEscapeCallback
--- Sets a callback to control how values are formatted.
---
---@param callback minijinja.FormatterCallback
--- Sets the syntax for the environment.
---
---@param syntax minijinja.SyntaxConfig
--- Render a template.
---
---@param name string The name of the template to render.
---@param ctx? table The template context.
---
---@return string # The rendered template.
--- Render a string directly.
---
---@param source string The template source.
---@param ctx? table The template context.
---@param name? string The name of the template. Defaults to `<string>`.
---
---@return string # The rendered template.
--- Evaluate an expression.
---
---@param source string The expression source
---@param ctx? table The expression context.
---
---@return any # The result of the expression
--- Add a filter.
---
---@param name string The name of the filter.
---@param filter minijinja.Filter The filter.
---@param pass_state? boolean Whether to pass a [`State`](minijinja.State) as the first argument.
--- Remove a filter.
---
---@param name string The name of the filter.
--- Add a test.
---
---@param name string The name of the test.
---@param test minijinja.Test The test.
---@param pass_state? boolean Whether to pass a [`State`](minijinja.State) as the first argument.
--- Remove a test.
---
---@param name string The name of the test.
--- Add a global variable.
---
---@param name string The name of the variable.
---@param global minijinja.Global The variable.
---@param pass_state? boolean Whether to pass a [`State`](minijinja.State) as the first argument to function variables.
--- Remove a global variable.
---
---@param name string The name of the variable.
--- Get a list of all global variables.
---
---@return any[]
--- A minijinja state.
---
--- Only accesible within filters, tests, and global functions.
---
---@class (exact) minijinja.State: userdata
minijinja. =
--- Get the name of the current template.
---
---@return string # The template name.
--- Get the current value of the auto escape flag.
---
---@return minijinja.AutoEscape # The current auto escape flag.
--- Get the current undefined behavior.
---
---@return minijinja.UndefinedBehavior # The current undefined behavior.
--- Get the name of the innermost block.
---
---@return string # The name of the innermost block.
--- Look up a variable in the render context by name.
---
---@param name string The name of the variable.
---
---@return any # The variable associated with `name`.
--- Call a macro.
---
---@param name string The name of the macro.
---@param ... any Arguments to pass to the macro.
---
---@return string # The macro output.
--- Get a list of names for all exports (top-level variables).
---
---@return string[]
--- Get a list of all known variables.
---
---@return string[]
--- Invokes a filter with some arguments.
---
---@param filter string The name of the filter.
---@param ... any Arguments to pass to the filter.
---
---@return any # The output of the filter.
--- Invokes a test function on a value.
---
---@param test string The name of the test.
---@param ... any Arguments to pass to the test.
---
---@return boolean # The output of the test.
--- Format a value to a string using the formatter configured for the environment.
---
---@param value any The value to format.
---
---@return string # The formatted value.
--- Get the consumed and remaining fuel levels.
---
---@return [number, number] # The [consumed, remaining] fuel levels.
--- Look up a temp variable.
---
---@param name string The name of the variable.
---
---@return any # The variable associated with `name`.
--- Set a temp variable and return the old value.
---
---@param name string The name of the variable.
---@param temp any The temp variable.
---
---@return any # The old temp variable value.
--- Get a temp variable or add the variable returned by `func`.
---
---@param name string The name of the variable.
---@param func fun(): any The function to call if the temp is not set.
---
---@return any # The variable associated with `name`, or the variable returnd by `func`.
--- Get the type of `value`
---
--- This function returns the strings
--- - `'environment'` for [`Environment`](minijinja.Environment)
--- - `'state'` for [`State`](minijinja.State)
--- - `'none'` for [`None`](minijinja.None)
--- - or the values returned by the builtin `type()` function.
---
---@param value any
---
---@return minijinja.Types|string
--- Get a callback to load templates from the provided directory paths.
---
--- The function returned by this one can be passed to [`Environment:set_loader()`](minijinja.Environment.set_loader) to load templates from the filesystem.
---
---@param paths string|string[]
---
---@return minijinja.LoaderCallback
return minijinja