miki-template 1.3.3 → 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.
Files changed (115) hide show
  1. package/.eslintrc.json +16 -0
  2. package/.github/release-notes/v1.3.1.md +55 -55
  3. package/.github/release-notes/v1.3.3.md +77 -0
  4. package/.github/workflows/ci.yml +38 -54
  5. package/.github/workflows/release.yml +106 -0
  6. package/AGENT.md +71 -71
  7. package/API_REFERENCE.md +314 -314
  8. package/CHANGELOG.md +173 -169
  9. package/CODE_OF_CONDUCT.md +14 -14
  10. package/CONTRIBUTING.md +27 -27
  11. package/README.md +342 -321
  12. package/ROADMAP.md +40 -40
  13. package/benchmarks/report.json +16 -16
  14. package/benchmarks/run.js +49 -49
  15. package/benchmarks/stress.mjs +647 -647
  16. package/benchmarks/templates/large.dtpl +7 -7
  17. package/benchmarks/templates/medium.dtpl +3 -3
  18. package/benchmarks/templates/small.dtpl +7 -7
  19. package/context/component.md +109 -109
  20. package/context/prd.md +131 -131
  21. package/context/project-structure.md +33 -33
  22. package/dir/base.html +22 -22
  23. package/dir/cmpnt.html +10 -10
  24. package/dir/footer.html +2 -2
  25. package/dir/home.html +80 -80
  26. package/dir/index.html +80 -0
  27. package/dir/navbar.html +8 -8
  28. package/docs/README.md +18 -18
  29. package/docs/advanced_usage.md +71 -71
  30. package/docs/api.md +119 -119
  31. package/docs/filters.md +708 -708
  32. package/docs/installation.md +106 -106
  33. package/docs/overview.md +79 -57
  34. package/docs/partialdef.md +70 -70
  35. package/docs/security.md +27 -27
  36. package/docs/tags.md +673 -673
  37. package/docs/usage.md +646 -646
  38. package/eslint.config.mjs +42 -42
  39. package/ex.mjs +34 -32
  40. package/live-test/package-lock.json +915 -0
  41. package/live-test/package.json +9 -0
  42. package/live-test/server.js +14 -0
  43. package/live-test/views/base.html +8 -0
  44. package/live-test/views/child.html +7 -0
  45. package/live-test/views/index.html +1 -0
  46. package/miki-template-extension/.github/workflows/ci.yml +116 -116
  47. package/miki-template-extension/.vscodeignore +7 -7
  48. package/miki-template-extension/CHANGELOG.md +99 -99
  49. package/miki-template-extension/LICENSE +21 -21
  50. package/miki-template-extension/README.md +273 -273
  51. package/miki-template-extension/extension.js +1013 -1013
  52. package/miki-template-extension/icon.svg +10 -10
  53. package/miki-template-extension/package.json +280 -280
  54. package/miki-template-extension/snippets/miki-template.json +717 -717
  55. package/miki-template-extension/syntaxes/language-configuration.json +114 -114
  56. package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +355 -355
  57. package/miki-template-extension/tests/grammar-tests.json +162 -162
  58. package/miki-template-extension/tests/run-grammar-tests.js +82 -82
  59. package/package.json +40 -34
  60. package/sample-app/package-lock.json +901 -0
  61. package/sample-app/package.json +9 -0
  62. package/sample-app/server.js +14 -0
  63. package/sample-app/views/index.html +1 -0
  64. package/scripts/build-vsix.js +129 -129
  65. package/scripts/build-vsix.ps1 +15 -15
  66. package/snippets/miki-template.json +177 -177
  67. package/src/asyncRender.js +20 -20
  68. package/src/cache.js +80 -80
  69. package/src/context.js +126 -126
  70. package/src/context_processors.js +48 -48
  71. package/src/esm.mjs +89 -84
  72. package/src/filters.js +975 -975
  73. package/src/i18n.js +171 -171
  74. package/src/index.js +1112 -940
  75. package/src/lexer.js +114 -114
  76. package/src/libraries.js +371 -371
  77. package/src/parser.js +270 -270
  78. package/src/security.js +53 -53
  79. package/src/tags/control.js +719 -719
  80. package/src/tags/extra.js +154 -154
  81. package/src/tags/helpers.js +26 -26
  82. package/src/tags/i18n.js +256 -256
  83. package/src/tags/inheritance.js +335 -335
  84. package/src/tags/registry.js +18 -18
  85. package/src/tags/util.js +400 -400
  86. package/src/types.d.ts +107 -107
  87. package/syntaxes/language-configuration.json +26 -26
  88. package/syntaxes/miki-template.tmLanguage.json +146 -146
  89. package/tests/asyncRender.test.js +17 -17
  90. package/tests/base.html +6 -6
  91. package/tests/child.html +3 -3
  92. package/tests/context_processors.test.js +13 -13
  93. package/tests/esm.test.mjs +61 -61
  94. package/tests/filters.test.js +254 -254
  95. package/tests/finder-appdirs.test.js +19 -0
  96. package/tests/finder.test.js +17 -0
  97. package/tests/fixtures/views/nested/index.html +1 -0
  98. package/tests/fixtures/views/partial.html +1 -0
  99. package/tests/fixtures/views/sub/deepfile.html +1 -0
  100. package/tests/fixtures/views-appdirs/product/site/detail.html +1 -0
  101. package/tests/include_security.test.js +9 -9
  102. package/tests/integration/README.md +32 -32
  103. package/tests/integration/features.test.cjs +1681 -1681
  104. package/tests/integration/features.test.mjs +1697 -1697
  105. package/tests/integration/finder.esm.test.mjs +13 -0
  106. package/tests/integration/templates/base.miki +6 -6
  107. package/tests/integration/templates/child.miki +6 -6
  108. package/tests/integration/templates/index.html +17 -17
  109. package/tests/lexer.test.js +45 -45
  110. package/tests/parser.test.js +57 -57
  111. package/tests/partial.html +1 -1
  112. package/tests/partialdef.test.js +79 -79
  113. package/tests/production_checks.js +57 -57
  114. package/tests/security.test.js +28 -28
  115. package/tests/tags.test.js +233 -233
package/CHANGELOG.md CHANGED
@@ -1,169 +1,173 @@
1
- # Changelog
2
-
3
- ## [1.3.3] - 2026-09-04
4
- ### Fixed
5
- - **`date` and `time` filters** — multi-character tokens (`yyyy`, `MM`, `dd`, `HH`, `mm`, `ii`, `ss`) now work correctly. Previously `"yyyy-MM-dd"` rendered as `"24242424-JunJun-1515"` because each character was treated as an independent token. The fix uses longest-first token matching and adds backward-compatible single-character aliases (`m`/`d`/`H`/`i`/`s` for Django-style unpadded values).
6
-
7
- ### Performance
8
- - **Inheritance parent-source cache** — `{% extends %}` no longer re-reads the parent template from disk on every render. A 64-entry LRU cache in `src/cache.js` (`getParentSource` / `hasParentSource`) memoises the parent source. Inheritance rendering improved from ~481 rps to **~2,056 rps** in the stress benchmark (4.3× faster, no functional change).
9
-
10
- ### Tooling
11
- - **`benchmarks/stress.mjs`** — comprehensive 37-check stress benchmark covering correctness, compile speed, render speed, cache behavior, scale, endurance, partial rendering, async, and concurrency. Run with `node benchmarks/stress.mjs`. Exits with code 1 on any failure.
12
- - **`eslint.config.mjs`** — added `URL`, `URLSearchParams`, `TextEncoder`, `TextDecoder`, `fetch`, `crypto`, `performance` to the Node 18+ globals list so `no-undef` no longer flags standard Web APIs.
13
- - Removed dead code flagged by the linter: unused `elifBranches` variable in `parseIfChanged`, unused `extractPluralMappings` function in `i18n.js`. Renamed unused tag-parser `parser` parameters to `_parser` in `lorem` library and `parseLoad`.
14
-
15
- ### Verification
16
- - `npx eslint src/**/*.js` — 0 errors, 0 warnings
17
- - `npm test` — 397/397 passing
18
- - `node benchmarks/stress.mjs` — 37/37 passing
19
-
20
- ## [1.3.1] - 2026-09-03
21
- ### Highlights
22
- - **One-line Express integration**: `miki.setupExpress(app, { extension: 'html', views: dir })` — wires the view engine, `views` directory, and a `res.render` shim that lets you do `res.render('home#card', ...)` for HTMX-style partial responses. No more boilerplate, no extra middleware.
23
- - **Render-any-partial-from-string**: `renderPartialFromSource(source, partialName, ctx, opts)` loads a template string and returns only the named `{% partialdef %}` body. This is what powers `res.render('view#partial')` and HTMX responses.
24
- - **True built-in libraries**: `humanize`, `cache`, and `lorem` are now auto-activated on module load — `{% lorem %}` works without `{% load lorem %}`. Existing libraries now also expose helpers, not just tags.
25
- - **Comprehensive integration test suite**: 382 tests covering every tag, filter, and feature under both CommonJS and ESM, all running against a **real Express HTTP server** on ephemeral ports.
26
-
27
- ### Added
28
- - `miki.setupExpress(app, { extension, views, async })` — one-line Express bootstrap. Sets `view engine`, registers the engine, and patches `res.render` to handle `view#partial` selectors. Replaces the need to call `app.engine()`, `app.set('views')`, and `app.set('view engine')` manually.
29
- - `miki.express()` — factory that returns a view-engine function suitable for `app.engine(...)`. Honors `view#partial` suffixes.
30
- - `miki.expressPartialRenderer()` — middleware that adds `res.renderPartial(view, locals)`. Useful as a drop-in HTMX helper.
31
- - `renderPartialFromSource(source, partialName, context, options)` — render a single named partial from a template string. Resolves `extends` chains so partials defined inside `{% block %}` tags are discoverable. Walks the AST and registers every `PartialDefNode` it finds, even when nested inside `{% for %}` or `{% if %}` blocks that won't render during partial lookup.
32
- - `renderPartialFromFile(filePath, partialName, context, options)` — file-based convenience wrapper.
33
- - `Context.get(name)` now returns `undefined` for missing keys (was `''`). This lets `default_if_none` distinguish "not provided" from an explicit empty string, matching Django.
34
- - `escapeHtml(value, force = false)` — added a `force` flag so the `|escape` filter re-escapes even a `SafeString` (Django parity).
35
- - `Context` constructor now supports `partialDefs` and `options` for cloning the partial registry.
36
- - New exports: `setupExpress`, `express`, `expressPartialRenderer`, `renderPartialFromFile`, `renderPartialFromSource`, `clearContextProcessors`.
37
- - ESM surface (`src/esm.mjs`) now exposes all the new helpers, with the same `default` + named import shape.
38
- - Lorem library now ships a real `{% lorem N method %}` tag, a `lorem` filter, plus helpers. Built-in and auto-activated.
39
- - `library.activate(name)` now also activates helpers and `registerTag` functions, not just filters.
40
-
41
- ### Changed
42
- - Context processors now follow Django semantics: **existing context values win** over processor defaults. If you render with `{ user: req.user }` and a processor returns `{ user: 'Guest' }`, the explicit value is preserved.
43
- - `__express` and `__expressAsync` now detect a `#partial` suffix in the view name and delegate to `renderPartialFromSource` automatically. This makes `app.engine('html', miki.__express)` already HTMX-ready — `setupExpress` just adds convenience.
44
- - `cache.getCompiled` ignores function-valued and `undefined` options when building cache keys, so passing the same `urlHelper` function to multiple `compile()` calls no longer causes cache misses.
45
- - Lexer rewritten with brace-depth counting for more reliable `{{ }}` and `{% %}` tokenization in templates with nested braces, escaped braces, and unusual whitespace.
46
- - Filters now receive the rendering `context` as a final argument, so custom filters can read other context variables (e.g. for locale-aware formatting).
47
- - `for` and `with` tags fully reworked for the user-reported edge cases:
48
- - `{% with x=1, y=2 as pair %}` — pair list followed by an alias.
49
- - `{% with value=expr %}` — single pair (no comma).
50
- - `{% with x=1, y=2 %}` — pure pair list (no alias).
51
- - Quoted values containing commas (`{% with a="x,y" %}`) parse correctly.
52
- - Pair values may be context variables.
53
- - `partial` now accepts `with` kwargs and overrides context for the partial scope.
54
- - `include` now supports `file#partial` syntax — the same partial-selector pattern works with `{% include %}` as with `res.render`.
55
- - `url` tag respects `urlHelper` more cleanly: kwargs (a trailing object literal) are passed as the last argument instead of being conflated with positional args.
56
- - `static` tag normalizes leading slashes; prefix can be customized.
57
- - `csrf_token` and `csp_nonce_attr` outputs are properly escaped to prevent attribute injection.
58
-
59
- ### Fixed
60
- - `with a=x b=y` (multi-pair) was previously treated as a single value/expression. Now correctly binds each pair.
61
- - `cycle` with `as` form emits nothing but stores the value, matching Django.
62
- - `block.super` works inside partials that override blocks.
63
- - `extends` resolves `views` from `options.settings.views` (Express's normal path), `options.views`, or the default.
64
- - Path traversal protection now applies to `extends` *and* `include`, including `include "file#partial"` form.
65
- - `if` conditions handle dotted lookup, function auto-call, and missing variables without throwing.
66
- - `default` vs `default_if_none`: `default` falls back on empty string, `null`, and `undefined`; `default_if_none` only on `null`/`undefined`. Both now match Django exactly.
67
- - `removetags` filter now accepts multiple tag names.
68
- - `safe` / `escape` filters correctly re-escape `SafeString` only when forced.
69
- - `Context.get('a.b.c')` no longer stringifies `undefined` to `''`, fixing `{% if x %}` checks against missing variables.
70
- - Cache key collisions when passing the same template string with different function-valued options (e.g. `urlHelper`).
71
-
72
- ### Compatibility
73
- - No breaking changes. All existing public APIs continue to work. New APIs are opt-in.
74
-
75
- ## [1.2.0] - 2026-09-01
76
- ### Added
77
- - Full **ESM** support via `src/esm.mjs` wrapper and conditional `package.json` exports.
78
- - **TypeScript** type definitions (`src/types.d.ts`).
79
- - **Async Express 5+** adapter: `__expressAsync(filePath, options) → Promise<string>`.
80
- - **i18n**: `trans` tag/filter, `blocktrans`, `language`, plural rules, `registerTranslation`.
81
- - **Plugin/library system**: `registerLibrary`, `registerLibraryFromPath`, built-ins (`humanize`, `cache`, `lorem`).
82
- - **`load` tag** now activates registered libraries (no longer a stub).
83
- - **`widthratio`** tag for proportional width calculations.
84
- - **`debug`** tag for dumping template context during development.
85
- - **`regroup`** filter for grouping arrays by attribute.
86
- - **`strftime`** filter with full `date-fns` format support.
87
- - **Unclosed tag validation**: throws descriptive errors for missing `endif`/`endfor`/`endwith`.
88
- - **Filter chaining on string literals**: `{{ "Hello"|lower|capfirst }}` now works.
89
- - New exports: `getFilter`, `stripExpressContext`, `activateLibrary`.
90
-
91
- ### Fixed
92
- - `for` loop now supports filter expressions in iterable path (e.g. `items|regroup:"category"`).
93
- - `Context.reset()` properly clears cycle state and blocks between renders.
94
- - `__express` strips Express framework keys (`_locals`, `settings`, `cache`) from context.
95
- - `renderPartial` renders only the named partial, not the full template.
96
- - `with` tag correctly handles multiple `key=value` assignments and quoted values.
97
- - `if` tag condition evaluation handles `not`, `and`, `or`, and operator precedence correctly.
98
- - `forloop.parentloop` correctly propagates for nested loops.
99
- - `floatformat` default behavior matches Django (1 decimal place).
100
- - `timesince`/`timeuntil` handle seconds, minutes, hours, days correctly.
101
- - `pluralize` correctly handles singular vs plural forms.
102
- - `default` filter treats empty string `''` as falsy like Django.
103
- - `striptags` correctly removes HTML tags and handles edge cases.
104
- - Spaceless tag preserves whitespace inside tag attributes correctly.
105
-
106
- ### Changed
107
- - Condition evaluation rewritten to use shunting-yard algorithm for correct operator precedence.
108
- - Simplified `for` loop to use `[key, value]` tuples internally for cleaner unpacking.
109
- - Improved `partialdef` to support both quoted and unquoted partial names.
110
- - `floatformat` with `-1` argument now removes all decimals.
111
-
112
- ## [1.1.0] - 2026-08-31
113
- ### Added
114
- - Missing `comment`/`endcomment` tag support for block comments.
115
- - `firstof` tag to return the first non-falsy value from arguments.
116
- - `length_is` filter for comparing length to a value.
117
- - `urlencode`, `escapeuri`, `stringformat`, `cut`, `addslashes`, `removetags` filters for Django parity.
118
- - `Context.reset()` method for clearing state between renders.
119
- - `firstof` filter variant for inline first-truthy selection.
120
-
121
- ### Fixed
122
- - Malformed code in `inheritance.js` with extra closing braces.
123
- - `__express` was not exported from the module.
124
- - `__express` now strips Express framework keys (`_locals`, `settings`, etc.) from context.
125
- - `renderPartial` now properly extracts and renders only the named partial definition.
126
- - `with` tag now correctly handles multiple `key=value` assignments and quoted values.
127
- - `if` tag condition evaluation now properly handles `not`, `and`, `or`, and operator precedence.
128
- - `for` loop now correctly unpacks `key, value` from objects and `item, index` from arrays.
129
- - `forloop.parentloop` now correctly chains for nested loops.
130
- - Cycle state (`cycleStates`) now resets per render via `Context.reset()`.
131
- - Async helpers now work correctly with `asyncRender`.
132
- - Partial definitions now collected at compile time for proper `renderPartial` support.
133
- - Path traversal protection added to `extends` tag (previously only on `include`).
134
- - `floatformat` default behavior now matches Django (1 decimal place).
135
- - `timesince`/`timeuntil` now handles seconds, minutes, hours, days correctly.
136
- - `pluralize` now correctly handles singular vs plural forms.
137
- - `default` filter now treats empty string `''` as falsy like Django.
138
- - `striptags` now correctly removes HTML tags and handles edge cases.
139
- - Spaceless tag now preserves whitespace inside tag attributes correctly.
140
-
141
- ### Changed
142
- - Rewrote condition evaluation to use shunting-yard algorithm for correct operator precedence.
143
- - Simplified `for` loop to use `[key, value]` tuples internally for cleaner unpacking.
144
- - Improved `partialdef` to support both quoted and unquoted partial names.
145
- - `floatformat` with `-1` argument now removes all decimals.
146
-
147
- ## [1.0.0] - 2026-08-29
148
- ### Added
149
- - Full Django‑style template engine with variables, filters, tags, inheritance, partials, and context processors.
150
- - Security features: auto‑escaping, `markSafe`, `csrf_token` and `csp_nonce_attr` tags.
151
- - Extensible API: `registerTag`, `registerFilter`, `markSafe`.
152
- - Express integration via `__express` adapter.
153
- - Comprehensive test suite (40 passing tests) and benchmark suite.
154
- - Detailed documentation hierarchy (`docs/`): overview, installation, usage, tags, filters, partialdef, security, API reference, contribution guide.
155
- - CI workflow using GitHub Actions.
156
- - Project scaffolding, linting, and contribution guardrails (`AGENT.md`).
157
-
158
- ### Fixed
159
- - Auto‑escaping now respects `SafeString` values.
160
- - Context processors correctly propagate returned context.
161
- - Fixed tag parsing edge cases in `IfNode` and `PartialDefNode`.
162
-
163
- ### Changed
164
- - Updated README with npm version and CI badges.
165
- - Added `CHANGELOG.md` for release notes.
166
-
167
- [1.2.0]: https://github.com/your-repo/miki-template/releases/tag/v1.2.0
168
- [1.1.0]: https://github.com/your-repo/miki-template/releases/tag/v1.1.0
169
- [1.0.0]: https://github.com/your-repo/miki-template/releases/tag/v1.0.0
1
+ # Changelog
2
+
3
+ ## [1.3.4] - 2026-09-05
4
+ ### Fixed
5
+ - **Express views path resolution** — normalize `views` entries and ensure miki treats file paths as directories when resolving templates and `#partial` lookups. This fixes `Failed to lookup view "home" in views directory ".../dir"` when `miki-template` is used from a host project's `node_modules` and `views` is passed as a file path.
6
+
7
+ ## [1.3.3] - 2026-09-04
8
+ ### Fixed
9
+ - **`date` and `time` filters** — multi-character tokens (`yyyy`, `MM`, `dd`, `HH`, `mm`, `ii`, `ss`) now work correctly. Previously `"yyyy-MM-dd"` rendered as `"24242424-JunJun-1515"` because each character was treated as an independent token. The fix uses longest-first token matching and adds backward-compatible single-character aliases (`m`/`d`/`H`/`i`/`s` for Django-style unpadded values).
10
+
11
+ ### Performance
12
+ - **Inheritance parent-source cache** — `{% extends %}` no longer re-reads the parent template from disk on every render. A 64-entry LRU cache in `src/cache.js` (`getParentSource` / `hasParentSource`) memoises the parent source. Inheritance rendering improved from ~481 rps to **~2,056 rps** in the stress benchmark (4.3× faster, no functional change).
13
+
14
+ ### Tooling
15
+ - **`benchmarks/stress.mjs`** — comprehensive 37-check stress benchmark covering correctness, compile speed, render speed, cache behavior, scale, endurance, partial rendering, async, and concurrency. Run with `node benchmarks/stress.mjs`. Exits with code 1 on any failure.
16
+ - **`eslint.config.mjs`** — added `URL`, `URLSearchParams`, `TextEncoder`, `TextDecoder`, `fetch`, `crypto`, `performance` to the Node 18+ globals list so `no-undef` no longer flags standard Web APIs.
17
+ - Removed dead code flagged by the linter: unused `elifBranches` variable in `parseIfChanged`, unused `extractPluralMappings` function in `i18n.js`. Renamed unused tag-parser `parser` parameters to `_parser` in `lorem` library and `parseLoad`.
18
+
19
+ ### Verification
20
+ - `npx eslint src/**/*.js` — 0 errors, 0 warnings
21
+ - `npm test` — 397/397 passing
22
+ - `node benchmarks/stress.mjs` — 37/37 passing
23
+
24
+ ## [1.3.1] - 2026-09-03
25
+ ### Highlights
26
+ - **One-line Express integration**: `miki.setupExpress(app, { extension: 'html', views: dir })` — wires the view engine, `views` directory, and a `res.render` shim that lets you do `res.render('home#card', ...)` for HTMX-style partial responses. No more boilerplate, no extra middleware.
27
+ - **Render-any-partial-from-string**: `renderPartialFromSource(source, partialName, ctx, opts)` loads a template string and returns only the named `{% partialdef %}` body. This is what powers `res.render('view#partial')` and HTMX responses.
28
+ - **True built-in libraries**: `humanize`, `cache`, and `lorem` are now auto-activated on module load — `{% lorem %}` works without `{% load lorem %}`. Existing libraries now also expose helpers, not just tags.
29
+ - **Comprehensive integration test suite**: 382 tests covering every tag, filter, and feature under both CommonJS and ESM, all running against a **real Express HTTP server** on ephemeral ports.
30
+
31
+ ### Added
32
+ - `miki.setupExpress(app, { extension, views, async })` — one-line Express bootstrap. Sets `view engine`, registers the engine, and patches `res.render` to handle `view#partial` selectors. Replaces the need to call `app.engine()`, `app.set('views')`, and `app.set('view engine')` manually.
33
+ - `miki.express()` — factory that returns a view-engine function suitable for `app.engine(...)`. Honors `view#partial` suffixes.
34
+ - `miki.expressPartialRenderer()` — middleware that adds `res.renderPartial(view, locals)`. Useful as a drop-in HTMX helper.
35
+ - `renderPartialFromSource(source, partialName, context, options)` — render a single named partial from a template string. Resolves `extends` chains so partials defined inside `{% block %}` tags are discoverable. Walks the AST and registers every `PartialDefNode` it finds, even when nested inside `{% for %}` or `{% if %}` blocks that won't render during partial lookup.
36
+ - `renderPartialFromFile(filePath, partialName, context, options)` — file-based convenience wrapper.
37
+ - `Context.get(name)` now returns `undefined` for missing keys (was `''`). This lets `default_if_none` distinguish "not provided" from an explicit empty string, matching Django.
38
+ - `escapeHtml(value, force = false)` — added a `force` flag so the `|escape` filter re-escapes even a `SafeString` (Django parity).
39
+ - `Context` constructor now supports `partialDefs` and `options` for cloning the partial registry.
40
+ - New exports: `setupExpress`, `express`, `expressPartialRenderer`, `renderPartialFromFile`, `renderPartialFromSource`, `clearContextProcessors`.
41
+ - ESM surface (`src/esm.mjs`) now exposes all the new helpers, with the same `default` + named import shape.
42
+ - Lorem library now ships a real `{% lorem N method %}` tag, a `lorem` filter, plus helpers. Built-in and auto-activated.
43
+ - `library.activate(name)` now also activates helpers and `registerTag` functions, not just filters.
44
+
45
+ ### Changed
46
+ - Context processors now follow Django semantics: **existing context values win** over processor defaults. If you render with `{ user: req.user }` and a processor returns `{ user: 'Guest' }`, the explicit value is preserved.
47
+ - `__express` and `__expressAsync` now detect a `#partial` suffix in the view name and delegate to `renderPartialFromSource` automatically. This makes `app.engine('html', miki.__express)` already HTMX-ready — `setupExpress` just adds convenience.
48
+ - `cache.getCompiled` ignores function-valued and `undefined` options when building cache keys, so passing the same `urlHelper` function to multiple `compile()` calls no longer causes cache misses.
49
+ - Lexer rewritten with brace-depth counting for more reliable `{{ }}` and `{% %}` tokenization in templates with nested braces, escaped braces, and unusual whitespace.
50
+ - Filters now receive the rendering `context` as a final argument, so custom filters can read other context variables (e.g. for locale-aware formatting).
51
+ - `for` and `with` tags fully reworked for the user-reported edge cases:
52
+ - `{% with x=1, y=2 as pair %}` — pair list followed by an alias.
53
+ - `{% with value=expr %}` — single pair (no comma).
54
+ - `{% with x=1, y=2 %}` — pure pair list (no alias).
55
+ - Quoted values containing commas (`{% with a="x,y" %}`) parse correctly.
56
+ - Pair values may be context variables.
57
+ - `partial` now accepts `with` kwargs and overrides context for the partial scope.
58
+ - `include` now supports `file#partial` syntax — the same partial-selector pattern works with `{% include %}` as with `res.render`.
59
+ - `url` tag respects `urlHelper` more cleanly: kwargs (a trailing object literal) are passed as the last argument instead of being conflated with positional args.
60
+ - `static` tag normalizes leading slashes; prefix can be customized.
61
+ - `csrf_token` and `csp_nonce_attr` outputs are properly escaped to prevent attribute injection.
62
+
63
+ ### Fixed
64
+ - `with a=x b=y` (multi-pair) was previously treated as a single value/expression. Now correctly binds each pair.
65
+ - `cycle` with `as` form emits nothing but stores the value, matching Django.
66
+ - `block.super` works inside partials that override blocks.
67
+ - `extends` resolves `views` from `options.settings.views` (Express's normal path), `options.views`, or the default.
68
+ - Path traversal protection now applies to `extends` *and* `include`, including `include "file#partial"` form.
69
+ - `if` conditions handle dotted lookup, function auto-call, and missing variables without throwing.
70
+ - `default` vs `default_if_none`: `default` falls back on empty string, `null`, and `undefined`; `default_if_none` only on `null`/`undefined`. Both now match Django exactly.
71
+ - `removetags` filter now accepts multiple tag names.
72
+ - `safe` / `escape` filters correctly re-escape `SafeString` only when forced.
73
+ - `Context.get('a.b.c')` no longer stringifies `undefined` to `''`, fixing `{% if x %}` checks against missing variables.
74
+ - Cache key collisions when passing the same template string with different function-valued options (e.g. `urlHelper`).
75
+
76
+ ### Compatibility
77
+ - No breaking changes. All existing public APIs continue to work. New APIs are opt-in.
78
+
79
+ ## [1.2.0] - 2026-09-01
80
+ ### Added
81
+ - Full **ESM** support via `src/esm.mjs` wrapper and conditional `package.json` exports.
82
+ - **TypeScript** type definitions (`src/types.d.ts`).
83
+ - **Async Express 5+** adapter: `__expressAsync(filePath, options) → Promise<string>`.
84
+ - **i18n**: `trans` tag/filter, `blocktrans`, `language`, plural rules, `registerTranslation`.
85
+ - **Plugin/library system**: `registerLibrary`, `registerLibraryFromPath`, built-ins (`humanize`, `cache`, `lorem`).
86
+ - **`load` tag** now activates registered libraries (no longer a stub).
87
+ - **`widthratio`** tag for proportional width calculations.
88
+ - **`debug`** tag for dumping template context during development.
89
+ - **`regroup`** filter for grouping arrays by attribute.
90
+ - **`strftime`** filter with full `date-fns` format support.
91
+ - **Unclosed tag validation**: throws descriptive errors for missing `endif`/`endfor`/`endwith`.
92
+ - **Filter chaining on string literals**: `{{ "Hello"|lower|capfirst }}` now works.
93
+ - New exports: `getFilter`, `stripExpressContext`, `activateLibrary`.
94
+
95
+ ### Fixed
96
+ - `for` loop now supports filter expressions in iterable path (e.g. `items|regroup:"category"`).
97
+ - `Context.reset()` properly clears cycle state and blocks between renders.
98
+ - `__express` strips Express framework keys (`_locals`, `settings`, `cache`) from context.
99
+ - `renderPartial` renders only the named partial, not the full template.
100
+ - `with` tag correctly handles multiple `key=value` assignments and quoted values.
101
+ - `if` tag condition evaluation handles `not`, `and`, `or`, and operator precedence correctly.
102
+ - `forloop.parentloop` correctly propagates for nested loops.
103
+ - `floatformat` default behavior matches Django (1 decimal place).
104
+ - `timesince`/`timeuntil` handle seconds, minutes, hours, days correctly.
105
+ - `pluralize` correctly handles singular vs plural forms.
106
+ - `default` filter treats empty string `''` as falsy like Django.
107
+ - `striptags` correctly removes HTML tags and handles edge cases.
108
+ - Spaceless tag preserves whitespace inside tag attributes correctly.
109
+
110
+ ### Changed
111
+ - Condition evaluation rewritten to use shunting-yard algorithm for correct operator precedence.
112
+ - Simplified `for` loop to use `[key, value]` tuples internally for cleaner unpacking.
113
+ - Improved `partialdef` to support both quoted and unquoted partial names.
114
+ - `floatformat` with `-1` argument now removes all decimals.
115
+
116
+ ## [1.1.0] - 2026-08-31
117
+ ### Added
118
+ - Missing `comment`/`endcomment` tag support for block comments.
119
+ - `firstof` tag to return the first non-falsy value from arguments.
120
+ - `length_is` filter for comparing length to a value.
121
+ - `urlencode`, `escapeuri`, `stringformat`, `cut`, `addslashes`, `removetags` filters for Django parity.
122
+ - `Context.reset()` method for clearing state between renders.
123
+ - `firstof` filter variant for inline first-truthy selection.
124
+
125
+ ### Fixed
126
+ - Malformed code in `inheritance.js` with extra closing braces.
127
+ - `__express` was not exported from the module.
128
+ - `__express` now strips Express framework keys (`_locals`, `settings`, etc.) from context.
129
+ - `renderPartial` now properly extracts and renders only the named partial definition.
130
+ - `with` tag now correctly handles multiple `key=value` assignments and quoted values.
131
+ - `if` tag condition evaluation now properly handles `not`, `and`, `or`, and operator precedence.
132
+ - `for` loop now correctly unpacks `key, value` from objects and `item, index` from arrays.
133
+ - `forloop.parentloop` now correctly chains for nested loops.
134
+ - Cycle state (`cycleStates`) now resets per render via `Context.reset()`.
135
+ - Async helpers now work correctly with `asyncRender`.
136
+ - Partial definitions now collected at compile time for proper `renderPartial` support.
137
+ - Path traversal protection added to `extends` tag (previously only on `include`).
138
+ - `floatformat` default behavior now matches Django (1 decimal place).
139
+ - `timesince`/`timeuntil` now handles seconds, minutes, hours, days correctly.
140
+ - `pluralize` now correctly handles singular vs plural forms.
141
+ - `default` filter now treats empty string `''` as falsy like Django.
142
+ - `striptags` now correctly removes HTML tags and handles edge cases.
143
+ - Spaceless tag now preserves whitespace inside tag attributes correctly.
144
+
145
+ ### Changed
146
+ - Rewrote condition evaluation to use shunting-yard algorithm for correct operator precedence.
147
+ - Simplified `for` loop to use `[key, value]` tuples internally for cleaner unpacking.
148
+ - Improved `partialdef` to support both quoted and unquoted partial names.
149
+ - `floatformat` with `-1` argument now removes all decimals.
150
+
151
+ ## [1.0.0] - 2026-08-29
152
+ ### Added
153
+ - Full Django‑style template engine with variables, filters, tags, inheritance, partials, and context processors.
154
+ - Security features: auto‑escaping, `markSafe`, `csrf_token` and `csp_nonce_attr` tags.
155
+ - Extensible API: `registerTag`, `registerFilter`, `markSafe`.
156
+ - Express integration via `__express` adapter.
157
+ - Comprehensive test suite (40 passing tests) and benchmark suite.
158
+ - Detailed documentation hierarchy (`docs/`): overview, installation, usage, tags, filters, partialdef, security, API reference, contribution guide.
159
+ - CI workflow using GitHub Actions.
160
+ - Project scaffolding, linting, and contribution guardrails (`AGENT.md`).
161
+
162
+ ### Fixed
163
+ - Auto‑escaping now respects `SafeString` values.
164
+ - Context processors correctly propagate returned context.
165
+ - Fixed tag parsing edge cases in `IfNode` and `PartialDefNode`.
166
+
167
+ ### Changed
168
+ - Updated README with npm version and CI badges.
169
+ - Added `CHANGELOG.md` for release notes.
170
+
171
+ [1.2.0]: https://github.com/your-repo/miki-template/releases/tag/v1.2.0
172
+ [1.1.0]: https://github.com/your-repo/miki-template/releases/tag/v1.1.0
173
+ [1.0.0]: https://github.com/your-repo/miki-template/releases/tag/v1.0.0
@@ -1,14 +1,14 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
- We pledge to make participation in our project a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity, experience level, nationality, personal appearance, race, religion, or sexual orientation.
5
-
6
- ## Our Standards
7
- Examples of behavior that contributes to creating a positive environment include:
8
- - Using welcoming and inclusive language.
9
- - Being respectful of differing viewpoints and experiences.
10
- - Gracefully accepting constructive criticism.
11
- - Focusing on what is best for the community.
12
- - Showing empathy towards other community members.
13
-
14
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct.
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+ We pledge to make participation in our project a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity, experience level, nationality, personal appearance, race, religion, or sexual orientation.
5
+
6
+ ## Our Standards
7
+ Examples of behavior that contributes to creating a positive environment include:
8
+ - Using welcoming and inclusive language.
9
+ - Being respectful of differing viewpoints and experiences.
10
+ - Gracefully accepting constructive criticism.
11
+ - Focusing on what is best for the community.
12
+ - Showing empathy towards other community members.
13
+
14
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct.
package/CONTRIBUTING.md CHANGED
@@ -1,27 +1,27 @@
1
- # Contributing to Django-Style Template Engine
2
-
3
- Thank you for your interest in contributing! Please follow these guidelines:
4
-
5
- ---
6
-
7
- ## 🛠️ Development Setup
8
-
9
- 1. **Clone the Repository**
10
- 2. **Install Dependencies**:
11
- ```bash
12
- npm install
13
- ```
14
- 3. **Run the Tests**:
15
- ```bash
16
- npm test
17
- ```
18
-
19
- ---
20
-
21
- ## 🛑 Guardrails & Standards
22
-
23
- Before submitting a PR, make sure your code aligns with the strict requirements outlined in [AGENT.md](file:///c:/Users/Coder%20Miki/Desktop/miki-template/AGENT.md):
24
- - Ensure full parity with Django syntax behavior.
25
- - Do not use `eval()` for safety.
26
- - Write corresponding unit tests in `tests/` for all new features or bug fixes.
27
- - Verify that auto-escaping remains secure by default.
1
+ # Contributing to Django-Style Template Engine
2
+
3
+ Thank you for your interest in contributing! Please follow these guidelines:
4
+
5
+ ---
6
+
7
+ ## 🛠️ Development Setup
8
+
9
+ 1. **Clone the Repository**
10
+ 2. **Install Dependencies**:
11
+ ```bash
12
+ npm install
13
+ ```
14
+ 3. **Run the Tests**:
15
+ ```bash
16
+ npm test
17
+ ```
18
+
19
+ ---
20
+
21
+ ## 🛑 Guardrails & Standards
22
+
23
+ Before submitting a PR, make sure your code aligns with the strict requirements outlined in [AGENT.md](file:///c:/Users/Coder%20Miki/Desktop/miki-template/AGENT.md):
24
+ - Ensure full parity with Django syntax behavior.
25
+ - Do not use `eval()` for safety.
26
+ - Write corresponding unit tests in `tests/` for all new features or bug fixes.
27
+ - Verify that auto-escaping remains secure by default.