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.
- package/.github/workflows/docs.yml +3 -1
- package/.github/workflows/release.yml +0 -5
- package/README.md +17 -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
|
@@ -1,102 +1,204 @@
|
|
|
1
|
-
# Getting Started
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
Get up and running with miki-template in under a minute.
|
|
4
6
|
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
## Prerequisites
|
|
6
10
|
|
|
11
|
+
|
|
12
|
+
|
|
7
13
|
- **Node.js** 18.x or 20.x (or later, including Bun)
|
|
14
|
+
|
|
8
15
|
- **npm** 9+, **pnpm**, or **yarn**
|
|
9
16
|
|
|
17
|
+
|
|
18
|
+
|
|
10
19
|
## Installation
|
|
11
20
|
|
|
21
|
+
|
|
22
|
+
|
|
12
23
|
=== "npm"
|
|
13
24
|
|
|
25
|
+
|
|
26
|
+
|
|
14
27
|
```bash
|
|
28
|
+
|
|
15
29
|
npm install miki-template
|
|
30
|
+
|
|
16
31
|
```
|
|
17
32
|
|
|
33
|
+
|
|
34
|
+
|
|
18
35
|
=== "pnpm"
|
|
19
36
|
|
|
37
|
+
|
|
38
|
+
|
|
20
39
|
```bash
|
|
40
|
+
|
|
21
41
|
pnpm add miki-template
|
|
42
|
+
|
|
22
43
|
```
|
|
23
44
|
|
|
45
|
+
|
|
46
|
+
|
|
24
47
|
=== "yarn"
|
|
25
48
|
|
|
49
|
+
|
|
50
|
+
|
|
26
51
|
```bash
|
|
52
|
+
|
|
27
53
|
yarn add miki-template
|
|
54
|
+
|
|
28
55
|
```
|
|
29
56
|
|
|
57
|
+
|
|
58
|
+
|
|
30
59
|
## Quick Example: Render a Template String
|
|
31
60
|
|
|
61
|
+
|
|
62
|
+
|
|
32
63
|
The simplest way to use miki-template is the `render()` convenience function. It compiles the template, applies any registered context processors, and returns the HTML — all in one call.
|
|
33
64
|
|
|
65
|
+
|
|
66
|
+
|
|
34
67
|
=== "CommonJS (require)"
|
|
35
68
|
|
|
69
|
+
|
|
70
|
+
|
|
36
71
|
```javascript
|
|
72
|
+
|
|
37
73
|
const { render } = require('miki-template');
|
|
38
74
|
|
|
75
|
+
|
|
76
|
+
|
|
39
77
|
const html = render('Hello {{ name|title }}!', { name: 'alice' });
|
|
78
|
+
|
|
40
79
|
console.log(html); // "Hello Alice!"
|
|
80
|
+
|
|
41
81
|
```
|
|
42
82
|
|
|
83
|
+
|
|
84
|
+
|
|
43
85
|
=== "ES Modules (import)"
|
|
44
86
|
|
|
87
|
+
|
|
88
|
+
|
|
45
89
|
```javascript
|
|
90
|
+
|
|
46
91
|
import { render } from 'miki-template';
|
|
47
92
|
|
|
93
|
+
|
|
94
|
+
|
|
48
95
|
const html = render('Hello {{ name|title }}!', { name: 'alice' });
|
|
96
|
+
|
|
49
97
|
console.log(html); // "Hello Alice!"
|
|
98
|
+
|
|
50
99
|
```
|
|
51
100
|
|
|
101
|
+
|
|
102
|
+
|
|
52
103
|
## Quick Example: Express App
|
|
53
104
|
|
|
105
|
+
|
|
106
|
+
|
|
54
107
|
The real power of miki-template comes with `setupExpress()` — a single function that registers the view engine, configures the views directory, and patches `res.render` so you can render partials with the `view#partial` syntax.
|
|
55
108
|
|
|
109
|
+
|
|
110
|
+
|
|
56
111
|
=== "CommonJS (require)"
|
|
57
112
|
|
|
113
|
+
|
|
114
|
+
|
|
58
115
|
```javascript
|
|
116
|
+
|
|
59
117
|
const express = require('express');
|
|
118
|
+
|
|
60
119
|
const miki = require('miki-template');
|
|
61
120
|
|
|
121
|
+
|
|
122
|
+
|
|
62
123
|
const app = express();
|
|
124
|
+
|
|
63
125
|
miki.setupExpress(app, { extension: 'html', views: './views' });
|
|
64
126
|
|
|
127
|
+
|
|
128
|
+
|
|
65
129
|
app.get('/', (req, res) => res.render('home', { user: req.user }));
|
|
66
130
|
|
|
131
|
+
|
|
132
|
+
|
|
67
133
|
app.listen(3000, () => console.log('Listening on :3000'));
|
|
134
|
+
|
|
68
135
|
```
|
|
69
136
|
|
|
137
|
+
|
|
138
|
+
|
|
70
139
|
=== "ES Modules (import)"
|
|
71
140
|
|
|
141
|
+
|
|
142
|
+
|
|
72
143
|
```javascript
|
|
144
|
+
|
|
73
145
|
import express from 'express';
|
|
146
|
+
|
|
74
147
|
import miki from 'miki-template';
|
|
75
148
|
|
|
149
|
+
|
|
150
|
+
|
|
76
151
|
const app = express();
|
|
152
|
+
|
|
77
153
|
miki.setupExpress(app, { extension: 'html', views: './views' });
|
|
78
154
|
|
|
155
|
+
|
|
156
|
+
|
|
79
157
|
app.get('/', (req, res) => res.render('home', { user: req.user }));
|
|
80
158
|
|
|
159
|
+
|
|
160
|
+
|
|
81
161
|
app.listen(3000, () => console.log('Listening on :3000'));
|
|
162
|
+
|
|
82
163
|
```
|
|
83
164
|
|
|
165
|
+
|
|
166
|
+
|
|
84
167
|
=== "Bun"
|
|
85
168
|
|
|
169
|
+
|
|
170
|
+
|
|
86
171
|
```typescript
|
|
172
|
+
|
|
87
173
|
import { setupExpress } from 'miki-template';
|
|
174
|
+
|
|
88
175
|
import express from 'express';
|
|
89
176
|
|
|
177
|
+
|
|
178
|
+
|
|
90
179
|
const app = express();
|
|
180
|
+
|
|
91
181
|
// Named import works; default import also works (`import miki from ...`)
|
|
182
|
+
|
|
92
183
|
setupExpress(app, { extension: 'html', views: './views' });
|
|
184
|
+
|
|
93
185
|
```
|
|
94
186
|
|
|
187
|
+
|
|
188
|
+
|
|
95
189
|
## Next Steps
|
|
96
190
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
- [
|
|
100
|
-
|
|
101
|
-
- [
|
|
102
|
-
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
- [What is miki-template?](./what-is-miki-template.md)
|
|
194
|
+
|
|
195
|
+
- [Why miki-template?](./why-miki-template.md)
|
|
196
|
+
|
|
197
|
+
- [Installation Guide](./installation.md)
|
|
198
|
+
|
|
199
|
+
- [Quick Start](./quick-start.md)
|
|
200
|
+
|
|
201
|
+
- [Template Syntax & Tags](./tags.md)
|
|
202
|
+
|
|
203
|
+
- [Filters](./filters.md)
|
|
204
|
+
|
|
@@ -1,95 +1,190 @@
|
|
|
1
|
-
# Installation
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
Complete guide to installing and verifying miki-template in different environments.
|
|
4
6
|
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
## Requirements
|
|
6
10
|
|
|
11
|
+
|
|
12
|
+
|
|
7
13
|
- **Node.js** 18.x or 20.x (Node 18+ required for `URL`, `fetch`, and other Web API globals used by the engine)
|
|
14
|
+
|
|
8
15
|
- **npm** 9+, **pnpm**, or **yarn**
|
|
16
|
+
|
|
9
17
|
- **Bun** (optional) — miki-template is fully compatible with Bun
|
|
10
18
|
|
|
19
|
+
|
|
20
|
+
|
|
11
21
|
## Install via npm
|
|
12
22
|
|
|
23
|
+
|
|
24
|
+
|
|
13
25
|
```bash
|
|
26
|
+
|
|
14
27
|
npm install miki-template
|
|
28
|
+
|
|
15
29
|
```
|
|
16
30
|
|
|
31
|
+
|
|
32
|
+
|
|
17
33
|
## Install via pnpm
|
|
18
34
|
|
|
35
|
+
|
|
36
|
+
|
|
19
37
|
```bash
|
|
38
|
+
|
|
20
39
|
pnpm add miki-template
|
|
40
|
+
|
|
21
41
|
```
|
|
22
42
|
|
|
43
|
+
|
|
44
|
+
|
|
23
45
|
## Install via yarn
|
|
24
46
|
|
|
47
|
+
|
|
48
|
+
|
|
25
49
|
```bash
|
|
50
|
+
|
|
26
51
|
yarn add miki-template
|
|
52
|
+
|
|
27
53
|
```
|
|
28
54
|
|
|
55
|
+
|
|
56
|
+
|
|
29
57
|
## Install via Bun
|
|
30
58
|
|
|
59
|
+
|
|
60
|
+
|
|
31
61
|
```bash
|
|
62
|
+
|
|
32
63
|
bun add miki-template
|
|
64
|
+
|
|
33
65
|
```
|
|
34
66
|
|
|
67
|
+
|
|
68
|
+
|
|
35
69
|
## Package.json `"type"` Considerations
|
|
36
70
|
|
|
71
|
+
|
|
72
|
+
|
|
37
73
|
miki-template ships a dual CommonJS/ESM package:
|
|
38
74
|
|
|
75
|
+
|
|
76
|
+
|
|
39
77
|
- **CommonJS** entry: `src/index.js` — importable via `require('miki-template')` or `import` (Node auto-detects the `import` condition).
|
|
78
|
+
|
|
40
79
|
- **ESM** entry: `src/esm.mjs` — importable via `import ... from 'miki-template'`.
|
|
41
80
|
|
|
81
|
+
|
|
82
|
+
|
|
42
83
|
| Your project uses | How to import |
|
|
84
|
+
|
|
43
85
|
|---|---|
|
|
86
|
+
|
|
44
87
|
| CommonJS (`"type": "commonjs"` or no `type` field) | `const miki = require('miki-template')` |
|
|
88
|
+
|
|
45
89
|
| ES Modules (`"type": "module"`) | `import miki from 'miki-template'` or `import { render } from 'miki-template'` |
|
|
90
|
+
|
|
46
91
|
| TypeScript /Bun | Same as ESM — `import` syntax works directly |
|
|
47
92
|
|
|
93
|
+
|
|
94
|
+
|
|
48
95
|
> **Tip:** If your project is ESM-only (no `"type"` field but using `.mjs` files), use named imports: `import { render, compile } from 'miki-template'`.
|
|
49
96
|
|
|
97
|
+
|
|
98
|
+
|
|
50
99
|
## Verifying the Installation
|
|
51
100
|
|
|
101
|
+
|
|
102
|
+
|
|
52
103
|
=== "CommonJS"
|
|
53
104
|
|
|
105
|
+
|
|
106
|
+
|
|
54
107
|
```javascript
|
|
108
|
+
|
|
55
109
|
const miki = require('miki-template');
|
|
110
|
+
|
|
56
111
|
console.log(miki.render('Hello {{ name }}!', { name: 'World' }));
|
|
112
|
+
|
|
57
113
|
// Output: Hello World!
|
|
114
|
+
|
|
58
115
|
```
|
|
59
116
|
|
|
117
|
+
|
|
118
|
+
|
|
60
119
|
=== "ES Modules"
|
|
61
120
|
|
|
121
|
+
|
|
122
|
+
|
|
62
123
|
```javascript
|
|
124
|
+
|
|
63
125
|
import { render } from 'miki-template';
|
|
126
|
+
|
|
64
127
|
console.log(render('Hello {{ name }}!', { name: 'World' }));
|
|
128
|
+
|
|
65
129
|
// Output: Hello World!
|
|
130
|
+
|
|
66
131
|
```
|
|
67
132
|
|
|
133
|
+
|
|
134
|
+
|
|
68
135
|
=== "Bun / TypeScript"
|
|
69
136
|
|
|
137
|
+
|
|
138
|
+
|
|
70
139
|
```typescript
|
|
140
|
+
|
|
71
141
|
import { render } from 'miki-template';
|
|
142
|
+
|
|
72
143
|
console.log(render('Hello {{ name }}!', { name: 'World' }));
|
|
144
|
+
|
|
73
145
|
// Output: Hello World!
|
|
146
|
+
|
|
74
147
|
```
|
|
75
148
|
|
|
149
|
+
|
|
150
|
+
|
|
76
151
|
## Troubleshooting
|
|
77
152
|
|
|
153
|
+
|
|
154
|
+
|
|
78
155
|
### "Cannot find module 'miki-template'"
|
|
79
156
|
|
|
157
|
+
|
|
158
|
+
|
|
80
159
|
Ensure the package is installed in the correct `node_modules` directory. If you're working in a monorepo, run `npm install` from the package root.
|
|
81
160
|
|
|
161
|
+
|
|
162
|
+
|
|
82
163
|
### Auto-escaping produces `&` where you expect `&`
|
|
83
164
|
|
|
165
|
+
|
|
166
|
+
|
|
84
167
|
This is by design — miki-template escapes all variables by default to prevent XSS. Use `|safe` or `markSafe()` for trusted HTML:
|
|
85
168
|
|
|
169
|
+
|
|
170
|
+
|
|
86
171
|
```html
|
|
172
|
+
|
|
87
173
|
{{ htmlContent|safe }}
|
|
174
|
+
|
|
88
175
|
```
|
|
89
176
|
|
|
90
|
-
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
See [Security](./security.md) for details.
|
|
180
|
+
|
|
181
|
+
|
|
91
182
|
|
|
92
183
|
## Next Steps
|
|
93
184
|
|
|
94
|
-
|
|
95
|
-
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
- [Quick Start](./quick-start.md)
|
|
188
|
+
|
|
189
|
+
- [What is miki-template?](./what-is-miki-template.md)
|
|
190
|
+
|