miki-template 2.3.1 → 2.3.2

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 (159) hide show
  1. package/package.json +45 -1
  2. package/.eslintrc.json +0 -16
  3. package/.github/release-notes/v1.3.1.md +0 -55
  4. package/.github/release-notes/v1.3.3.md +0 -77
  5. package/.github/release-notes/v1.3.7.md +0 -20
  6. package/.github/workflows/ci.yml +0 -42
  7. package/.github/workflows/docs.yml +0 -107
  8. package/.github/workflows/release.yml +0 -107
  9. package/AGENT.md +0 -71
  10. package/API_REFERENCE.md +0 -341
  11. package/CHANGELOG.md +0 -173
  12. package/CODE_OF_CONDUCT.md +0 -14
  13. package/CONTRIBUTING.md +0 -27
  14. package/ROADMAP.md +0 -40
  15. package/assets/banner.png +0 -0
  16. package/assets/logo.png +0 -0
  17. package/benchmarks/ejs-results.json +0 -17
  18. package/benchmarks/ejs.js +0 -38
  19. package/benchmarks/handlebars-results.json +0 -17
  20. package/benchmarks/handlebars.js +0 -45
  21. package/benchmarks/miki-results.json +0 -17
  22. package/benchmarks/miki.js +0 -39
  23. package/benchmarks/pug-results.json +0 -17
  24. package/benchmarks/pug.js +0 -38
  25. package/benchmarks/report.json +0 -17
  26. package/benchmarks/run.js +0 -81
  27. package/benchmarks/stress.mjs +0 -647
  28. package/benchmarks/templates/large.dtpl +0 -7
  29. package/benchmarks/templates/medium.dtpl +0 -3
  30. package/benchmarks/templates/small.dtpl +0 -7
  31. package/context/component.md +0 -109
  32. package/context/prd.md +0 -131
  33. package/context/project-structure.md +0 -33
  34. package/dir/base.html +0 -23
  35. package/dir/cmpnt.html +0 -11
  36. package/dir/footer.html +0 -3
  37. package/dir/home.html +0 -80
  38. package/dir/index.html +0 -80
  39. package/dir/navbar.html +0 -9
  40. package/docs/api/async-render.md +0 -170
  41. package/docs/api/cache.md +0 -174
  42. package/docs/api/compile.md +0 -256
  43. package/docs/api/context-processors.md +0 -154
  44. package/docs/api/filters.md +0 -437
  45. package/docs/api/finder.md +0 -188
  46. package/docs/api/helpers.md +0 -106
  47. package/docs/api/i18n.md +0 -314
  48. package/docs/api/index.md +0 -108
  49. package/docs/api/libraries.md +0 -414
  50. package/docs/api/render-partial.md +0 -162
  51. package/docs/api/render.md +0 -184
  52. package/docs/api/security.md +0 -290
  53. package/docs/api/setup-express.md +0 -152
  54. package/docs/api/tags.md +0 -268
  55. package/docs/assets/banner.png +0 -0
  56. package/docs/assets/logo.png +0 -0
  57. package/docs/filter.md +0 -0
  58. package/docs/guide/advanced-usage.md +0 -794
  59. package/docs/guide/async-rendering.md +0 -616
  60. package/docs/guide/context-processors.md +0 -514
  61. package/docs/guide/custom-filters.md +0 -622
  62. package/docs/guide/custom-tags.md +0 -542
  63. package/docs/guide/filters.md +0 -1314
  64. package/docs/guide/getting-started.md +0 -204
  65. package/docs/guide/installation.md +0 -190
  66. package/docs/guide/partial-templates.md +0 -734
  67. package/docs/guide/quick-start.md +0 -444
  68. package/docs/guide/security.md +0 -690
  69. package/docs/guide/tags.md +0 -1566
  70. package/docs/guide/template-discovery.md +0 -340
  71. package/docs/guide/template-inheritance.md +0 -546
  72. package/docs/guide/what-is-miki-template.md +0 -28
  73. package/docs/guide/why-miki-template.md +0 -75
  74. package/docs/index.md +0 -86
  75. package/docs/integrations/elysia.md +0 -80
  76. package/docs/integrations/express.md +0 -219
  77. package/docs/integrations/fastify.md +0 -79
  78. package/docs/integrations/hono.md +0 -80
  79. package/docs/integrations/index.md +0 -68
  80. package/docs/integrations/koa.md +0 -90
  81. package/docs/integrations/nestjs.md +0 -80
  82. package/docs/integrations/tsed.md +0 -83
  83. package/docs/performance.md +0 -74
  84. package/eslint.config.mjs +0 -42
  85. package/ex.mjs +0 -36
  86. package/live-test/integrations/elysia-example.js +0 -16
  87. package/live-test/integrations/express-example.js +0 -24
  88. package/live-test/integrations/fastify-example.js +0 -20
  89. package/live-test/integrations/hono-example.js +0 -16
  90. package/live-test/integrations/koa-example.js +0 -30
  91. package/live-test/integrations/nestjs-example.js +0 -25
  92. package/live-test/integrations/smoke-test.js +0 -166
  93. package/live-test/integrations/tsed-example.js +0 -23
  94. package/live-test/package-lock.json +0 -1150
  95. package/live-test/package.json +0 -13
  96. package/live-test/packages/product/templates/product/detail.html +0 -7
  97. package/live-test/server.js +0 -38
  98. package/live-test/templates/app_templates/detail.html +0 -6
  99. package/live-test/views/base.html +0 -8
  100. package/live-test/views/child.html +0 -7
  101. package/live-test/views/home.html +0 -17
  102. package/live-test/views/index.html +0 -1
  103. package/miki-template-extension/.github/workflows/ci.yml +0 -116
  104. package/miki-template-extension/.vscodeignore +0 -7
  105. package/miki-template-extension/CHANGELOG.md +0 -99
  106. package/miki-template-extension/LICENSE +0 -21
  107. package/miki-template-extension/README.md +0 -273
  108. package/miki-template-extension/extension.js +0 -1013
  109. package/miki-template-extension/icon.png +0 -0
  110. package/miki-template-extension/icon.svg +0 -10
  111. package/miki-template-extension/miki-template-1.7.1.vsix +0 -0
  112. package/miki-template-extension/package.json +0 -280
  113. package/miki-template-extension/snippets/miki-template.json +0 -717
  114. package/miki-template-extension/syntaxes/language-configuration.json +0 -114
  115. package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +0 -355
  116. package/miki-template-extension/tests/grammar-tests.json +0 -162
  117. package/miki-template-extension/tests/run-grammar-tests.js +0 -82
  118. package/mkdocs.yml +0 -195
  119. package/overrides/main.html +0 -26
  120. package/requirements-docs.txt +0 -2
  121. package/sample-app/package-lock.json +0 -901
  122. package/sample-app/package.json +0 -9
  123. package/sample-app/server.js +0 -14
  124. package/sample-app/views/index.html +0 -1
  125. package/scripts/build-vsix.js +0 -129
  126. package/scripts/build-vsix.ps1 +0 -15
  127. package/snippets/miki-template.json +0 -177
  128. package/src/asyncRender.js +0 -21
  129. package/src/types.d.ts +0 -107
  130. package/syntaxes/language-configuration.json +0 -26
  131. package/syntaxes/miki-template.tmLanguage.json +0 -146
  132. package/tests/asyncRender.test.js +0 -17
  133. package/tests/base.html +0 -6
  134. package/tests/child.html +0 -3
  135. package/tests/context_processors.test.js +0 -13
  136. package/tests/esm.test.mjs +0 -61
  137. package/tests/filters.test.js +0 -263
  138. package/tests/finder-appdirs.test.js +0 -19
  139. package/tests/finder.test.js +0 -17
  140. package/tests/fixtures/views/nested/index.html +0 -1
  141. package/tests/fixtures/views/partial.html +0 -1
  142. package/tests/fixtures/views/sub/deepfile.html +0 -1
  143. package/tests/fixtures/views-appdirs/product/site/detail.html +0 -1
  144. package/tests/include_security.test.js +0 -9
  145. package/tests/integration/README.md +0 -32
  146. package/tests/integration/features.test.cjs +0 -1681
  147. package/tests/integration/features.test.mjs +0 -1697
  148. package/tests/integration/finder.esm.test.mjs +0 -13
  149. package/tests/integration/partial-render.test.cjs +0 -13
  150. package/tests/integration/templates/base.miki +0 -6
  151. package/tests/integration/templates/child.miki +0 -6
  152. package/tests/integration/templates/index.html +0 -17
  153. package/tests/lexer.test.js +0 -45
  154. package/tests/parser.test.js +0 -57
  155. package/tests/partial.html +0 -1
  156. package/tests/partialdef.test.js +0 -79
  157. package/tests/production_checks.js +0 -57
  158. package/tests/security.test.js +0 -28
  159. package/tests/tags.test.js +0 -233
@@ -1,80 +0,0 @@
1
- # Elysia
2
-
3
- Use miki-template with Elysia (Bun-native framework) by calling `asyncRender()` in your handlers.
4
-
5
- ## Setup
6
-
7
- === "ES Modules"
8
-
9
- ```javascript
10
- import { Elysia } from 'elysia';
11
- import miki from 'miki-template';
12
-
13
- const app = new Elysia();
14
-
15
- app.get('/', async () => {
16
- const html = await miki.asyncRender('index', {}, { views: './views' });
17
- return new Response(html, {
18
- headers: { 'Content-Type': 'text/html' }
19
- });
20
- });
21
-
22
- export default app;
23
- ```
24
-
25
- === "CommonJS"
26
-
27
- ```javascript
28
- const { Elysia } = require('elysia');
29
- const miki = require('miki-template');
30
-
31
- const app = new Elysia();
32
-
33
- app.get('/', async () => {
34
- const html = await miki.asyncRender('index', {}, { views: './views' });
35
- return new Response(html, {
36
- headers: { 'Content-Type': 'text/html' }
37
- });
38
- });
39
-
40
- module.exports = app;
41
- ```
42
-
43
- ## Partial Rendering
44
-
45
- === "ES Modules"
46
-
47
- ```javascript
48
- app.get('/partials/:name', async ({ params }) => {
49
- const html = await miki.asyncRender(
50
- `home#${params.name}`,
51
- {},
52
- { views: './views' }
53
- );
54
- return new Response(html, {
55
- headers: { 'Content-Type': 'text/html' }
56
- });
57
- });
58
- ```
59
-
60
- === "CommonJS"
61
-
62
- ```javascript
63
- app.get('/partials/:name', async ({ params }) => {
64
- const html = await miki.asyncRender(
65
- `home#${params.name}`,
66
- {},
67
- { views: './views' }
68
- );
69
- return new Response(html, {
70
- headers: { 'Content-Type': 'text/html' }
71
- });
72
- });
73
- ```
74
-
75
- ## Next Steps
76
-
77
- - [Integrations Overview](../index.md)
78
- - [API Reference: asyncRender param($m) $m.Value -replace '([a-z][a-z0-9-]+)\.md
79
- , '../.md' -replace '([a-z][a-z0-9-]+)
80
- , '../.md'
@@ -1,219 +0,0 @@
1
- # Express
2
-
3
- Express is the most common integration. Use `setupExpress()` for one-line setup.
4
-
5
- ## Setup
6
-
7
- === "CommonJS"
8
-
9
- ```javascript
10
- const express = require('express');
11
- const miki = require('miki-template');
12
-
13
- const app = express();
14
- miki.setupExpress(app, { extension: 'html', views: './views' });
15
-
16
- app.get('/', (req, res) => res.render('home', { user: req.user }));
17
- app.get('/partials/:name', (req, res) =>
18
- res.render(`home#${req.params.name}`, { user: req.user })
19
- );
20
-
21
- app.listen(3000);
22
- ```
23
-
24
- === "ES Modules"
25
-
26
- ```javascript
27
- import express from 'express';
28
- import miki from 'miki-template';
29
-
30
- const app = express();
31
- miki.setupExpress(app, { extension: 'html', views: './views' });
32
-
33
- app.get('/', (req, res) => res.render('home', { user: req.user }));
34
- app.get('/partials/:name', (req, res) =>
35
- res.render(`home#${req.params.name}`, { user: req.user })
36
- );
37
-
38
- app.listen(3000);
39
- ```
40
-
41
- ## Options
42
-
43
- | Option | Default | Description |
44
- |--------|---------|-------------|
45
- | `extension` | `'html'` | File extension for views. Use `'miki'` if you prefer `.miki` files. |
46
- | `views` | `app.get('views')` | Views directory (passed to `app.set('views', ...)`). |
47
- | `async` | `false` | Use the async engine (`__expressAsync`). For Express 5+ with async helpers. |
48
-
49
- > The `res.render` shim intercepts **only** view names containing a `#`. Everything else (full pages, `res.render(view, cb)`, callback forms) goes through Express's normal view lookup, so the integration is fully compatible with existing Express middleware.
50
-
51
- ## Manual Setup
52
-
53
- If you prefer full control:
54
-
55
- === "CommonJS"
56
-
57
- ```javascript
58
- const express = require('express');
59
- const { __express } = require('miki-template');
60
-
61
- const app = express();
62
- app.engine('html', __express);
63
- app.set('view engine', 'html');
64
- app.set('views', './views');
65
- ```
66
-
67
- === "ES Modules"
68
-
69
- ```javascript
70
- import express from 'express';
71
- import { __express } from 'miki-template';
72
-
73
- const app = express();
74
- app.engine('html', __express);
75
- app.set('view engine', 'html');
76
- app.set('views', './views');
77
- ```
78
-
79
- ## Async Express 5+
80
-
81
- Express 5+ supports async route handlers natively. Pass `async: true` to `setupExpress`, or use `__expressAsync` directly:
82
-
83
- === "CommonJS"
84
-
85
- ```javascript
86
- const express = require('express');
87
- const miki = require('miki-template');
88
-
89
- const app = express();
90
- miki.setupExpress(app, { extension: 'html', views: './views', async: true });
91
-
92
- app.get('/user/:id', async (req, res) => {
93
- const user = await User.findById(req.params.id);
94
- if (!user) return res.status(404).send('Not found');
95
- res.render('user-profile', { user });
96
- });
97
- ```
98
-
99
- === "ES Modules"
100
-
101
- ```javascript
102
- import express from 'express';
103
- import miki from 'miki-template';
104
-
105
- const app = express();
106
- miki.setupExpress(app, { extension: 'html', views: './views', async: true });
107
-
108
- app.get('/user/:id', async (req, res) => {
109
- const user = await User.findById(req.params.id);
110
- if (!user) return res.status(404).send('Not found');
111
- res.render('user-profile', { user });
112
- });
113
- ```
114
-
115
- ## Partial Renderer Middleware
116
-
117
- Add partial rendering without changing engine registration:
118
-
119
- === "CommonJS"
120
-
121
- ```javascript
122
- const express = require('express');
123
- const miki = require('miki-template');
124
-
125
- const app = express();
126
- miki.setupExpress(app, { extension: 'html', views: './views' });
127
- app.use(miki.expressPartialRenderer());
128
-
129
- app.get('/card', (req, res) => res.renderPartial('home#card', { user: req.user }));
130
- ```
131
-
132
- === "ES Modules"
133
-
134
- ```javascript
135
- import express from 'express';
136
- import miki from 'miki-template';
137
-
138
- const app = express();
139
- miki.setupExpress(app, { extension: 'html', views: './views' });
140
- // Note: must call expressPartialRenderer() before routes
141
- app.use(miki.expressPartialRenderer());
142
-
143
- app.get('/card', (req, res) => res.renderPartial('home#card', { user: req.user }));
144
- ```
145
-
146
- ## Express Adapter (app.engine)
147
-
148
- If you prefer not to use `setupExpress()`, you can use `express()` directly as a view engine:
149
-
150
- === "CommonJS"
151
-
152
- ```javascript
153
- const express = require('express');
154
- const { express: mikiExpress } = require('miki-template');
155
-
156
- const app = express();
157
- app.engine('html', mikiExpress({ async: true }));
158
- app.set('view engine', 'html');
159
- app.set('views', './views');
160
- ```
161
-
162
- === "ES Modules"
163
-
164
- ```javascript
165
- import express from 'express';
166
- import { express as mikiExpress } from 'miki-template';
167
-
168
- const app = express();
169
- app.engine('html', mikiExpress({ async: true }));
170
- app.set('view engine', 'html');
171
- app.set('views', './views');
172
- ```
173
-
174
- ## HTMX Example
175
-
176
- miki-template's partial rendering (`#partialName`) is purpose-built for HTMX and similar frameworks:
177
-
178
- === "CommonJS"
179
-
180
- ```javascript
181
- const express = require('express');
182
- const miki = require('miki-template');
183
-
184
- const app = express();
185
- miki.setupExpress(app, { extension: 'html', views: './views' });
186
-
187
- // Full page — initial load
188
- app.get('/', (req, res) => res.render('home', { user: req.user }));
189
-
190
- // HTMX partial — only re-renders the "card" component
191
- app.get('/partials/:name', (req, res) =>
192
- res.render(`home#${req.params.name}`, { user: req.user })
193
- );
194
-
195
- app.listen(3000);
196
- ```
197
-
198
- === "ES Modules"
199
-
200
- ```javascript
201
- import express from 'express';
202
- import miki from 'miki-template';
203
-
204
- const app = express();
205
- miki.setupExpress(app, { extension: 'html', views: './views' });
206
-
207
- app.get('/', (req, res) => res.render('home', { user: req.user }));
208
-
209
- app.get('/partials/:name', (req, res) =>
210
- res.render(`home#${req.params.name}`, { user: req.user })
211
- );
212
-
213
- app.listen(3000);
214
- ```
215
-
216
- ## Next Steps
217
-
218
- - [Integrations Overview](../index.md)
219
- - [API Reference: setupExpress](../api/setup-express.md)
@@ -1,79 +0,0 @@
1
- # Fastify
2
-
3
- Use miki-template with Fastify by calling `asyncRender()` inline in your route handlers.
4
-
5
- ## Setup
6
-
7
- === "CommonJS"
8
-
9
- ```javascript
10
- const fastify = require('fastify')();
11
- const path = require('path');
12
- const miki = require('miki-template');
13
-
14
- fastify.get('/', async (request, reply) => {
15
- const html = await miki.asyncRender(
16
- 'index',
17
- { user: request.user },
18
- { views: path.resolve('./views') }
19
- );
20
- reply.type('text/html').send(html);
21
- });
22
-
23
- fastify.listen({ port: 3000 });
24
- ```
25
-
26
- === "ES Modules"
27
-
28
- ```javascript
29
- import Fastify from 'fastify';
30
- import miki from 'miki-template';
31
-
32
- const fastify = Fastify();
33
-
34
- fastify.get('/', async (request, reply) => {
35
- const html = await miki.asyncRender(
36
- 'index',
37
- { user: request.user },
38
- { views: './views' }
39
- );
40
- reply.type('text/html').send(html);
41
- });
42
-
43
- fastify.listen({ port: 3000 });
44
- ```
45
-
46
- ## Partial Rendering
47
-
48
- === "CommonJS"
49
-
50
- ```javascript
51
- fastify.get('/partial/:name', async (request, reply) => {
52
- const html = await miki.asyncRender(
53
- `home#${request.params.name}`,
54
- { user: request.user },
55
- { views: path.resolve('./views') }
56
- );
57
- reply.type('text/html').send(html);
58
- });
59
- ```
60
-
61
- === "ES Modules"
62
-
63
- ```javascript
64
- fastify.get('/partial/:name', async (request, reply) => {
65
- const html = await miki.asyncRender(
66
- `home#${request.params.name}`,
67
- { user: request.user },
68
- { views: './views' }
69
- );
70
- reply.type('text/html').send(html);
71
- });
72
- ```
73
-
74
- ## Next Steps
75
-
76
- - [Integrations Overview](../index.md)
77
- - [API Reference: asyncRender param($m) $m.Value -replace '([a-z][a-z0-9-]+)\.md
78
- , '../.md' -replace '([a-z][a-z0-9-]+)
79
- , '../.md'
@@ -1,80 +0,0 @@
1
- # Hono
2
-
3
- Use miki-template with Hono (ESM-first framework) by calling `asyncRender()` in your handlers.
4
-
5
- ## Setup
6
-
7
- === "ES Modules"
8
-
9
- ```javascript
10
- import { Hono } from 'hono';
11
- import miki from 'miki-template';
12
-
13
- const app = new Hono();
14
-
15
- app.get('/', async (c) => {
16
- const html = await miki.asyncRender(
17
- 'index',
18
- { user: c.get('user') },
19
- { views: './views' }
20
- );
21
- return c.html(html);
22
- });
23
-
24
- export default app;
25
- ```
26
-
27
- === "CommonJS"
28
-
29
- ```javascript
30
- const { Hono } = require('hono');
31
- const miki = require('miki-template');
32
-
33
- const app = new Hono();
34
-
35
- app.get('/', async (c) => {
36
- const html = await miki.asyncRender(
37
- 'index',
38
- { user: c.get('user') },
39
- { views: './views' }
40
- );
41
- return c.html(html);
42
- });
43
-
44
- module.exports = app;
45
- ```
46
-
47
- ## Partial Rendering
48
-
49
- === "ES Modules"
50
-
51
- ```javascript
52
- app.get('/partials/:name', async (c) => {
53
- const html = await miki.asyncRender(
54
- `home#${c.req.param('name')}`,
55
- { user: c.get('user') },
56
- { views: './views' }
57
- );
58
- return c.html(html);
59
- });
60
- ```
61
-
62
- === "CommonJS"
63
-
64
- ```javascript
65
- app.get('/partials/:name', async (c) => {
66
- const html = await miki.asyncRender(
67
- `home#${c.req.param('name')}`,
68
- { user: c.get('user') },
69
- { views: './views' }
70
- );
71
- return c.html(html);
72
- });
73
- ```
74
-
75
- ## Next Steps
76
-
77
- - [Integrations Overview](../index.md)
78
- - [API Reference: asyncRender param($m) $m.Value -replace '([a-z][a-z0-9-]+)\.md
79
- , '../.md' -replace '([a-z][a-z0-9-]+)
80
- , '../.md'
@@ -1,68 +0,0 @@
1
- # Integrations Overview
2
-
3
- miki-template works with all major Node.js web frameworks. Use `render()` for synchronous output or `asyncRender()` for templates with async filters/tags.
4
-
5
- ## Supported Frameworks
6
-
7
- - [Express](./express.md) — One-line setup with `setupExpress()`
8
- - [Koa](./koa.md) — Context helper using `asyncRender()`
9
- - [Fastify](./fastify.md) — Inline `asyncRender()` calls
10
- - [Hono](./hono.md) — ESM-first, using `asyncRender()`
11
- - [Elysia](./elysia.md) — ESM-first, using `asyncRender()`
12
- - [NestJS](./nestjs.md) — Module/Provider pattern
13
- - [TSDX / TS-Economy (TSed)](./tsed.md) — TypeScript integration
14
-
15
- ## Quick Example
16
-
17
- === "CommonJS"
18
-
19
- ```javascript
20
- const express = require('express');
21
- const miki = require('miki-template');
22
-
23
- const app = express();
24
- miki.setupExpress(app, { extension: 'html', views: './views' });
25
-
26
- app.get('/', (req, res) => res.render('home', { user: req.user }));
27
-
28
- app.listen(3000);
29
- ```
30
-
31
- === "ES Modules"
32
-
33
- ```javascript
34
- import express from 'express';
35
- import miki from 'miki-template';
36
-
37
- const app = express();
38
- miki.setupExpress(app, { extension: 'html', views: './views' });
39
-
40
- app.get('/', (req, res) => res.render('home', { user: req.user }));
41
-
42
- app.listen(3000);
43
- ```
44
-
45
- ## Notes
46
-
47
- - For CommonJS: `const miki = require('miki-template');`
48
- - For ESM / Bun: `import miki from 'miki-template';` or `import * as miki from 'miki-template';`
49
- - When rendering files, pass `options.views` or set framework view roots so the engine can locate templates.
50
- - Use `asyncRender()` if your templates use async filters, async tags, or `{% load %}` libraries with async components.
51
-
52
- ## Installation
53
-
54
- ```bash
55
- # npm
56
- npm install miki-template
57
-
58
- # bun
59
- bun add miki-template
60
-
61
- # yarn
62
- yarn add miki-template
63
- ```
64
-
65
- ## Next Steps
66
-
67
- - [Express Integration](./express.md)
68
- - [API Reference: render](../api/render.md)
@@ -1,90 +0,0 @@
1
- # Koa
2
-
3
- Use miki-template with Koa by attaching an async render helper to the context.
4
-
5
- ## Setup
6
-
7
- === "CommonJS"
8
-
9
- ```javascript
10
- const Koa = require('koa');
11
- const path = require('path');
12
- const miki = require('miki-template');
13
-
14
- const app = new Koa();
15
-
16
- app.context.render = async function (view, locals = {}) {
17
- const html = await miki.asyncRender(view, locals, {
18
- views: path.resolve('./views')
19
- });
20
- this.type = 'text/html';
21
- this.body = html;
22
- };
23
-
24
- app.use(async (ctx) => {
25
- await ctx.render('index', { user: ctx.state.user });
26
- });
27
-
28
- app.listen(3000);
29
- ```
30
-
31
- === "ES Modules"
32
-
33
- ```javascript
34
- import { Koa } from 'koa';
35
- import miki from 'miki-template';
36
- import path from 'node:path';
37
-
38
- const app = new Koa();
39
-
40
- app.context.render = async function (view, locals = {}) {
41
- const html = await miki.asyncRender(view, locals, {
42
- views: path.resolve('./views')
43
- });
44
- this.type = 'text/html';
45
- this.body = html;
46
- };
47
-
48
- app.use(async (ctx) => {
49
- await ctx.render('index', { user: ctx.state.user });
50
- });
51
-
52
- export default app;
53
- ```
54
-
55
- ## Partial Rendering
56
-
57
- === "CommonJS"
58
-
59
- ```javascript
60
- app.use(async (ctx) => {
61
- const html = await miki.asyncRender(
62
- `home#${ctx.params.name}`,
63
- { user: ctx.state.user },
64
- { views: path.resolve('./views') }
65
- );
66
- ctx.type = 'text/html';
67
- ctx.body = html;
68
- });
69
- ```
70
-
71
- === "ES Modules"
72
-
73
- ```javascript
74
- app.use(async (ctx) => {
75
- const html = await miki.asyncRender(
76
- `home#${ctx.params.name}`,
77
- { user: ctx.state.user },
78
- { views: './views' }
79
- );
80
- ctx.type = 'text/html';
81
- ctx.body = html;
82
- });
83
- ```
84
-
85
- ## Next Steps
86
-
87
- - [Integrations Overview](../index.md)
88
- - [API Reference: asyncRender param($m) $m.Value -replace '([a-z][a-z0-9-]+)\.md
89
- , '../.md' -replace '([a-z][a-z0-9-]+)
90
- , '../.md'
@@ -1,80 +0,0 @@
1
- # NestJS
2
-
3
- Use miki-template with NestJS by wiring it into the underlying Express adapter instance.
4
-
5
- ## Setup
6
-
7
- NestJS abstracts the HTTP adapter. To use miki-template, access the underlying Express app and call `setupExpress()`.
8
-
9
- === "TypeScript"
10
-
11
- ```typescript
12
- // main.ts
13
- import { NestFactory } from '@nestjs/core';
14
- import { AppModule } from './app.module';
15
- import * as miki from 'miki-template';
16
-
17
- async function bootstrap() {
18
- const app = await NestFactory.create(AppModule);
19
- const expressApp = app.getHttpAdapter().getInstance();
20
- miki.setupExpress(expressApp, { extension: 'html', views: './views' });
21
- await app.listen(3006);
22
- }
23
-
24
- bootstrap();
25
- ```
26
-
27
- === "CommonJS"
28
-
29
- ```javascript
30
- const { NestFactory } = require('@nestjs/core');
31
- const { AppModule } = require('./app.module');
32
- const miki = require('miki-template');
33
-
34
- async function bootstrap() {
35
- const app = await NestFactory.create(AppModule);
36
- const expressApp = app.getHttpAdapter().getInstance();
37
- miki.setupExpress(expressApp, { extension: 'html', views: './views' });
38
- await app.listen(3006);
39
- }
40
-
41
- bootstrap();
42
- ```
43
-
44
- ## Using in Controllers
45
-
46
- Once `setupExpress()` is wired, use `res.render()` normally in Express-style controllers or middleware:
47
-
48
- ```typescript
49
- import { Controller, Get, Req, Res } from '@nestjs/common';
50
- import { Request, Response } from 'express';
51
-
52
- @Controller()
53
- export class AppController {
54
- @Get()
55
- renderHome(@Req() req: Request, @Res() res: Response) {
56
- res.render('home', { user: req.user });
57
- }
58
-
59
- @Get('partials/:name')
60
- renderPartial(@Req() req: Request, @Res() res: Response) {
61
- res.render(`home#${req.params.name}`, { user: req.user });
62
- }
63
- }
64
- ```
65
-
66
- ## Partial Rendering
67
-
68
- ```typescript
69
- @Get('cards/:id')
70
- renderCard(@Req() req: Request, @Res() res: Response) {
71
- res.render(`home#card`, { user: req.user });
72
- }
73
- ```
74
-
75
- ## Next Steps
76
-
77
- - [Integrations Overview](../index.md)
78
- - [API Reference: setupExpress param($m) $m.Value -replace '([a-z][a-z0-9-]+)\.md
79
- , '../.md' -replace '([a-z][a-z0-9-]+)
80
- , '../.md'