miki-template 2.2.3 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/docs.yml +3 -1
- package/.github/workflows/release.yml +0 -5
- package/benchmarks/ejs-results.json +6 -6
- package/benchmarks/ejs.js +5 -3
- package/benchmarks/handlebars-results.json +6 -6
- package/benchmarks/handlebars.js +5 -8
- package/benchmarks/miki-results.json +6 -6
- package/benchmarks/miki.js +6 -3
- package/benchmarks/pug-results.json +6 -6
- package/benchmarks/pug.js +5 -3
- package/docs/api/async-render.md +88 -3
- package/docs/api/cache.md +90 -3
- package/docs/api/compile.md +131 -3
- package/docs/api/context-processors.md +80 -3
- package/docs/api/filters.md +223 -3
- package/docs/api/finder.md +97 -3
- package/docs/api/helpers.md +56 -3
- package/docs/api/i18n.md +160 -3
- package/docs/api/index.md +82 -28
- package/docs/api/libraries.md +210 -3
- package/docs/api/render-partial.md +84 -3
- package/docs/api/render.md +95 -3
- package/docs/api/security.md +148 -3
- package/docs/api/setup-express.md +78 -2
- package/docs/api/tags.md +138 -4
- package/docs/filter.md +0 -0
- package/docs/guide/advanced-usage.md +403 -6
- package/docs/guide/async-rendering.md +312 -4
- package/docs/guide/context-processors.md +261 -4
- package/docs/guide/custom-filters.md +315 -4
- package/docs/guide/custom-tags.md +275 -4
- package/docs/guide/filters.md +675 -3
- package/docs/guide/getting-started.md +109 -7
- package/docs/guide/installation.md +99 -4
- package/docs/guide/partial-templates.md +371 -4
- package/docs/guide/quick-start.md +228 -6
- package/docs/guide/security.md +348 -3
- package/docs/guide/tags.md +789 -6
- package/docs/guide/template-discovery.md +174 -4
- package/docs/guide/template-inheritance.md +277 -4
- package/docs/index.md +24 -42
- package/docs/integrations/elysia.md +4 -2
- package/docs/integrations/express.md +219 -219
- package/docs/integrations/fastify.md +4 -2
- package/docs/integrations/hono.md +4 -2
- package/docs/integrations/index.md +68 -68
- package/docs/integrations/koa.md +4 -2
- package/docs/integrations/nestjs.md +4 -2
- package/docs/integrations/tsed.md +4 -2
- package/docs/performance.md +45 -8
- package/ex.mjs +1 -1
- package/mkdocs.yml +0 -22
- package/overrides/main.html +1 -1
- package/package.json +1 -1
- package/requirements-docs.txt +2 -1
- package/src/codegen.js +905 -0
- package/src/context.js +42 -30
- package/src/filters.js +16 -0
- package/src/index.js +66 -61
- package/src/tags/control.js +15 -12
- package/src/utils.js +60 -0
- package/tests/filters.test.js +9 -0
- package/docs/javascripts/extra.js +0 -174
- package/docs/stylesheets/extra.css +0 -819
- package/overrides/partials/footer.html +0 -9
package/docs/api/tags.md
CHANGED
|
@@ -1,134 +1,268 @@
|
|
|
1
|
-
# Tags API
|
|
1
|
+
# Tags API
|
|
2
|
+
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
## registerTag
|
|
4
6
|
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
Register a custom tag callable from templates as `{% tag_name content %}...{% endtag_name %}`.
|
|
6
10
|
|
|
11
|
+
|
|
12
|
+
|
|
7
13
|
=== "CommonJS"
|
|
8
14
|
|
|
15
|
+
|
|
16
|
+
|
|
9
17
|
```javascript
|
|
18
|
+
|
|
10
19
|
const { registerTag } = require('miki-template');
|
|
11
20
|
|
|
21
|
+
|
|
22
|
+
|
|
12
23
|
registerTag('hello', (tagContent, parser) => {
|
|
24
|
+
|
|
13
25
|
return {
|
|
26
|
+
|
|
14
27
|
render: (context) => 'Hello World!'
|
|
28
|
+
|
|
15
29
|
};
|
|
30
|
+
|
|
16
31
|
});
|
|
32
|
+
|
|
17
33
|
```
|
|
18
34
|
|
|
35
|
+
|
|
36
|
+
|
|
19
37
|
=== "ES Modules"
|
|
20
38
|
|
|
39
|
+
|
|
40
|
+
|
|
21
41
|
```javascript
|
|
42
|
+
|
|
22
43
|
import { registerTag } from 'miki-template';
|
|
23
44
|
|
|
45
|
+
|
|
46
|
+
|
|
24
47
|
registerTag('hello', (tagContent, parser) => {
|
|
48
|
+
|
|
25
49
|
return {
|
|
50
|
+
|
|
26
51
|
render: (context) => 'Hello World!'
|
|
52
|
+
|
|
27
53
|
};
|
|
54
|
+
|
|
28
55
|
});
|
|
56
|
+
|
|
29
57
|
```
|
|
30
58
|
|
|
59
|
+
|
|
60
|
+
|
|
31
61
|
### Tag Parser Signature
|
|
32
62
|
|
|
63
|
+
|
|
64
|
+
|
|
33
65
|
- `tagContent` — The full text after the tag name, as a string.
|
|
66
|
+
|
|
34
67
|
- `parser` — The Parser instance, providing `parser.parse()`, `parser.peek()`, `parser.skipTag()`.
|
|
35
68
|
|
|
69
|
+
|
|
70
|
+
|
|
36
71
|
Returns a **Node** object with a `render(context)` method. The render method receives the `Context` object and returns a string.
|
|
37
72
|
|
|
73
|
+
|
|
74
|
+
|
|
38
75
|
## Built-in Tags
|
|
39
76
|
|
|
77
|
+
|
|
78
|
+
|
|
40
79
|
### Control Flow
|
|
41
80
|
|
|
81
|
+
|
|
82
|
+
|
|
42
83
|
| Tag | Description |
|
|
84
|
+
|
|
43
85
|
|-----|-------------|
|
|
86
|
+
|
|
44
87
|
| `if / elif / else / endif` | Conditional blocks |
|
|
88
|
+
|
|
45
89
|
| `for / empty / endfor` | Loop over arrays/objects |
|
|
90
|
+
|
|
46
91
|
| `with / endwith` | Create a scoped context |
|
|
92
|
+
|
|
47
93
|
| `cycle` | Cycle through values |
|
|
94
|
+
|
|
48
95
|
| `firstof` | Output first non-empty value |
|
|
96
|
+
|
|
49
97
|
| `ifchanged / endifchanged` | Only output if value changed |
|
|
50
98
|
|
|
99
|
+
|
|
100
|
+
|
|
51
101
|
### Variable Assignment
|
|
52
102
|
|
|
103
|
+
|
|
104
|
+
|
|
53
105
|
| Tag | Description |
|
|
106
|
+
|
|
54
107
|
|-----|-------------|
|
|
108
|
+
|
|
55
109
|
| `set var = expr` | Inline variable assignment |
|
|
110
|
+
|
|
56
111
|
| `set var %}...{% endset` | Capture block output into a variable |
|
|
57
112
|
|
|
113
|
+
|
|
114
|
+
|
|
58
115
|
### Date and Time
|
|
59
116
|
|
|
117
|
+
|
|
118
|
+
|
|
60
119
|
| Tag | Description |
|
|
120
|
+
|
|
61
121
|
|-----|-------------|
|
|
122
|
+
|
|
62
123
|
| `now "Y-m-d H:i:s"` | Output current date/time |
|
|
63
124
|
|
|
125
|
+
|
|
126
|
+
|
|
64
127
|
### Utility
|
|
65
128
|
|
|
129
|
+
|
|
130
|
+
|
|
66
131
|
| Tag | Description |
|
|
132
|
+
|
|
67
133
|
|-----|-------------|
|
|
134
|
+
|
|
68
135
|
| `static "path"` | Resolve static asset path |
|
|
136
|
+
|
|
69
137
|
| `url 'route.name' arg1 arg2` | Generate URL by route name |
|
|
138
|
+
|
|
70
139
|
| `regroup list by attr as name` | Regroup a list by an attribute |
|
|
140
|
+
|
|
71
141
|
| `spaceless / endspaceless` | Remove whitespace between HTML tags |
|
|
142
|
+
|
|
72
143
|
| `widthratio value max max_width` | Calculate CSS width ratio |
|
|
144
|
+
|
|
73
145
|
| `debug` | Output debugging context information |
|
|
74
146
|
|
|
147
|
+
|
|
148
|
+
|
|
75
149
|
### Security
|
|
76
150
|
|
|
151
|
+
|
|
152
|
+
|
|
77
153
|
| Tag | Description |
|
|
154
|
+
|
|
78
155
|
|-----|-------------|
|
|
156
|
+
|
|
79
157
|
| `csrf_token` | Output CSRF hidden input |
|
|
158
|
+
|
|
80
159
|
| `csp_nonce_attr` | Output `nonce` attribute for CSP |
|
|
81
160
|
|
|
161
|
+
|
|
162
|
+
|
|
82
163
|
### Comments and Raw Output
|
|
83
164
|
|
|
165
|
+
|
|
166
|
+
|
|
84
167
|
| Tag | Description |
|
|
168
|
+
|
|
85
169
|
|-----|-------------|
|
|
170
|
+
|
|
86
171
|
| `comment / endcomment` | Comment out content |
|
|
172
|
+
|
|
87
173
|
| `verbatim / endverbatim` | Disable tag parsing within |
|
|
88
174
|
|
|
175
|
+
|
|
176
|
+
|
|
89
177
|
### Autoescape
|
|
90
178
|
|
|
179
|
+
|
|
180
|
+
|
|
91
181
|
| Tag | Description |
|
|
182
|
+
|
|
92
183
|
|-----|-------------|
|
|
184
|
+
|
|
93
185
|
| `autoescape on / off / endautoescape` | Toggle HTML escaping |
|
|
94
186
|
|
|
187
|
+
|
|
188
|
+
|
|
95
189
|
### Library Loading
|
|
96
190
|
|
|
191
|
+
|
|
192
|
+
|
|
97
193
|
| Tag | Description |
|
|
194
|
+
|
|
98
195
|
|-----|-------------|
|
|
196
|
+
|
|
99
197
|
| `load library_name` | Load a registered library |
|
|
100
198
|
|
|
199
|
+
|
|
200
|
+
|
|
101
201
|
### Template Tags
|
|
102
202
|
|
|
203
|
+
|
|
204
|
+
|
|
103
205
|
| Tag | Description |
|
|
206
|
+
|
|
104
207
|
|-----|-------------|
|
|
208
|
+
|
|
105
209
|
| `templatetag token` | Output a template syntax character (e.g. `{% templatetag openpercentblock %}`) |
|
|
106
210
|
|
|
211
|
+
|
|
212
|
+
|
|
107
213
|
### Inheritance
|
|
108
214
|
|
|
215
|
+
|
|
216
|
+
|
|
109
217
|
| Tag | Description |
|
|
218
|
+
|
|
110
219
|
|-----|-------------|
|
|
220
|
+
|
|
111
221
|
| `extends "parent.html"` | Inherit from a parent template |
|
|
222
|
+
|
|
112
223
|
| `block name / endblock` | Define/overriding inheritable block |
|
|
224
|
+
|
|
113
225
|
| `include "file.html"` | Include another template |
|
|
114
226
|
|
|
227
|
+
|
|
228
|
+
|
|
115
229
|
### Partials
|
|
116
230
|
|
|
231
|
+
|
|
232
|
+
|
|
117
233
|
| Tag | Description |
|
|
234
|
+
|
|
118
235
|
|-----|-------------|
|
|
236
|
+
|
|
119
237
|
| `partialdef name / endpartialdef` | Define a named partial |
|
|
238
|
+
|
|
120
239
|
| `partial name with k=v` | Render a defined partial |
|
|
121
240
|
|
|
241
|
+
|
|
242
|
+
|
|
122
243
|
### i18n
|
|
123
244
|
|
|
245
|
+
|
|
246
|
+
|
|
124
247
|
| Tag | Description |
|
|
248
|
+
|
|
125
249
|
|-----|-------------|
|
|
250
|
+
|
|
126
251
|
| `trans "key"` | Translate a string |
|
|
252
|
+
|
|
127
253
|
| `blocktrans / endblocktrans` | Translate with variables |
|
|
254
|
+
|
|
128
255
|
| `language "xx" / endlanguage` | Switch language for a block |
|
|
129
256
|
|
|
257
|
+
|
|
258
|
+
|
|
130
259
|
## Next Steps
|
|
131
260
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
- [
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
- [Tags Guide](../guide/tags.md)
|
|
264
|
+
|
|
265
|
+
- [Custom Tags](../guide/custom-tags.md)
|
|
266
|
+
|
|
267
|
+
- [API Reference](../index.md)
|
|
268
|
+
|
package/docs/filter.md
ADDED
|
File without changes
|