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.
Files changed (65) hide show
  1. package/.github/workflows/docs.yml +3 -1
  2. package/.github/workflows/release.yml +0 -5
  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/docs/javascripts/extra.js +0 -174
  64. package/docs/stylesheets/extra.css +0 -819
  65. package/overrides/partials/footer.html +0 -9
@@ -1,128 +1,256 @@
1
- # compile()
1
+ # compile()
2
+
3
+
2
4
 
3
5
  Compile a template string into a reusable renderable object.
4
6
 
7
+
8
+
5
9
  ## Signature
6
10
 
11
+
12
+
7
13
  ```javascript
14
+
8
15
  compile(templateStr, options = {})
16
+
9
17
  ```
10
18
 
19
+
20
+
11
21
  ## Parameters
12
22
 
23
+
24
+
13
25
  | Parameter | Type | Description |
26
+
14
27
  |-----------|------|-------------|
28
+
15
29
  | `templateStr` | `string` | Template source string |
30
+
16
31
  | `options` | `object` | Options including `views` directories |
17
32
 
33
+
34
+
18
35
  ## Returns
19
36
 
37
+
38
+
20
39
  An object with these render methods:
21
40
 
41
+
42
+
22
43
  | Method | Description |
44
+
23
45
  |--------|-------------|
46
+
24
47
  | `render(contextObj, callOptions)` | Synchronous render |
48
+
25
49
  | `renderWith(contextObj, callOptions)` | Render with options override |
50
+
26
51
  | `asyncRender(contextObj)` | Asynchronous render (supports async filters/tags) |
52
+
27
53
  | `asyncRenderWith(contextObj, callOptions)` | Async render with options override |
54
+
28
55
  | `renderBlock(blockName, contextObj)` | Render a single `{% block %}` |
56
+
29
57
  | `renderPartial(partialName, contextObj)` | Render a named `{% partialdef %}` |
30
58
 
59
+
60
+
31
61
  ## Examples
32
62
 
63
+
64
+
33
65
  ### Basic compile
34
66
 
67
+
68
+
35
69
  === "CommonJS"
36
70
 
71
+
72
+
37
73
  ```javascript
74
+
38
75
  const { compile } = require('miki-template');
39
76
 
77
+
78
+
40
79
  const compiled = compile('<h1>{{ title }}</h1>');
41
80
 
81
+
82
+
42
83
  const html = compiled.render({ title: 'Hello' });
84
+
43
85
  // Output: <h1>Hello</h1>
86
+
44
87
  ```
45
88
 
89
+
90
+
46
91
  === "ES Modules"
47
92
 
93
+
94
+
48
95
  ```javascript
96
+
49
97
  import { compile } from 'miki-template';
50
98
 
99
+
100
+
51
101
  const compiled = compile('<h1>{{ title }}</h1>');
52
102
 
103
+
104
+
53
105
  const html = compiled.render({ title: 'Hello' });
106
+
54
107
  // Output: <h1>Hello</h1>
108
+
55
109
  ```
56
110
 
111
+
112
+
57
113
  ### Render with options override
58
114
 
115
+
116
+
59
117
  === "CommonJS"
60
118
 
119
+
120
+
61
121
  ```javascript
122
+
62
123
  const { compile } = require('miki-template');
63
124
 
125
+
126
+
64
127
  const compiled = compile(template, { views: './templates' });
128
+
65
129
  const html = compiled.renderWith({ title: 'Hello' }, { views: './other-views' });
130
+
66
131
  ```
67
132
 
133
+
134
+
68
135
  === "ES Modules"
69
136
 
137
+
138
+
70
139
  ```javascript
140
+
71
141
  import { compile } from 'miki-template';
72
142
 
143
+
144
+
73
145
  const compiled = compile(template, { views: './templates' });
146
+
74
147
  const html = compiled.renderWith({ title: 'Hello' }, { views: './other-views' });
148
+
75
149
  ```
76
150
 
151
+
152
+
77
153
  ### Render a Block (template inheritance)
78
154
 
155
+
156
+
79
157
  === "CommonJS"
80
158
 
159
+
160
+
81
161
  ```javascript
162
+
82
163
  const { compile } = require('miki-template');
83
164
 
165
+
166
+
84
167
  const compiled = compile(childTemplate, { views: './templates' });
168
+
85
169
  const html = compiled.renderBlock('content', context);
170
+
86
171
  ```
87
172
 
173
+
174
+
88
175
  === "ES Modules"
89
176
 
177
+
178
+
90
179
  ```javascript
180
+
91
181
  import { compile } from 'miki-template';
92
182
 
183
+
184
+
93
185
  const compiled = compile(childTemplate, { views: './templates' });
186
+
94
187
  const html = compiled.renderBlock('content', context);
188
+
95
189
  ```
96
190
 
191
+
192
+
97
193
  ### Render a Partial
98
194
 
195
+
196
+
99
197
  === "CommonJS"
100
198
 
199
+
200
+
101
201
  ```javascript
202
+
102
203
  const { compile } = require('miki-template');
103
204
 
205
+
206
+
104
207
  const compiled = compile(`
208
+
105
209
  {% partialdef card %}
210
+
106
211
  <div class="card">{{ title }}</div>
212
+
107
213
  {% endpartialdef %}
214
+
108
215
  `);
216
+
109
217
  const html = compiled.renderPartial('card', { title: 'Hello' });
218
+
110
219
  ```
111
220
 
221
+
222
+
112
223
  === "ES Modules"
113
224
 
225
+
226
+
114
227
  ```javascript
228
+
115
229
  import { compile } from 'miki-template';
116
230
 
231
+
232
+
117
233
  const compiled = compile(`
234
+
118
235
  {% partialdef card %}
236
+
119
237
  <div class="card">{{ title }}</div>
238
+
120
239
  {% endpartialdef %}
240
+
121
241
  `);
242
+
122
243
  const html = compiled.renderPartial('card', { title: 'Hello' });
244
+
123
245
  ```
124
246
 
247
+
248
+
125
249
  ## Related
126
250
 
127
- - [render()](./render)
128
- - [asyncRender()](./async-render)
251
+
252
+
253
+ - [render()](./render.md)
254
+
255
+ - [asyncRender()](./async-render.md)
256
+
@@ -1,77 +1,154 @@
1
- # Context Processors API
1
+ # Context Processors API
2
+
3
+
2
4
 
3
5
  ## registerContextProcessor
4
6
 
7
+
8
+
5
9
  Register a context processor function that runs before every render. The returned object is merged into the rendering context, with explicit context values always winning.
6
10
 
11
+
12
+
7
13
  === "CommonJS"
8
14
 
15
+
16
+
9
17
  ```javascript
18
+
10
19
  const { registerContextProcessor } = require('miki-template');
11
20
 
21
+
22
+
12
23
  registerContextProcessor((context) => {
24
+
13
25
  return {
26
+
14
27
  siteName: 'My App',
28
+
15
29
  currentYear: new Date().getFullYear()
30
+
16
31
  };
32
+
17
33
  });
34
+
18
35
  ```
19
36
 
37
+
38
+
20
39
  === "ES Modules"
21
40
 
41
+
42
+
22
43
  ```javascript
44
+
23
45
  import { registerContextProcessor } from 'miki-template';
24
46
 
47
+
48
+
25
49
  registerContextProcessor((context) => {
50
+
26
51
  return {
52
+
27
53
  siteName: 'My App',
54
+
28
55
  currentYear: new Date().getFullYear()
56
+
29
57
  };
58
+
30
59
  });
60
+
31
61
  ```
32
62
 
63
+
64
+
33
65
  ### Signature
34
66
 
67
+
68
+
35
69
  ```typescript
70
+
36
71
  type ContextProcessor = (context: Context) => Record<string, any> | null
72
+
37
73
  ```
38
74
 
75
+
76
+
39
77
  - Receives the `Context` object, allowing inspection of existing values via `context.get('key')`.
78
+
40
79
  - Must return a plain object. Returning `null` or `undefined` is treated as `{}`.
80
+
41
81
  - Must be synchronous — no async/await or Promises.
42
82
 
83
+
84
+
43
85
  ## clearContextProcessors
44
86
 
87
+
88
+
45
89
  Clear all registered context processors. Useful in tests or when re-configuring.
46
90
 
91
+
92
+
47
93
  === "CommonJS"
48
94
 
95
+
96
+
49
97
  ```javascript
98
+
50
99
  const { clearContextProcessors } = require('miki-template');
51
100
 
101
+
102
+
52
103
  clearContextProcessors();
104
+
53
105
  ```
54
106
 
107
+
108
+
55
109
  === "ES Modules"
56
110
 
111
+
112
+
57
113
  ```javascript
114
+
58
115
  import { clearContextProcessors } from 'miki-template';
59
116
 
117
+
118
+
60
119
  clearContextProcessors();
120
+
61
121
  ```
62
122
 
123
+
124
+
63
125
  ## Precedence Rules
64
126
 
127
+
128
+
65
129
  1. **Context processors run first** — their key/value pairs are added to the context.
130
+
66
131
  2. **Your explicit context is applied last** — explicit values always override processor values.
67
132
 
133
+
134
+
68
135
  ```javascript
136
+
69
137
  // Processor sets: { siteName: 'My App', theme: 'dark' }
138
+
70
139
  // You render with: { theme: 'light' }
140
+
71
141
  // Result: { siteName: 'My App', theme: 'light' }
142
+
72
143
  ```
73
144
 
145
+
146
+
74
147
  ## Next Steps
75
148
 
76
- - [Context Processors Guide](../guide/context-processors)
77
- - [API Reference](../)
149
+
150
+
151
+ - [Context Processors Guide](../guide/context-processors.md)
152
+
153
+ - [API Reference](../index.md)
154
+