1
- [ Aspect] ( ./../readme.md ) › API Documentation
2
- ============================================
1
+ ---
2
+ layout : page
3
+ title : API Documentation
4
+ ---
3
5
4
6
<!-- {% raw %} -->
5
7
6
8
This chapter describes the API to Aspect and not the template language.
7
9
It will be most useful as reference to those implementing the template interface to the application
8
10
and not those who are creating Aspect templates.
9
11
10
- Table Of Content
11
- ----------------
12
-
13
- - [ Basic API Usage] ( #basic-api-usage )
14
- - [ Rendering Templates] ( #rendering-templates )
15
- - [ Options] ( #options )
16
- - [ Cache] ( #cache )
17
- - [ Loaders] ( #loaders )
18
- - [ Extending] ( #extending )
19
- - [ Add tags] ( #add-tags )
20
- - [ Add filters] ( #add-filters )
21
- - [ Add functions] ( #add-functions )
22
- - [ Add operators] ( #add-operators )
23
- - [ Behaviors] ( #behaviors )
24
- - [ Condition behaviour] ( #condition-behaviour )
25
- - [ Empty string behaviour] ( #empty-string-behaviour )
26
- - [ Number behaviour] ( #number-behaviour )
27
- - [ Custom escaper] ( #custom-escaper )
28
- - [ Date processing] ( #date-processing )
29
- - [ Iterator and countable objects] ( #iterator-and-countable-objects )
30
-
31
12
Basic API Usage
32
13
--------------
33
14
@@ -58,8 +39,6 @@ aspect:display("dashboard.tpl", {
58
39
})
59
40
```
60
41
61
- [ Back to TOC] ( #table-of-content )
62
-
63
42
## Render result
64
43
65
44
``` lua
@@ -76,8 +55,6 @@ local output, err = aspect:display(template, vars)
76
55
```
77
56
- ` err ` is ` aspect.error ` object and contains error information. ` nil ` if no errors.
78
57
79
- [ Back to TOC] ( #table-of-content )
80
-
81
58
Rendering Templates
82
59
-------------------
83
60
@@ -111,8 +88,6 @@ Rendering Templates
111
88
** Note** . ` render ` functions and ` display ` functions returns ` aspect.output ` object with template result
112
89
(if result not displayed) and more useful information
113
90
114
- [ Back to TOC] ( #table-of-content )
115
-
116
91
Options
117
92
-------
118
93
@@ -142,8 +117,6 @@ The following options are available:
142
117
* ` autoescape ` _ boolean_
143
118
Enables or disables auto-escaping with 'html' strategy.
144
119
145
- [ Back to TOC] ( #table-of-content )
146
-
147
120
Cache
148
121
-----
149
122
@@ -198,8 +171,6 @@ local template = aspect.new({
198
171
})
199
172
```
200
173
201
- [ Back to TOC] ( #table-of-content )
202
-
203
174
Loaders
204
175
-------
205
176
@@ -219,8 +190,6 @@ aspect:display("pages/about.html", vars)
219
190
220
191
loads ` /var/project/templates/pages/about.html ` template.
221
192
222
- [ Back to TOC] ( #table-of-content )
223
-
224
193
### Resty loader
225
194
226
195
``` lua
@@ -235,8 +204,6 @@ aspect:display("pages/about.html", vars)
235
204
236
205
loads ` /.templates/pages/about.html ` template (via [ ngx.location.capture] ( https://github.com/openresty/lua-nginx-module#ngxlocationcapture ) ).
237
206
238
- [ Back to TOC] ( #table-of-content )
239
-
240
207
### Array loader
241
208
242
209
``` lua
@@ -248,8 +215,6 @@ tpls["theme.tpl"] = [[<html> ... template ... </html>]]
248
215
aspect .loader = tpls
249
216
```
250
217
251
- [ Back to TOC] ( #table-of-content )
252
-
253
218
Extending
254
219
---------
255
220
295
260
296
261
See [ aspect.tags] ( ../src/aspect/tags.lua ) for more examples.
297
262
298
- [ Back to TOC] ( #table-of-content )
299
-
300
263
## Add filters
301
264
302
265
``` lua
317
280
318
281
See [ aspect.filters] ( ../src/aspect/filters.lua ) for more examples.
319
282
320
- [ Back to TOC] ( #table-of-content )
321
-
322
283
## Add functions
323
284
324
285
Add function ` {{ foo(arg1=x, arg2=y) }} ` :
346
307
347
308
See [ aspect.funcs] ( ../src/aspect/funcs.lua ) for more examples.
348
309
349
- [ Back to TOC] ( #table-of-content )
350
-
351
310
## Add tests
352
311
353
312
Add tests ` foo ` , ` bar ` and ` baz `
@@ -378,8 +337,6 @@ Result:
378
337
379
338
See [ aspect.tests] ( ../src/aspect/tests.lua ) for more examples.
380
339
381
- [ Back to TOC] ( #table-of-content )
382
-
383
340
## Add operators
384
341
385
342
For example add bitwise operator ` & ` (using [ bitop] ( http://bitop.luajit.org/ ) package):
@@ -406,8 +363,6 @@ table.insert(ops, {
406
363
407
364
See [ aspect.ast.ops] ( ../src/aspect/ast/ops.lua ) for more examples.
408
365
409
- [ Back to TOC] ( #table-of-content )
410
-
411
366
## Behaviors
412
367
413
368
### Condition behaviour
@@ -456,8 +411,6 @@ is_false['0'] = true
456
411
457
412
Now example output ` Unacceptable condition! ` because ` zero ` will be casted to false.
458
413
459
- [ Back to TOC] ( #table-of-content )
460
-
461
414
### Empty string behaviour
462
415
463
416
Configure ` aspect.config.is_empty_string ` table. Indicate which values are empty string or values with specific metatable.
@@ -468,8 +421,6 @@ is_empty_string[ngx.null] = true
468
421
is_empty_string [getmetatable (cbson .null ())] = true
469
422
```
470
423
471
- [ Back to TOC] ( #table-of-content )
472
-
473
424
### Number behaviour
474
425
475
426
Configure ` aspect.config.is_n ` table. Indicate which objects can behave like numbers.
@@ -479,8 +430,6 @@ local is_n = require("aspect.config").is_n
479
430
is_n [getmetatable (cbson .number (0 ))] = 0
480
431
```
481
432
482
- [ Back to TOC] ( #table-of-content )
483
-
484
433
## Custom escaper
485
434
486
435
Add custom escaper via config, using escaper name:
495
444
{{ data.raw|e("csv") }}
496
445
```
497
446
498
- [ Back to TOC] ( #table-of-content )
499
-
500
447
## Date processing
501
448
502
449
### strtotime
@@ -508,8 +455,6 @@ local strtotime = require("aspect.utils.date").strtotime
508
455
local ts , info = strtotime (" 2009-02-13 23:31:30" )
509
456
```
510
457
511
- [ Back to TOC] ( #table-of-content )
512
-
513
458
### Date localization
514
459
515
460
Add or change month localizations. For example add localized months for russian and spain languages.
@@ -524,8 +469,6 @@ months["diciembre"] = 12 -- add long name of december on spain
524
469
```
525
470
There 1 - january, 12 - december.
526
471
527
- [ Back to TOC] ( #table-of-content )
528
-
529
472
### Date parser
530
473
531
474
Add or change date parsers. For example add parser for date like ` 2009Y02M13D23h31m30s+0230z ` (it is ` 2009-02-13 23:31:30 UTC+02:30 ` )
@@ -570,8 +513,6 @@ How parsers work:
570
513
571
514
See ` date.parsers ` for more information.
572
515
573
- [ Back to TOC] ( #table-of-content )
574
-
575
516
Iterator and countable objects
576
517
-------------------------------
577
518
@@ -583,6 +524,4 @@ For example see [range iterator](../src/aspect/utils/range.lua).
583
524
As in Lua 5.2+, the Aspect allows to determine the length of objects through the ` __len() ` function.
584
525
Works for all lua/luajit versions.
585
526
586
- [ Back to TOC] ( #table-of-content )
587
-
588
527
<!-- {% endraw %} -->
0 commit comments