miki-template 2.0.1 → 2.2.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.
- package/.github/workflows/ci.yml +13 -37
- package/.github/workflows/docs.yml +105 -0
- package/.github/workflows/npm-publish-github-packages.yml +36 -0
- package/README.md +69 -14
- package/assets/logo.png +0 -0
- package/benchmarks/ejs-results.json +4 -4
- package/benchmarks/handlebars-results.json +6 -6
- package/benchmarks/miki-results.json +4 -4
- package/benchmarks/pug-results.json +4 -4
- package/benchmarks/stress.mjs +1 -1
- package/docs/api/async-render.md +85 -0
- package/docs/api/cache.md +87 -0
- package/docs/api/compile.md +128 -0
- package/docs/api/context-processors.md +77 -0
- package/docs/api/filters.md +217 -0
- package/docs/api/finder.md +94 -0
- package/docs/api/helpers.md +53 -0
- package/docs/api/i18n.md +157 -0
- package/docs/api/index.md +54 -0
- package/docs/api/libraries.md +207 -0
- package/docs/api/render-partial.md +81 -0
- package/docs/api/render.md +92 -0
- package/docs/api/security.md +145 -0
- package/docs/api/setup-express.md +76 -0
- package/docs/api/tags.md +134 -0
- package/docs/assets/banner.png +0 -0
- package/docs/assets/logo.png +0 -0
- package/docs/guide/advanced-usage.md +397 -0
- package/docs/guide/async-rendering.md +308 -0
- package/docs/guide/context-processors.md +257 -0
- package/docs/guide/custom-filters.md +311 -0
- package/docs/guide/custom-tags.md +271 -0
- package/docs/guide/filters.md +642 -0
- package/docs/guide/getting-started.md +102 -0
- package/docs/guide/installation.md +95 -0
- package/docs/guide/partial-templates.md +367 -0
- package/docs/guide/quick-start.md +222 -0
- package/docs/guide/security.md +345 -0
- package/docs/guide/tags.md +783 -0
- package/docs/guide/template-discovery.md +170 -0
- package/docs/guide/template-inheritance.md +273 -0
- package/docs/guide/what-is-miki-template.md +28 -0
- package/docs/guide/why-miki-template.md +75 -0
- package/docs/index.md +104 -0
- package/docs/integrations/elysia.md +78 -0
- package/docs/integrations/express.md +219 -0
- package/docs/integrations/fastify.md +77 -0
- package/docs/integrations/hono.md +78 -0
- package/docs/integrations/index.md +68 -0
- package/docs/integrations/koa.md +88 -0
- package/docs/integrations/nestjs.md +78 -0
- package/docs/integrations/tsed.md +81 -0
- package/docs/javascripts/extra.js +174 -0
- package/docs/performance.md +37 -0
- package/docs/stylesheets/extra.css +819 -0
- package/mkdocs.yml +217 -0
- package/overrides/main.html +26 -0
- package/overrides/partials/footer.html +9 -0
- package/package.json +4 -2
- package/requirements-docs.txt +1 -0
- package/docs/README.md +0 -18
- package/docs/advanced_usage.md +0 -71
- package/docs/api.md +0 -122
- package/docs/filters.md +0 -708
- package/docs/installation.md +0 -106
- package/docs/integrations.md +0 -214
- package/docs/overview.md +0 -79
- package/docs/partialdef.md +0 -70
- package/docs/security.md +0 -27
- package/docs/tags.md +0 -673
- package/docs/usage.md +0 -646
package/mkdocs.yml
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
site_name: miki-template
|
|
2
|
+
site_url: https://alainmiki.github.io/miki-template/
|
|
3
|
+
site_description: Django-style template engine for Node.js and Express
|
|
4
|
+
site_author: Alain Miki
|
|
5
|
+
|
|
6
|
+
repo_name: miki-template
|
|
7
|
+
repo_url: https://github.com/alainmiki/miki-template
|
|
8
|
+
edit_uri: edit/main/docs/
|
|
9
|
+
|
|
10
|
+
theme:
|
|
11
|
+
name: material
|
|
12
|
+
custom_dir: overrides
|
|
13
|
+
logo: assets/logo.png
|
|
14
|
+
favicon: assets/logo.png
|
|
15
|
+
palette:
|
|
16
|
+
- media: "(prefers-color-scheme: light)"
|
|
17
|
+
scheme: default
|
|
18
|
+
primary: custom
|
|
19
|
+
accent: custom
|
|
20
|
+
toggle:
|
|
21
|
+
icon: material/brightness-7
|
|
22
|
+
name: Switch to dark mode
|
|
23
|
+
- media: "(prefers-color-scheme: dark)"
|
|
24
|
+
scheme: custom
|
|
25
|
+
primary: custom
|
|
26
|
+
accent: custom
|
|
27
|
+
toggle:
|
|
28
|
+
icon: material/brightness-4
|
|
29
|
+
name: Switch to light mode
|
|
30
|
+
font:
|
|
31
|
+
text: Inter
|
|
32
|
+
code: JetBrains Mono
|
|
33
|
+
features:
|
|
34
|
+
- navigation.instant
|
|
35
|
+
- navigation.instant.prefetch
|
|
36
|
+
- navigation.instant.progress
|
|
37
|
+
- navigation.tracking
|
|
38
|
+
- navigation.tabs
|
|
39
|
+
- navigation.tabs.sticky
|
|
40
|
+
- navigation.sections
|
|
41
|
+
- navigation.path
|
|
42
|
+
- navigation.top
|
|
43
|
+
- navigation.footer
|
|
44
|
+
- navigation.prune
|
|
45
|
+
- navigation.indexes
|
|
46
|
+
- toc.integrate
|
|
47
|
+
- toc.follow
|
|
48
|
+
- search.suggest
|
|
49
|
+
- search.highlight
|
|
50
|
+
- content.code.copy
|
|
51
|
+
- announce.dismiss
|
|
52
|
+
icon:
|
|
53
|
+
repo: fontawesome/brands/github
|
|
54
|
+
admonition:
|
|
55
|
+
note: fontawesome/solid/note-sticky
|
|
56
|
+
abstract: fontawesome/solid/book-open
|
|
57
|
+
info: fontawesome/solid/circle-info
|
|
58
|
+
tip: fontawesome/solid/lightbulb
|
|
59
|
+
success: fontawesome/solid/check-circle
|
|
60
|
+
question: fontawesome/solid/question-circle
|
|
61
|
+
warning: fontawesome/solid/triangle-exclamation
|
|
62
|
+
failure: fontawesome/solid/circle-xmark
|
|
63
|
+
danger: fontawesome/solid/skull
|
|
64
|
+
bug: fontawesome/solid/robot
|
|
65
|
+
example: fontawesome/solid/flask
|
|
66
|
+
quote: fontawesome/solid/quote-left
|
|
67
|
+
|
|
68
|
+
nav:
|
|
69
|
+
- Home: index.md
|
|
70
|
+
- Getting Started:
|
|
71
|
+
- What is miki-template?: guide/what-is-miki-template.md
|
|
72
|
+
- Why miki-template?: guide/why-miki-template.md
|
|
73
|
+
- Getting Started: guide/getting-started.md
|
|
74
|
+
- Installation: guide/installation.md
|
|
75
|
+
- Quick Start: guide/quick-start.md
|
|
76
|
+
- Core Features:
|
|
77
|
+
- Partial Templates: guide/partial-templates.md
|
|
78
|
+
- Smart Template Discovery: guide/template-discovery.md
|
|
79
|
+
- Template Inheritance: guide/template-inheritance.md
|
|
80
|
+
- Filters: guide/filters.md
|
|
81
|
+
- Tags: guide/tags.md
|
|
82
|
+
- Security: guide/security.md
|
|
83
|
+
- Advanced:
|
|
84
|
+
- Custom Tags: guide/custom-tags.md
|
|
85
|
+
- Custom Filters: guide/custom-filters.md
|
|
86
|
+
- Context Processors: guide/context-processors.md
|
|
87
|
+
- Async Rendering: guide/async-rendering.md
|
|
88
|
+
- Advanced Usage: guide/advanced-usage.md
|
|
89
|
+
- API Reference:
|
|
90
|
+
- API Overview: api/index.md
|
|
91
|
+
- render(): api/render.md
|
|
92
|
+
- compile(): api/compile.md
|
|
93
|
+
- asyncRender(): api/async-render.md
|
|
94
|
+
- renderPartial(): api/render-partial.md
|
|
95
|
+
- setupExpress(): api/setup-express.md
|
|
96
|
+
- Filters: api/filters.md
|
|
97
|
+
- Tags: api/tags.md
|
|
98
|
+
- Security: api/security.md
|
|
99
|
+
- i18n: api/i18n.md
|
|
100
|
+
- Libraries: api/libraries.md
|
|
101
|
+
- Cache: api/cache.md
|
|
102
|
+
- Finder: api/finder.md
|
|
103
|
+
- Helpers: api/helpers.md
|
|
104
|
+
- Context Processors: api/context-processors.md
|
|
105
|
+
- Integrations:
|
|
106
|
+
- Integrations Overview: integrations/index.md
|
|
107
|
+
- Express: integrations/express.md
|
|
108
|
+
- Koa: integrations/koa.md
|
|
109
|
+
- Fastify: integrations/fastify.md
|
|
110
|
+
- Hono: integrations/hono.md
|
|
111
|
+
- Elysia: integrations/elysia.md
|
|
112
|
+
- NestJS: integrations/nestjs.md
|
|
113
|
+
- TSDX / TSed: integrations/tsed.md
|
|
114
|
+
- Performance: performance.md
|
|
115
|
+
|
|
116
|
+
markdown_extensions:
|
|
117
|
+
- abbr
|
|
118
|
+
- admonition
|
|
119
|
+
- attr_list
|
|
120
|
+
- def_list
|
|
121
|
+
- footnotes
|
|
122
|
+
- meta
|
|
123
|
+
- toc:
|
|
124
|
+
permalink: true
|
|
125
|
+
title: On this page
|
|
126
|
+
- pymdownx.arithmatex:
|
|
127
|
+
generic: true
|
|
128
|
+
- pymdownx.betterem:
|
|
129
|
+
smart_enable: all
|
|
130
|
+
- pymdownx.caret
|
|
131
|
+
- pymdownx.details
|
|
132
|
+
- pymdownx.emoji:
|
|
133
|
+
emoji_index: !!python/name:material.extensions.emoji.twemoji
|
|
134
|
+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
|
|
135
|
+
- pymdownx.highlight:
|
|
136
|
+
anchor_linenums: true
|
|
137
|
+
line_spans: __span
|
|
138
|
+
pygments_lang_class: true
|
|
139
|
+
- pymdownx.inlinehilite
|
|
140
|
+
- pymdownx.keys
|
|
141
|
+
- pymdownx.mark
|
|
142
|
+
- pymdownx.smartsymbols
|
|
143
|
+
- pymdownx.superfences:
|
|
144
|
+
custom_fences:
|
|
145
|
+
- name: mermaid
|
|
146
|
+
class: mermaid
|
|
147
|
+
format: !!python/name:pymdownx.superfences.fence_code_format
|
|
148
|
+
- pymdownx.tabbed:
|
|
149
|
+
alternate_style: true
|
|
150
|
+
- pymdownx.tasklist:
|
|
151
|
+
custom_checkbox: true
|
|
152
|
+
- pymdownx.tilde
|
|
153
|
+
- material.extensions.emoji:
|
|
154
|
+
options:
|
|
155
|
+
custom_icons:
|
|
156
|
+
- overrides/.icons
|
|
157
|
+
- material.extensions.tabbed
|
|
158
|
+
- material.extensions.anchor
|
|
159
|
+
- material.extensions.details
|
|
160
|
+
- material.extensions.superfences
|
|
161
|
+
- material.extensions.magic-link:
|
|
162
|
+
repo_url_shorthand: true
|
|
163
|
+
user: alainmiki
|
|
164
|
+
repo: miki-template
|
|
165
|
+
|
|
166
|
+
extra:
|
|
167
|
+
social:
|
|
168
|
+
- icon: fontawesome/brands/github
|
|
169
|
+
link: https://github.com/alainmiki/miki-template
|
|
170
|
+
name: miki-template on GitHub
|
|
171
|
+
- icon: fontawesome/brands/npm
|
|
172
|
+
link: https://www.npmjs.com/package/miki-template
|
|
173
|
+
name: miki-template on npm
|
|
174
|
+
- icon: fontawesome/brands/youtube
|
|
175
|
+
link: https://youtube.com/@codewithmiki6849
|
|
176
|
+
name: Code with Miki on YouTube
|
|
177
|
+
- icon: fontawesome/brands/facebook
|
|
178
|
+
link: https://www.facebook.com/profile.php?id=100063798107667
|
|
179
|
+
name: Alain Miki on Facebook
|
|
180
|
+
- icon: fontawesome/brands/instagram
|
|
181
|
+
link: https://www.instagram.com/alain_miki
|
|
182
|
+
name: Alain Miki on Instagram
|
|
183
|
+
- icon: fontawesome/brands/facebook
|
|
184
|
+
link: https://www.facebook.com/codewithmiki
|
|
185
|
+
name: Code with Miki on Facebook
|
|
186
|
+
version:
|
|
187
|
+
provider: mike
|
|
188
|
+
homepage: https://alainmiki.github.io/miki-template/
|
|
189
|
+
generator: false
|
|
190
|
+
annotate:
|
|
191
|
+
json: [.s2s]
|
|
192
|
+
|
|
193
|
+
plugins:
|
|
194
|
+
- search:
|
|
195
|
+
separator: '[\s\-,:!=\[\]()"`/]+|\.(?!\d)|&[lg]t;|(?!\b)(?=[A-Z][a-z])'
|
|
196
|
+
- tags
|
|
197
|
+
- meta
|
|
198
|
+
- offline:
|
|
199
|
+
enabled: !ENV [READTHEDOCS, false]
|
|
200
|
+
- social:
|
|
201
|
+
cards: true
|
|
202
|
+
cards_layout_options:
|
|
203
|
+
color: "#1a1a2e"
|
|
204
|
+
font_family: Roboto
|
|
205
|
+
- optimize:
|
|
206
|
+
enabled: !ENV [READTHEDOCS, false]
|
|
207
|
+
concurrency: 4
|
|
208
|
+
css:
|
|
209
|
+
transpile: true
|
|
210
|
+
js:
|
|
211
|
+
bundle: true
|
|
212
|
+
|
|
213
|
+
extra_css:
|
|
214
|
+
- stylesheets/extra.css
|
|
215
|
+
|
|
216
|
+
extra_javascript:
|
|
217
|
+
- javascripts/extra.js
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{% extends "base.html" %}
|
|
2
|
+
|
|
3
|
+
{% block announce %}
|
|
4
|
+
<div class="md-announce" role="banner">
|
|
5
|
+
<div class="md-announce__inner">
|
|
6
|
+
<span>🚀 <strong>miki-template v2.0</strong> is now available with improved performance and new features!</span>
|
|
7
|
+
<a href="https://github.com/alainmiki/miki-template/releases" target="_blank" rel="noopener">View Release Notes</a>
|
|
8
|
+
<button class="md-announce__button" onclick="this.closest('.md-announce').remove()" aria-label="Dismiss announcement">
|
|
9
|
+
<span class="md-icon">✕</span>
|
|
10
|
+
</button>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
{% endblock %}
|
|
14
|
+
|
|
15
|
+
{% block extrahead %}
|
|
16
|
+
<meta name="theme-color" content="#1a1a2e">
|
|
17
|
+
<meta name="description" content="Django-style template magic for Node.js — blazing fast partials, smart template discovery, and zero friction for HTMX.">
|
|
18
|
+
<meta property="og:title" content="miki-template - Django-style templating for Node.js">
|
|
19
|
+
<meta property="og:description" content="Blazing fast partials, smart template discovery, and zero friction for HTMX. Bring Django's beloved template language to Node.js and Express.">
|
|
20
|
+
<meta property="og:type" content="website">
|
|
21
|
+
<meta property="og:url" content="https://alainmiki.github.io/miki-template/">
|
|
22
|
+
<meta property="og:image" content="https://alainmiki.github.io/miki-template/social-card.png">
|
|
23
|
+
<meta name="twitter:card" content="summary_large_image">
|
|
24
|
+
<meta name="twitter:title" content="miki-template - Django-style templating for Node.js">
|
|
25
|
+
<meta name="twitter:description" content="Blazing fast partials, smart template discovery, and zero friction for HTMX.">
|
|
26
|
+
{% endblock %}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{% extends "partials/footer.html" %}
|
|
2
|
+
|
|
3
|
+
{% block copyright %}
|
|
4
|
+
Copyright © 2024 - 2026 <a href="https://github.com/alainmiki">Alain Miki</a>
|
|
5
|
+
{% endblock %}
|
|
6
|
+
|
|
7
|
+
{% block generator %}
|
|
8
|
+
Made with <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">Material for MkDocs</a>
|
|
9
|
+
{% endblock %}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miki-template",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Django-Style template engine for Node.js and Express",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"fastify",
|
|
23
23
|
"nestjs"
|
|
24
24
|
],
|
|
25
|
-
"author": "",
|
|
25
|
+
"author": "Alain Miki aka Coder Miki",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"date-fns": "^3.6.0",
|
|
@@ -41,6 +41,8 @@
|
|
|
41
41
|
"test": "node -e \"const fs=require('fs');const path=require('path');function walk(d){const out=[];for(const e of fs.readdirSync(d,{withFileTypes:true})){const p=path.join(d,e.name);if(e.isDirectory())out.push(...walk(p));else if(/\\\\.test\\\\.(cjs|mjs|js)$/.test(e.name))out.push(p);}return out;}const files=walk('tests');require('child_process').execSync('node --test '+files.join(' '),{stdio:'inherit'})\"",
|
|
42
42
|
"lint": "eslint . -f unix",
|
|
43
43
|
"bench": "node benchmarks/run.js",
|
|
44
|
+
"docs:build": "mkdocs build",
|
|
45
|
+
"docs:serve": "mkdocs serve",
|
|
44
46
|
"release:patch": "npm version patch --no-git-tag-version -m \"chore(release): v%s\" && git push origin main",
|
|
45
47
|
"release:minor": "npm version minor --no-git-tag-version -m \"chore(release): v%s\" && git push origin main",
|
|
46
48
|
"release:major": "npm version major --no-git-tag-version -m \"chore(release): v%s\" && git push origin main"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mkdocs-material[imaging]>=9.5
|
package/docs/README.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Documentation Index
|
|
2
|
-
|
|
3
|
-
Welcome to the **miki-template** documentation hub. Below is a quick navigation guide to all docs.
|
|
4
|
-
|
|
5
|
-
| Document | Description |
|
|
6
|
-
|---|---|
|
|
7
|
-
| [overview.md](overview.md) | High‑level project overview and repository layout |
|
|
8
|
-
| [installation.md](installation.md) | How to install the package and prerequisites |
|
|
9
|
-
| [usage.md](usage.md) | Basic API usage, rendering, compilation, and block rendering |
|
|
10
|
-
| [tags.md](tags.md) | Reference for every built‑in tag (`if`, `for`, `partialdef`, etc.) |
|
|
11
|
-
| [filters.md](filters.md) | Comprehensive list of built‑in filters with examples |
|
|
12
|
-
| [partialdef.md](partialdef.md) | Detailed guide for the `partialdef` feature (including inline, nesting, API) |
|
|
13
|
-
| [security.md](security.md) | Security considerations (auto‑escaping, CSP, CSRF) |
|
|
14
|
-
| [api.md](api.md) | Low‑level API surface – `compile`, `renderPartial`, `registerTag`, etc. |
|
|
15
|
-
| [contributing.md](contributing.md) | Guidelines for contributing, pull‑request flow, and code style |
|
|
16
|
-
| [roadmap.md](roadmap.md) | Future milestones and release schedule |
|
|
17
|
-
|
|
18
|
-
All files are located under `c:/Users/Coder Miki/Desktop/miki-template/docs/`.
|
package/docs/advanced_usage.md
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# Advanced Usage
|
|
2
|
-
|
|
3
|
-
This document showcases real‑world examples of the **miki‑template** engine.
|
|
4
|
-
|
|
5
|
-
## 1. Partial Definition & Inclusion
|
|
6
|
-
```django
|
|
7
|
-
{% partialdef "header" %}
|
|
8
|
-
<header>
|
|
9
|
-
<h1>{{ site.title }}</h1>
|
|
10
|
-
</header>
|
|
11
|
-
{% endpartialdef %}
|
|
12
|
-
|
|
13
|
-
{% include "header" %}
|
|
14
|
-
```
|
|
15
|
-
*Result:* Renders a reusable header component.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
## 2. Custom Tag Helper – Markdown
|
|
19
|
-
```js
|
|
20
|
-
const { registerHelper } = require('./src/tags/helpers');
|
|
21
|
-
const markdownIt = require('markdown-it')();
|
|
22
|
-
registerHelper('markdown', (content) => markdownIt.render(content));
|
|
23
|
-
```
|
|
24
|
-
```django
|
|
25
|
-
{% markdown %}
|
|
26
|
-
# Hello World
|
|
27
|
-
* Item 1
|
|
28
|
-
* Item 2
|
|
29
|
-
{% endmarkdown %}
|
|
30
|
-
```
|
|
31
|
-
*Result:* Converts markdown to HTML on‑the‑fly.
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
## 3. Async Rendering with a Sleep Helper
|
|
35
|
-
```js
|
|
36
|
-
registerHelper('sleep', async (content) => {
|
|
37
|
-
await new Promise(r => setTimeout(r, 50));
|
|
38
|
-
return `Awake after ${content}`;
|
|
39
|
-
});
|
|
40
|
-
```
|
|
41
|
-
```django
|
|
42
|
-
{% sleep %}50ms{% endsleep %}
|
|
43
|
-
```
|
|
44
|
-
```js
|
|
45
|
-
const { asyncRender } = require('./src');
|
|
46
|
-
asyncRender(template, {} ).then(console.log);
|
|
47
|
-
```
|
|
48
|
-
*Result:* `Awake after 50ms`
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
## 4. Extended Date Formatting
|
|
52
|
-
```django
|
|
53
|
-
{{ now|date_format:"yyyy-MM-dd HH:mm:ss" }}
|
|
54
|
-
```
|
|
55
|
-
*Result:* `2026-08-29 13:48:07`
|
|
56
|
-
### Additional Date Filter Examples
|
|
57
|
-
|
|
58
|
-
```django
|
|
59
|
-
{{ now|strftime:"PPpp" }} {# Full date-fns pattern #}
|
|
60
|
-
{{ now|date:"Y-m-d H:i:s" }} {# Django style with seconds #}
|
|
61
|
-
{{ now|time:"H:i:s" }} {# Time only #}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
*Result:* Example outputs will appear when rendered.
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
## 5. Performance Benchmark (see `benchmarks/run.js`)
|
|
68
|
-
The benchmark renders three template sizes (small, medium, large) synchronously and asynchronously, reporting average render time and cache hit ratio.
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
> **Tip:** All examples work with the default Express integration via `app.engine('dtpl', require('miki-template').__express);`
|
package/docs/api.md
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
# API Reference
|
|
2
|
-
|
|
3
|
-
This document lists the public API exported by **miki-template** for developers to integrate the engine into their projects.
|
|
4
|
-
|
|
5
|
-
| Function / Export | Signature | Description | Example |
|
|
6
|
-
|---|---|---|---|
|
|
7
|
-
| `compile(templateStr, options?)` | `compile(string, object?) → { render, asyncRender, renderBlock, renderPartial }` | Compiles a template string into a renderable object. Optional `options` can include `views` directories, custom tags/filters, etc. | `const tpl = compile('Hello {{ name }}');` |
|
|
8
|
-
| `render(templateStr, context?, options?)` | `render(string, object?, object?) → string` | One‑off rendering of a template string with the provided context. | `render('Hello {{ name }}', { name: 'World' });` |
|
|
9
|
-
| `asyncRender(templateStr, context?, options?)` | `asyncRender(string, object?, object?) → Promise<string>` | Asynchronous rendering (useful with async helpers). | `await asyncRender(tpl, ctx);` |
|
|
10
|
-
| `__express(filePath, options, callback)` | `__express(string, object, function)` | Express view engine adapter – reads the file at `filePath` and renders it. Honors `view#partial` suffixes for HTMX-style partial responses. | `app.engine('html', miki.__express);` |
|
|
11
|
-
| `__expressAsync(filePath, options)` | `__expressAsync(string, object) → Promise<string>` | Async Express 5+ view engine adapter. Returns a Promise that resolves to rendered HTML. Also honors `view#partial` suffixes. | `app.engine('html', miki.__expressAsync);` |
|
|
12
|
-
| `express(options?)` | `express(object?) → function` | Factory that returns a view-engine function suitable for `app.engine(...)`. Honors `view#partial` selectors. | `app.engine('html', miki.express());` |
|
|
13
|
-
| `setupExpress(app, opts?)` | `setupExpress(expressApp, object?) → void` | **One-line Express integration.** Wires `app.engine(...)`, `app.set('views')`, and patches `res.render` so `res.render('view#partial', ...)` returns just that partial. Options: `{ extension?, views?, async? }`. | `miki.setupExpress(app, { extension: 'html', views: './views' });` |
|
|
14
|
-
| `expressPartialRenderer()` | `expressPartialRenderer() → function` | Express middleware that adds `res.renderPartial(view, locals)`. Useful as a drop-in HTMX helper without the full `setupExpress` shim. | `app.use(miki.expressPartialRenderer());` |
|
|
15
|
-
| `findTemplateInViews(name, viewsDirs)` | `findTemplateInViews(string, string[]|string) → string|null` | Search for a template by name across one or more `views` roots. Performs direct resolution first (supports explicit paths and extensions), then a recursive search for bare filenames in subdirectories. Returns the absolute file path or `null` if not found. | `miki.findTemplateInViews('detail', ['./views', './templates'])` |
|
|
16
|
-
| `setAppTemplateDirNames(names)` | `setAppTemplateDirNames(string[]|string) → void` | Configure which directory names are treated as app-style template folders when scanning (default: `['templates']`). Useful when projects use a different convention. | `miki.setAppTemplateDirNames(['templates','app_templates'])` |
|
|
17
|
-
| `getAppTemplateDirNames()` | `getAppTemplateDirNames() → string[]` | Retrieve the current configured app-template directory names. | `const names = miki.getAppTemplateDirNames()` |
|
|
18
|
-
| `renderPartialFromFile(filePath, partialName, context?, options?)` | `renderPartialFromFile(string, string, object?, object?) → string` | Load a file from disk and render only the named `{% partialdef %}`. | `miki.renderPartialFromFile('views/home.html', 'card', { user });` |
|
|
19
|
-
| `renderPartialFromSource(source, partialName, context?, options?)` | `renderPartialFromSource(string, string, object?, object?) → string` | Render a single named partial directly from a template string. Walks the AST (and `extends` chain) to discover partials nested inside blocks. | `miki.renderPartialFromSource(src, 'card', ctx, { views });` |
|
|
20
|
-
| `stripExpressContext(options)` | `stripExpressContext(object) → object` | Remove Express framework keys (`_locals`, `settings`, `cache`) from an options object. | `const ctx = stripExpressContext(res.locals);` |
|
|
21
|
-
| `clearCache()` | `clearCache() → void` | Clear the in-memory compiled template cache. | `clearCache();` |
|
|
22
|
-
| `registerTag(name, parserFn)` | `registerTag(string, function)` | Register a custom tag parser. Must be called before compiling templates. | `registerTag('mytag', parserFn);` |
|
|
23
|
-
| `registerFilter(name, fn)` | `registerFilter(string, function)` | Register a custom filter. | `registerFilter('reverse', str => str.split('').reverse().join(''));` |
|
|
24
|
-
| `getFilter(name)` | `getFilter(string) → function` | Retrieve a registered filter function by name. | `const upper = getFilter('upper');` |
|
|
25
|
-
| `registerHelper(name, fn)` | `registerHelper(string, function)` | Register a helper function available inside templates. | `registerHelper('upper', s => s.toUpperCase());` |
|
|
26
|
-
| `registerContextProcessor(fn)` | `registerContextProcessor(function)` | Add a context processor that mutates the rendering context before each render. | `registerContextProcessor(ctx => ({ ...ctx, csrf_token: '123' }));` |
|
|
27
|
-
| `registerTranslation(lang, messages)` | `registerTranslation(string, object) → void` | Register translation messages for a language. | `registerTranslation('fr', { 'Hello': 'Bonjour' });` |
|
|
28
|
-
| `setLanguage(lang)` | `setLanguage(string) → void` | Set the active language for all subsequent renders. | `setLanguage('fr');` |
|
|
29
|
-
| `getLanguage()` | `getLanguage() → string` | Get the currently active language. | `const lang = getLanguage();` |
|
|
30
|
-
| `setFallbackLanguage(lang)` | `setFallbackLanguage(string) → void` | Set the fallback language for missing translations. | `setFallbackLanguage('en');` |
|
|
31
|
-
| `getAvailableLanguages()` | `getAvailableLanguages() → string[]` | List all registered language codes. | `const langs = getAvailableLanguages();` |
|
|
32
|
-
| `registerLibrary(name, def)` | `registerLibrary(string, object) → void` | Register a plugin library of tags, filters, and helpers. | `registerLibrary('humanize', { filters: { intcomma } });` |
|
|
33
|
-
| `registerLibraryFromPath(name, path)` | `registerLibraryFromPath(string, string) → object` | Load a library from a JS file on disk. | `registerLibraryFromPath('myLib', './libs/my-lib.js');` |
|
|
34
|
-
| `activateLibrary(name)` | `activateLibrary(string) → void` | Activate a registered library (makes its tags/filters available). | `activateLibrary('humanize');` |
|
|
35
|
-
| `SafeString` | `class SafeString` | Wrapper class for values that should bypass auto‑escaping. Returned by `markSafe`. |
|
|
36
|
-
| `markSafe(value)` | `markSafe(any) → SafeString` | Marks a value as safe, preventing HTML escaping. |
|
|
37
|
-
| `isSafe(value)` | `isSafe(any) → boolean` | Checks if a value is a `SafeString`. |
|
|
38
|
-
| `escapeHtml(str)` | `escapeHtml(string) → string` | Escapes HTML special characters. Used internally for auto‑escaping. |
|
|
39
|
-
|
|
40
|
-
All of the above are exported from `src/index.js` and can be imported via:
|
|
41
|
-
|
|
42
|
-
### CommonJS
|
|
43
|
-
```js
|
|
44
|
-
const {
|
|
45
|
-
compile,
|
|
46
|
-
render,
|
|
47
|
-
asyncRender,
|
|
48
|
-
__express,
|
|
49
|
-
__expressAsync,
|
|
50
|
-
express,
|
|
51
|
-
setupExpress,
|
|
52
|
-
expressPartialRenderer,
|
|
53
|
-
renderPartialFromFile,
|
|
54
|
-
renderPartialFromSource,
|
|
55
|
-
stripExpressContext,
|
|
56
|
-
clearCache,
|
|
57
|
-
registerTag,
|
|
58
|
-
registerFilter,
|
|
59
|
-
getFilter,
|
|
60
|
-
registerHelper,
|
|
61
|
-
registerContextProcessor,
|
|
62
|
-
clearContextProcessors,
|
|
63
|
-
registerTranslation,
|
|
64
|
-
setLanguage,
|
|
65
|
-
getLanguage,
|
|
66
|
-
setFallbackLanguage,
|
|
67
|
-
getAvailableLanguages,
|
|
68
|
-
registerLibrary,
|
|
69
|
-
registerLibraryFromPath,
|
|
70
|
-
activateLibrary,
|
|
71
|
-
SafeString,
|
|
72
|
-
markSafe,
|
|
73
|
-
isSafe,
|
|
74
|
-
escapeHtml
|
|
75
|
-
} = require('miki-template');
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### ES Modules (ESM)
|
|
79
|
-
```js
|
|
80
|
-
import {
|
|
81
|
-
compile,
|
|
82
|
-
render,
|
|
83
|
-
asyncRender,
|
|
84
|
-
__express,
|
|
85
|
-
__expressAsync,
|
|
86
|
-
express,
|
|
87
|
-
setupExpress,
|
|
88
|
-
expressPartialRenderer,
|
|
89
|
-
renderPartialFromFile,
|
|
90
|
-
renderPartialFromSource,
|
|
91
|
-
stripExpressContext,
|
|
92
|
-
clearCache,
|
|
93
|
-
registerTag,
|
|
94
|
-
registerFilter,
|
|
95
|
-
getFilter,
|
|
96
|
-
registerHelper,
|
|
97
|
-
registerContextProcessor,
|
|
98
|
-
clearContextProcessors,
|
|
99
|
-
registerTranslation,
|
|
100
|
-
setLanguage,
|
|
101
|
-
getLanguage,
|
|
102
|
-
setFallbackLanguage,
|
|
103
|
-
getAvailableLanguages,
|
|
104
|
-
registerLibrary,
|
|
105
|
-
registerLibraryFromPath,
|
|
106
|
-
activateLibrary,
|
|
107
|
-
SafeString,
|
|
108
|
-
markSafe,
|
|
109
|
-
isSafe,
|
|
110
|
-
escapeHtml
|
|
111
|
-
} from 'miki-template';
|
|
112
|
-
|
|
113
|
-
// Or import all as default
|
|
114
|
-
import miki from 'miki-template';
|
|
115
|
-
const { render: mikiRender, setupExpress } = miki;
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
For detailed usage, refer to the corresponding sections in the documentation:
|
|
119
|
-
- **Usage** – `docs/usage.md`
|
|
120
|
-
- **Tags** – `docs/tags.md`
|
|
121
|
-
- **Filters** – `docs/filters.md`
|
|
122
|
-
- **Security** – `docs/security.md`
|