miki-template 1.2.0 → 1.3.3

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 (60) hide show
  1. package/.github/release-notes/v1.3.1.md +55 -0
  2. package/CHANGELOG.md +72 -0
  3. package/README.md +43 -26
  4. package/assets/banner.png +0 -0
  5. package/benchmarks/stress.mjs +647 -0
  6. package/dir/base.html +23 -0
  7. package/dir/cmpnt.html +11 -0
  8. package/dir/footer.html +3 -0
  9. package/dir/home.html +80 -0
  10. package/dir/navbar.html +9 -0
  11. package/docs/api.md +20 -3
  12. package/docs/filters.md +301 -133
  13. package/docs/partialdef.md +30 -1
  14. package/docs/tags.md +63 -0
  15. package/docs/usage.md +50 -3
  16. package/eslint.config.mjs +9 -1
  17. package/ex.mjs +33 -0
  18. package/miki-template-extension/.github/workflows/ci.yml +116 -0
  19. package/miki-template-extension/.vscodeignore +7 -0
  20. package/miki-template-extension/CHANGELOG.md +99 -0
  21. package/miki-template-extension/README.md +244 -53
  22. package/miki-template-extension/extension.js +1013 -0
  23. package/miki-template-extension/icon.png +0 -0
  24. package/miki-template-extension/miki-template-1.7.1.vsix +0 -0
  25. package/miki-template-extension/package.json +244 -10
  26. package/miki-template-extension/snippets/miki-template.json +612 -72
  27. package/miki-template-extension/syntaxes/language-configuration.json +101 -13
  28. package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +270 -61
  29. package/miki-template-extension/tests/grammar-tests.json +162 -0
  30. package/miki-template-extension/tests/run-grammar-tests.js +82 -0
  31. package/package.json +7 -4
  32. package/scripts/build-vsix.js +129 -0
  33. package/scripts/build-vsix.ps1 +15 -0
  34. package/src/cache.js +41 -2
  35. package/src/context.js +9 -5
  36. package/src/context_processors.js +9 -2
  37. package/src/esm.mjs +12 -0
  38. package/src/filters.js +472 -24
  39. package/src/index.js +571 -85
  40. package/src/lexer.js +76 -54
  41. package/src/libraries.js +134 -3
  42. package/src/parser.js +22 -2
  43. package/src/security.js +4 -2
  44. package/src/tags/control.js +150 -21
  45. package/src/tags/extra.js +154 -0
  46. package/src/tags/i18n.js +49 -23
  47. package/src/tags/inheritance.js +142 -23
  48. package/src/tags/util.js +102 -24
  49. package/tests/esm.test.mjs +37 -2
  50. package/tests/filters.test.js +155 -0
  51. package/tests/integration/README.md +32 -0
  52. package/tests/integration/features.test.cjs +1681 -0
  53. package/tests/integration/features.test.mjs +1697 -0
  54. package/tests/integration/templates/base.miki +6 -0
  55. package/tests/integration/templates/child.miki +6 -0
  56. package/tests/integration/templates/index.html +17 -0
  57. package/tests/parser.test.js +5 -3
  58. package/tests/partialdef.test.js +40 -1
  59. package/tests/tags.test.js +30 -0
  60. package/miki-template-1.2.0.vsix +0 -0
package/dir/home.html ADDED
@@ -0,0 +1,80 @@
1
+ {% extends 'base.html' %}
2
+
3
+ {% block title %}
4
+ {{ siteName|default:'Home page Here'|title }} | {{ block.super }}
5
+ {% endblock %}
6
+
7
+ {% block content %}
8
+ {% partialdef card inline %}
9
+ <div class="card">
10
+ <h3>{{ title|default:'No title' }}</h3>
11
+ <p>{{ description|default:'{% lorem 20 %}'|upper }}</p>
12
+ </div>
13
+ {% endpartialdef %}
14
+
15
+ {% partial card with title='Hello' description='World' %}
16
+
17
+ {% with a=5 %}
18
+ <marquee behavior="" direction="">
19
+ <span>some new stuff with with tag : {{ a|add:5 }}</span>
20
+ </marquee>
21
+ {% endwith %}
22
+
23
+ {{ name }}
24
+ {{ login.name }}
25
+ {{ login.email }}
26
+ <h1>Users table goes below</h1>
27
+ <table border="3">
28
+ <th>name</th>
29
+ <th>email</th>
30
+ <th>action</th>
31
+
32
+ {% for user in users %}
33
+ <tr>
34
+ <td>{{ user.name|title }}</td>
35
+ <td>{{ user.email }}</td>
36
+ <td>
37
+ <a href="">Delete user</a>
38
+ </td>
39
+ </tr>
40
+ {% endfor %}
41
+
42
+ </table>
43
+ <h1>Data list</h1>
44
+ <h2>data list of data</h2>
45
+ {% for obj in data %}
46
+ {% partialdef mike inline %}
47
+
48
+ <li>{{ obj.name }}</li>
49
+ <li>{{ forloop.counter }}</li>
50
+ <li> {{ obj.email }}</li>
51
+ {% endpartialdef %}
52
+ {% endfor %}
53
+
54
+ <h2>users list of data</h2>
55
+ <ul style="background-color: aqua;color: blueviolet; list-style-type:upper-roman;">
56
+
57
+ {% for obj in users %}
58
+ {% partial mike %}
59
+ {% endfor %}
60
+ </ul>
61
+
62
+ <h3>form with crsf</h3>
63
+
64
+ <form action="">
65
+ {% csrf_token %}
66
+ <input type="text" name="" id="" title="some text"/>
67
+ </form>
68
+ <h3>included content here</h3>
69
+ {% include 'cmpnt.html#me' %}
70
+
71
+ {{"2324"|filesizeformat}}
72
+ {{"224"|filesizeformat}}
73
+ {{ "123456789"|filesizeformat }}
74
+ {{ "1234567890"|filesizeformat }}
75
+ {{ "1234567890123"|filesizeformat }}
76
+ {{ "1234567890123456"|filesizeformat }}
77
+ {{ "1234567890123456789"|filesizeformat }}
78
+
79
+
80
+ {% endblock %}
@@ -0,0 +1,9 @@
1
+ <header>
2
+ <div class="brand">
3
+ <img src="/path/to/logo.png" alt="Logo" width="40px">
4
+ </div>
5
+ <nav>
6
+ <a href="/">Home</a>
7
+
8
+ </nav>
9
+ </header>
package/docs/api.md CHANGED
@@ -7,8 +7,13 @@ This document lists the public API exported by **miki-template** for developers
7
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
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
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. | `app.set('view engine', 'miki');` |
11
- | `__expressAsync(filePath, options)` | `__expressAsync(string, object) → Promise<string>` | Async Express 5+ view engine adapter. Returns a Promise that resolves to rendered HTML. | `app.engine('html', miki.__expressAsync);` |
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
+ | `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 });` |
16
+ | `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 });` |
12
17
  | `stripExpressContext(options)` | `stripExpressContext(object) → object` | Remove Express framework keys (`_locals`, `settings`, `cache`) from an options object. | `const ctx = stripExpressContext(res.locals);` |
13
18
  | `clearCache()` | `clearCache() → void` | Clear the in-memory compiled template cache. | `clearCache();` |
14
19
  | `registerTag(name, parserFn)` | `registerTag(string, function)` | Register a custom tag parser. Must be called before compiling templates. | `registerTag('mytag', parserFn);` |
@@ -39,6 +44,11 @@ const {
39
44
  asyncRender,
40
45
  __express,
41
46
  __expressAsync,
47
+ express,
48
+ setupExpress,
49
+ expressPartialRenderer,
50
+ renderPartialFromFile,
51
+ renderPartialFromSource,
42
52
  stripExpressContext,
43
53
  clearCache,
44
54
  registerTag,
@@ -46,6 +56,7 @@ const {
46
56
  getFilter,
47
57
  registerHelper,
48
58
  registerContextProcessor,
59
+ clearContextProcessors,
49
60
  registerTranslation,
50
61
  setLanguage,
51
62
  getLanguage,
@@ -69,6 +80,11 @@ import {
69
80
  asyncRender,
70
81
  __express,
71
82
  __expressAsync,
83
+ express,
84
+ setupExpress,
85
+ expressPartialRenderer,
86
+ renderPartialFromFile,
87
+ renderPartialFromSource,
72
88
  stripExpressContext,
73
89
  clearCache,
74
90
  registerTag,
@@ -76,6 +92,7 @@ import {
76
92
  getFilter,
77
93
  registerHelper,
78
94
  registerContextProcessor,
95
+ clearContextProcessors,
79
96
  registerTranslation,
80
97
  setLanguage,
81
98
  getLanguage,
@@ -92,7 +109,7 @@ import {
92
109
 
93
110
  // Or import all as default
94
111
  import miki from 'miki-template';
95
- const { render: mikiRender } = miki;
112
+ const { render: mikiRender, setupExpress } = miki;
96
113
  ```
97
114
 
98
115
  For detailed usage, refer to the corresponding sections in the documentation: