miki-template 2.2.2 → 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.
Files changed (66) hide show
  1. package/.github/workflows/docs.yml +3 -1
  2. package/.github/workflows/release.yml +1 -0
  3. package/benchmarks/ejs-results.json +6 -6
  4. package/benchmarks/ejs.js +5 -3
  5. package/benchmarks/handlebars-results.json +6 -6
  6. package/benchmarks/handlebars.js +5 -8
  7. package/benchmarks/miki-results.json +6 -6
  8. package/benchmarks/miki.js +6 -3
  9. package/benchmarks/pug-results.json +6 -6
  10. package/benchmarks/pug.js +5 -3
  11. package/docs/api/async-render.md +88 -3
  12. package/docs/api/cache.md +90 -3
  13. package/docs/api/compile.md +131 -3
  14. package/docs/api/context-processors.md +80 -3
  15. package/docs/api/filters.md +223 -3
  16. package/docs/api/finder.md +97 -3
  17. package/docs/api/helpers.md +56 -3
  18. package/docs/api/i18n.md +160 -3
  19. package/docs/api/index.md +82 -28
  20. package/docs/api/libraries.md +210 -3
  21. package/docs/api/render-partial.md +84 -3
  22. package/docs/api/render.md +95 -3
  23. package/docs/api/security.md +148 -3
  24. package/docs/api/setup-express.md +78 -2
  25. package/docs/api/tags.md +138 -4
  26. package/docs/filter.md +0 -0
  27. package/docs/guide/advanced-usage.md +403 -6
  28. package/docs/guide/async-rendering.md +312 -4
  29. package/docs/guide/context-processors.md +261 -4
  30. package/docs/guide/custom-filters.md +315 -4
  31. package/docs/guide/custom-tags.md +275 -4
  32. package/docs/guide/filters.md +675 -3
  33. package/docs/guide/getting-started.md +109 -7
  34. package/docs/guide/installation.md +99 -4
  35. package/docs/guide/partial-templates.md +371 -4
  36. package/docs/guide/quick-start.md +228 -6
  37. package/docs/guide/security.md +348 -3
  38. package/docs/guide/tags.md +789 -6
  39. package/docs/guide/template-discovery.md +174 -4
  40. package/docs/guide/template-inheritance.md +277 -4
  41. package/docs/index.md +24 -42
  42. package/docs/integrations/elysia.md +4 -2
  43. package/docs/integrations/express.md +219 -219
  44. package/docs/integrations/fastify.md +4 -2
  45. package/docs/integrations/hono.md +4 -2
  46. package/docs/integrations/index.md +68 -68
  47. package/docs/integrations/koa.md +4 -2
  48. package/docs/integrations/nestjs.md +4 -2
  49. package/docs/integrations/tsed.md +4 -2
  50. package/docs/performance.md +45 -8
  51. package/ex.mjs +1 -1
  52. package/mkdocs.yml +0 -22
  53. package/overrides/main.html +1 -1
  54. package/package.json +1 -1
  55. package/requirements-docs.txt +2 -1
  56. package/src/codegen.js +905 -0
  57. package/src/context.js +42 -30
  58. package/src/filters.js +16 -0
  59. package/src/index.js +66 -61
  60. package/src/tags/control.js +15 -12
  61. package/src/utils.js +60 -0
  62. package/tests/filters.test.js +9 -0
  63. package/.github/workflows/npm-publish-github-packages.yml +0 -36
  64. package/docs/javascripts/extra.js +0 -174
  65. package/docs/stylesheets/extra.css +0 -819
  66. 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
- - [Tags Guide](../guide/tags)
133
- - [Custom Tags](../guide/custom-tags)
134
- - [API Reference](../)
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