miki-template 2.2.3 → 2.3.1

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 +0 -5
  3. package/README.md +17 -5
  4. package/benchmarks/ejs-results.json +6 -6
  5. package/benchmarks/ejs.js +5 -3
  6. package/benchmarks/handlebars-results.json +6 -6
  7. package/benchmarks/handlebars.js +5 -8
  8. package/benchmarks/miki-results.json +6 -6
  9. package/benchmarks/miki.js +6 -3
  10. package/benchmarks/pug-results.json +6 -6
  11. package/benchmarks/pug.js +5 -3
  12. package/docs/api/async-render.md +88 -3
  13. package/docs/api/cache.md +90 -3
  14. package/docs/api/compile.md +131 -3
  15. package/docs/api/context-processors.md +80 -3
  16. package/docs/api/filters.md +223 -3
  17. package/docs/api/finder.md +97 -3
  18. package/docs/api/helpers.md +56 -3
  19. package/docs/api/i18n.md +160 -3
  20. package/docs/api/index.md +82 -28
  21. package/docs/api/libraries.md +210 -3
  22. package/docs/api/render-partial.md +84 -3
  23. package/docs/api/render.md +95 -3
  24. package/docs/api/security.md +148 -3
  25. package/docs/api/setup-express.md +78 -2
  26. package/docs/api/tags.md +138 -4
  27. package/docs/filter.md +0 -0
  28. package/docs/guide/advanced-usage.md +403 -6
  29. package/docs/guide/async-rendering.md +312 -4
  30. package/docs/guide/context-processors.md +261 -4
  31. package/docs/guide/custom-filters.md +315 -4
  32. package/docs/guide/custom-tags.md +275 -4
  33. package/docs/guide/filters.md +675 -3
  34. package/docs/guide/getting-started.md +109 -7
  35. package/docs/guide/installation.md +99 -4
  36. package/docs/guide/partial-templates.md +371 -4
  37. package/docs/guide/quick-start.md +228 -6
  38. package/docs/guide/security.md +348 -3
  39. package/docs/guide/tags.md +789 -6
  40. package/docs/guide/template-discovery.md +174 -4
  41. package/docs/guide/template-inheritance.md +277 -4
  42. package/docs/index.md +24 -42
  43. package/docs/integrations/elysia.md +4 -2
  44. package/docs/integrations/express.md +219 -219
  45. package/docs/integrations/fastify.md +4 -2
  46. package/docs/integrations/hono.md +4 -2
  47. package/docs/integrations/index.md +68 -68
  48. package/docs/integrations/koa.md +4 -2
  49. package/docs/integrations/nestjs.md +4 -2
  50. package/docs/integrations/tsed.md +4 -2
  51. package/docs/performance.md +45 -8
  52. package/ex.mjs +1 -1
  53. package/mkdocs.yml +0 -22
  54. package/overrides/main.html +1 -1
  55. package/package.json +1 -1
  56. package/requirements-docs.txt +2 -1
  57. package/src/codegen.js +905 -0
  58. package/src/context.js +42 -30
  59. package/src/filters.js +16 -0
  60. package/src/index.js +66 -61
  61. package/src/tags/control.js +15 -12
  62. package/src/utils.js +60 -0
  63. package/tests/filters.test.js +9 -0
  64. package/docs/javascripts/extra.js +0 -174
  65. package/docs/stylesheets/extra.css +0 -819
  66. package/overrides/partials/footer.html +0 -9
@@ -1,170 +1,340 @@
1
- # Smart Template Discovery
1
+ # Smart Template Discovery
2
+
3
+
2
4
 
3
5
  miki-template includes a Django-inspired template finder that searches your project structure intelligently. You no longer need to manually configure every views directory or worry about `Failed to lookup view` errors when templates live in nested app folders.
4
6
 
7
+
8
+
5
9
  ## Table of Contents
6
10
 
11
+
12
+
7
13
  - [How It Works](#how-it-works)
14
+
8
15
  - [Supported Layouts](#supported-layouts)
16
+
9
17
  - [Express Integration](#express-integration)
18
+
10
19
  - [Custom Template Directory Names](#custom-template-directory-names)
20
+
11
21
  - [Manual Lookup](#manual-lookup)
22
+
12
23
  - [ESM Import](#esm-import)
24
+
13
25
  - [Next Steps](#next-steps)
14
26
 
27
+
28
+
15
29
  ---
16
30
 
31
+
32
+
17
33
  ## How It Works
18
34
 
35
+
36
+
19
37
  When you call `res.render('name')` or `render('name', ctx, { views })`, miki-template:
20
38
 
39
+
40
+
21
41
  1. Resolves the view name against the configured views directories.
42
+
22
43
  2. Searches recursively through subdirectories for matching files.
44
+
23
45
  3. Recognizes app-style `templates/` directories automatically.
46
+
24
47
  4. Supports custom directory names via `setAppTemplateDirNames()`.
25
48
 
49
+
50
+
26
51
  The search order is:
27
52
 
53
+
54
+
28
55
  1. **Direct resolution** — if you pass `nested/path`, it resolves relative to each views root.
56
+
29
57
  2. **Recursive search** — if you pass a bare name like `home`, the engine walks subdirectories searching for `home.html` or `home.miki`.
58
+
30
59
  3. **App-style directories** — directories named `templates` (or whatever you configure) are treated as additional view roots at any depth.
31
60
 
61
+
62
+
32
63
  ## Supported Layouts
33
64
 
65
+
66
+
34
67
  ```text
68
+
35
69
  project/
70
+
36
71
  ├── views/
72
+
37
73
  │ └── home.html
74
+
38
75
  ├── app/
76
+
39
77
  │ └── templates/
78
+
40
79
  │ └── dashboard.html
80
+
41
81
  ├── packages/
82
+
42
83
  │ └── admin/
84
+
43
85
  │ └── templates/
86
+
44
87
  │ └── settings.html
88
+
45
89
  ```
46
90
 
91
+
92
+
47
93
  All of these are discoverable without extra configuration.
48
94
 
95
+
96
+
49
97
  ## Express Integration
50
98
 
99
+
100
+
51
101
  When you use `setupExpress()`, the engine automatically expands your views roots to include all directories that contain template files:
52
102
 
103
+
104
+
53
105
  === "CommonJS"
54
106
 
107
+
108
+
55
109
  ```javascript
110
+
56
111
  const express = require('express');
112
+
57
113
  const miki = require('miki-template');
58
114
 
115
+
116
+
59
117
  const app = express();
118
+
60
119
  miki.setupExpress(app, { extension: 'html', views: './views' });
61
120
 
121
+
122
+
62
123
  // Templates placed deeply in your project are found automatically:
124
+
63
125
  app.get('/', (req, res) => res.render('home'));
126
+
64
127
  app.get('/admin', (req, res) => res.render('settings'));
128
+
65
129
  ```
66
130
 
131
+
132
+
67
133
  === "ES Modules"
68
134
 
135
+
136
+
69
137
  ```javascript
138
+
70
139
  import express from 'express';
140
+
71
141
  import miki from 'miki-template';
72
142
 
143
+
144
+
73
145
  const app = express();
146
+
74
147
  miki.setupExpress(app, { extension: 'html', views: './views' });
75
148
 
149
+
150
+
76
151
  app.get('/', (req, res) => res.render('home'));
152
+
77
153
  app.get('/admin', (req, res) => res.render('settings'));
154
+
78
155
  ```
79
156
 
157
+
158
+
80
159
  You can also pass multiple roots:
81
160
 
161
+
162
+
82
163
  ```javascript
164
+
83
165
  miki.setupExpress(app, {
166
+
84
167
  extension: 'html',
168
+
85
169
  views: ['./views', './app/templates', './packages/*/templates']
170
+
86
171
  });
172
+
87
173
  ```
88
174
 
175
+
176
+
89
177
  ## Custom Template Directory Names
90
178
 
179
+
180
+
91
181
  If your project uses a different convention than `templates`, configure it globally:
92
182
 
183
+
184
+
93
185
  === "CommonJS"
94
186
 
187
+
188
+
95
189
  ```javascript
190
+
96
191
  const { setAppTemplateDirNames } = require('miki-template');
97
192
 
193
+
194
+
98
195
  setAppTemplateDirNames(['templates', 'views', 'pages']);
196
+
99
197
  ```
100
198
 
199
+
200
+
101
201
  === "ES Modules"
102
202
 
203
+
204
+
103
205
  ```javascript
206
+
104
207
  import { setAppTemplateDirNames } from 'miki-template';
105
208
 
209
+
210
+
106
211
  setAppTemplateDirNames(['templates', 'views', 'pages']);
212
+
107
213
  ```
108
214
 
215
+
216
+
109
217
  This affects both Express integration and manual `render()` / `findTemplateInViews()` calls.
110
218
 
219
+
220
+
111
221
  ## Manual Lookup
112
222
 
223
+
224
+
113
225
  You can use the finder directly:
114
226
 
227
+
228
+
115
229
  === "CommonJS"
116
230
 
231
+
232
+
117
233
  ```javascript
234
+
118
235
  const { findTemplateInViews } = require('miki-template');
119
236
 
237
+
238
+
120
239
  const found = findTemplateInViews('home', [
240
+
121
241
  './views',
242
+
122
243
  './app/templates'
244
+
123
245
  ]);
124
246
 
247
+
248
+
125
249
  console.log(found);
250
+
126
251
  // Output: /absolute/path/to/home.html
252
+
127
253
  ```
128
254
 
255
+
256
+
129
257
  === "ES Modules"
130
258
 
259
+
260
+
131
261
  ```javascript
262
+
132
263
  import { findTemplateInViews } from 'miki-template';
133
264
 
265
+
266
+
134
267
  const found = findTemplateInViews('home', [
268
+
135
269
  './views',
270
+
136
271
  './app/templates'
272
+
137
273
  ]);
138
274
 
275
+
276
+
139
277
  console.log(found);
278
+
140
279
  // Output: /absolute/path/to/home.html
280
+
141
281
  ```
142
282
 
283
+
284
+
143
285
  ### Finder Behavior
144
286
 
287
+
288
+
145
289
  - Searches recursively through subdirectories for bare template names.
290
+
146
291
  - Tries `.html` and `.miki` extensions when no extension is provided.
292
+
147
293
  - Also searches app-style `templates/` directories nested inside the views root.
294
+
148
295
  - Returns the first match found, or `null` if not found.
149
296
 
297
+
298
+
150
299
  ### ESM Import
151
300
 
301
+
302
+
152
303
  === "ES Modules"
153
304
 
305
+
306
+
154
307
  ```javascript
308
+
155
309
  import { findTemplateInViews, setAppTemplateDirNames } from 'miki-template';
156
310
 
311
+
312
+
157
313
  // Set custom directory names
314
+
158
315
  setAppTemplateDirNames(['templates', 'app_templates']);
159
316
 
317
+
318
+
160
319
  // Find a template
320
+
161
321
  const path = findTemplateInViews('detail', ['./views', './packages']);
322
+
162
323
  console.log(path);
324
+
163
325
  // → /absolute/path/to/packages/product/templates/detail.html
326
+
164
327
  ```
165
328
 
329
+
330
+
166
331
  ## Next Steps
167
332
 
168
- - [Partial Templates](./partial-templates)
169
- - [Template Inheritance](./template-inheritance)
170
- - [Integrations: Express](../integrations/express)
333
+
334
+
335
+ - [Partial Templates](./partial-templates.md)
336
+
337
+ - [Template Inheritance](./template-inheritance.md)
338
+
339
+ - [Integrations: Express](../integrations/express.md)
340
+