miki-template 1.3.6 → 1.3.7
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/.eslintrc.json +16 -0
- package/docs/overview.md +22 -0
- package/ex.mjs +2 -0
- package/live-test/package-lock.json +915 -0
- package/live-test/package.json +9 -0
- package/live-test/server.js +14 -0
- package/live-test/views/base.html +8 -0
- package/live-test/views/child.html +7 -0
- package/live-test/views/index.html +1 -0
- package/miki-template-extension/extension.js +3 -3
- package/package.json +12 -9
- package/src/esm.mjs +5 -0
- package/src/index.js +141 -3
- package/tests/finder-appdirs.test.js +19 -0
- package/tests/finder.test.js +17 -0
- package/tests/fixtures/views/nested/index.html +1 -0
- package/tests/fixtures/views/partial.html +1 -0
- package/tests/fixtures/views/sub/deepfile.html +1 -0
- package/tests/fixtures/views-appdirs/product/site/detail.html +1 -0
- package/tests/integration/finder.esm.test.mjs +13 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"node": true,
|
|
4
|
+
"es2024": true
|
|
5
|
+
},
|
|
6
|
+
"extends": "eslint:recommended",
|
|
7
|
+
"parserOptions": {
|
|
8
|
+
"ecmaVersion": "latest",
|
|
9
|
+
"sourceType": "module"
|
|
10
|
+
},
|
|
11
|
+
"rules": {
|
|
12
|
+
"no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
|
|
13
|
+
"no-console": "off",
|
|
14
|
+
"semi": ["error", "always"]
|
|
15
|
+
}
|
|
16
|
+
}
|
package/docs/overview.md
CHANGED
|
@@ -44,6 +44,28 @@ Each module is deliberately **single‑responsibility** and fully typed via JSDo
|
|
|
44
44
|
- **Partial definitions** – see `docs/partialdef.md`.
|
|
45
45
|
- **Security considerations** – see `docs/security.md`.
|
|
46
46
|
|
|
47
|
+
## Recursive and app-style template discovery
|
|
48
|
+
|
|
49
|
+
`miki-template` now supports Django-style recursive template discovery. When you configure your views directory (via `miki.setupExpress(app, { views: './views' })` or by passing `views` to `render()`), the engine will:
|
|
50
|
+
|
|
51
|
+
- Resolve direct paths like `nested/index` relative to each `views` directory.
|
|
52
|
+
- If a bare template name (e.g. `card`) is used, recursively scan subfolders of the configured `views` directories to find `card.html` or `card.miki`.
|
|
53
|
+
- Discover app-style `templates` directories located under application packages (e.g. `project/apps/product/templates/...`) and include them in the search.
|
|
54
|
+
|
|
55
|
+
Configuration:
|
|
56
|
+
|
|
57
|
+
- Programmatically set which folder names should be treated as app template roots via the API:
|
|
58
|
+
|
|
59
|
+
- `setAppTemplateDirNames(['templates', 'site_templates'])` — sets the list of folder names that will be discovered under the views root.
|
|
60
|
+
- `getAppTemplateDirNames()` — returns the current list.
|
|
61
|
+
|
|
62
|
+
Examples:
|
|
63
|
+
|
|
64
|
+
- `render('home#card', ctx, { views: './views' })` will search `./views` and any `templates/` subfolders for `home.html` or `home.miki`, and render the `card` partial.
|
|
65
|
+
- If your project places templates under `packages/product/templates/detail.html`, `render('detail', ..., { views: './views' })` will find it automatically.
|
|
66
|
+
|
|
67
|
+
This behavior is opt‑out by simply clearing the app-dir names: `setAppTemplateDirNames([])` will disable app-style discovery.
|
|
68
|
+
|
|
47
69
|
For API‑level details (e.g., `compile().renderPartial`) check `docs/api.md`.
|
|
48
70
|
|
|
49
71
|
---
|
package/ex.mjs
CHANGED
|
@@ -10,6 +10,8 @@ const dir=path.join(process.cwd(),"dir")
|
|
|
10
10
|
// app.set('views', dir);
|
|
11
11
|
miki.setupExpress(app, { extension: 'html', views: dir });
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
|
|
13
15
|
// registerContextProcessor((cx)=>({
|
|
14
16
|
// siteName:"code with miki",
|
|
15
17
|
// login:{'name':"miki", 'email':"miki@example.com"}
|