miki-template 2.3.1 → 2.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 (167) hide show
  1. package/README.md +1 -1
  2. package/package.json +24 -2
  3. package/src/codegen.js +140 -9
  4. package/src/parser.js +69 -1
  5. package/src/tags/control.js +112 -51
  6. package/src/tags/extra.js +4 -17
  7. package/src/tags/i18n.js +6 -17
  8. package/src/tags/inheritance.js +6 -20
  9. package/src/tags/util.js +5 -20
  10. package/.eslintrc.json +0 -16
  11. package/.github/release-notes/v1.3.1.md +0 -55
  12. package/.github/release-notes/v1.3.3.md +0 -77
  13. package/.github/release-notes/v1.3.7.md +0 -20
  14. package/.github/workflows/ci.yml +0 -42
  15. package/.github/workflows/docs.yml +0 -107
  16. package/.github/workflows/release.yml +0 -107
  17. package/AGENT.md +0 -71
  18. package/API_REFERENCE.md +0 -341
  19. package/CHANGELOG.md +0 -173
  20. package/CODE_OF_CONDUCT.md +0 -14
  21. package/CONTRIBUTING.md +0 -27
  22. package/ROADMAP.md +0 -40
  23. package/assets/banner.png +0 -0
  24. package/assets/logo.png +0 -0
  25. package/benchmarks/ejs-results.json +0 -17
  26. package/benchmarks/ejs.js +0 -38
  27. package/benchmarks/handlebars-results.json +0 -17
  28. package/benchmarks/handlebars.js +0 -45
  29. package/benchmarks/miki-results.json +0 -17
  30. package/benchmarks/miki.js +0 -39
  31. package/benchmarks/pug-results.json +0 -17
  32. package/benchmarks/pug.js +0 -38
  33. package/benchmarks/report.json +0 -17
  34. package/benchmarks/run.js +0 -81
  35. package/benchmarks/stress.mjs +0 -647
  36. package/benchmarks/templates/large.dtpl +0 -7
  37. package/benchmarks/templates/medium.dtpl +0 -3
  38. package/benchmarks/templates/small.dtpl +0 -7
  39. package/context/component.md +0 -109
  40. package/context/prd.md +0 -131
  41. package/context/project-structure.md +0 -33
  42. package/dir/base.html +0 -23
  43. package/dir/cmpnt.html +0 -11
  44. package/dir/footer.html +0 -3
  45. package/dir/home.html +0 -80
  46. package/dir/index.html +0 -80
  47. package/dir/navbar.html +0 -9
  48. package/docs/api/async-render.md +0 -170
  49. package/docs/api/cache.md +0 -174
  50. package/docs/api/compile.md +0 -256
  51. package/docs/api/context-processors.md +0 -154
  52. package/docs/api/filters.md +0 -437
  53. package/docs/api/finder.md +0 -188
  54. package/docs/api/helpers.md +0 -106
  55. package/docs/api/i18n.md +0 -314
  56. package/docs/api/index.md +0 -108
  57. package/docs/api/libraries.md +0 -414
  58. package/docs/api/render-partial.md +0 -162
  59. package/docs/api/render.md +0 -184
  60. package/docs/api/security.md +0 -290
  61. package/docs/api/setup-express.md +0 -152
  62. package/docs/api/tags.md +0 -268
  63. package/docs/assets/banner.png +0 -0
  64. package/docs/assets/logo.png +0 -0
  65. package/docs/filter.md +0 -0
  66. package/docs/guide/advanced-usage.md +0 -794
  67. package/docs/guide/async-rendering.md +0 -616
  68. package/docs/guide/context-processors.md +0 -514
  69. package/docs/guide/custom-filters.md +0 -622
  70. package/docs/guide/custom-tags.md +0 -542
  71. package/docs/guide/filters.md +0 -1314
  72. package/docs/guide/getting-started.md +0 -204
  73. package/docs/guide/installation.md +0 -190
  74. package/docs/guide/partial-templates.md +0 -734
  75. package/docs/guide/quick-start.md +0 -444
  76. package/docs/guide/security.md +0 -690
  77. package/docs/guide/tags.md +0 -1566
  78. package/docs/guide/template-discovery.md +0 -340
  79. package/docs/guide/template-inheritance.md +0 -546
  80. package/docs/guide/what-is-miki-template.md +0 -28
  81. package/docs/guide/why-miki-template.md +0 -75
  82. package/docs/index.md +0 -86
  83. package/docs/integrations/elysia.md +0 -80
  84. package/docs/integrations/express.md +0 -219
  85. package/docs/integrations/fastify.md +0 -79
  86. package/docs/integrations/hono.md +0 -80
  87. package/docs/integrations/index.md +0 -68
  88. package/docs/integrations/koa.md +0 -90
  89. package/docs/integrations/nestjs.md +0 -80
  90. package/docs/integrations/tsed.md +0 -83
  91. package/docs/performance.md +0 -74
  92. package/eslint.config.mjs +0 -42
  93. package/ex.mjs +0 -36
  94. package/live-test/integrations/elysia-example.js +0 -16
  95. package/live-test/integrations/express-example.js +0 -24
  96. package/live-test/integrations/fastify-example.js +0 -20
  97. package/live-test/integrations/hono-example.js +0 -16
  98. package/live-test/integrations/koa-example.js +0 -30
  99. package/live-test/integrations/nestjs-example.js +0 -25
  100. package/live-test/integrations/smoke-test.js +0 -166
  101. package/live-test/integrations/tsed-example.js +0 -23
  102. package/live-test/package-lock.json +0 -1150
  103. package/live-test/package.json +0 -13
  104. package/live-test/packages/product/templates/product/detail.html +0 -7
  105. package/live-test/server.js +0 -38
  106. package/live-test/templates/app_templates/detail.html +0 -6
  107. package/live-test/views/base.html +0 -8
  108. package/live-test/views/child.html +0 -7
  109. package/live-test/views/home.html +0 -17
  110. package/live-test/views/index.html +0 -1
  111. package/miki-template-extension/.github/workflows/ci.yml +0 -116
  112. package/miki-template-extension/.vscodeignore +0 -7
  113. package/miki-template-extension/CHANGELOG.md +0 -99
  114. package/miki-template-extension/LICENSE +0 -21
  115. package/miki-template-extension/README.md +0 -273
  116. package/miki-template-extension/extension.js +0 -1013
  117. package/miki-template-extension/icon.png +0 -0
  118. package/miki-template-extension/icon.svg +0 -10
  119. package/miki-template-extension/miki-template-1.7.1.vsix +0 -0
  120. package/miki-template-extension/package.json +0 -280
  121. package/miki-template-extension/snippets/miki-template.json +0 -717
  122. package/miki-template-extension/syntaxes/language-configuration.json +0 -114
  123. package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +0 -355
  124. package/miki-template-extension/tests/grammar-tests.json +0 -162
  125. package/miki-template-extension/tests/run-grammar-tests.js +0 -82
  126. package/mkdocs.yml +0 -195
  127. package/overrides/main.html +0 -26
  128. package/requirements-docs.txt +0 -2
  129. package/sample-app/package-lock.json +0 -901
  130. package/sample-app/package.json +0 -9
  131. package/sample-app/server.js +0 -14
  132. package/sample-app/views/index.html +0 -1
  133. package/scripts/build-vsix.js +0 -129
  134. package/scripts/build-vsix.ps1 +0 -15
  135. package/snippets/miki-template.json +0 -177
  136. package/src/asyncRender.js +0 -21
  137. package/src/types.d.ts +0 -107
  138. package/syntaxes/language-configuration.json +0 -26
  139. package/syntaxes/miki-template.tmLanguage.json +0 -146
  140. package/tests/asyncRender.test.js +0 -17
  141. package/tests/base.html +0 -6
  142. package/tests/child.html +0 -3
  143. package/tests/context_processors.test.js +0 -13
  144. package/tests/esm.test.mjs +0 -61
  145. package/tests/filters.test.js +0 -263
  146. package/tests/finder-appdirs.test.js +0 -19
  147. package/tests/finder.test.js +0 -17
  148. package/tests/fixtures/views/nested/index.html +0 -1
  149. package/tests/fixtures/views/partial.html +0 -1
  150. package/tests/fixtures/views/sub/deepfile.html +0 -1
  151. package/tests/fixtures/views-appdirs/product/site/detail.html +0 -1
  152. package/tests/include_security.test.js +0 -9
  153. package/tests/integration/README.md +0 -32
  154. package/tests/integration/features.test.cjs +0 -1681
  155. package/tests/integration/features.test.mjs +0 -1697
  156. package/tests/integration/finder.esm.test.mjs +0 -13
  157. package/tests/integration/partial-render.test.cjs +0 -13
  158. package/tests/integration/templates/base.miki +0 -6
  159. package/tests/integration/templates/child.miki +0 -6
  160. package/tests/integration/templates/index.html +0 -17
  161. package/tests/lexer.test.js +0 -45
  162. package/tests/parser.test.js +0 -57
  163. package/tests/partial.html +0 -1
  164. package/tests/partialdef.test.js +0 -79
  165. package/tests/production_checks.js +0 -57
  166. package/tests/security.test.js +0 -28
  167. package/tests/tags.test.js +0 -233
package/tests/base.html DELETED
@@ -1,6 +0,0 @@
1
- <html>
2
- <body>
3
- {% block header %}Default Header{% endblock %}
4
- {% block content %}{% endblock %}
5
- </body>
6
- </html>
package/tests/child.html DELETED
@@ -1,3 +0,0 @@
1
- {% extends "base.html" %}
2
- {% block header %}Child Header ({{ block.super }}){% endblock %}
3
- {% block content %}Child Content{% endblock %}
@@ -1,13 +0,0 @@
1
- // Context Processors test using node:test
2
- const test = require('node:test');
3
- const assert = require('node:assert');
4
- const { registerContextProcessor, clearContextProcessors } = require('../src/context_processors');
5
- const { compile } = require('../src');
6
-
7
- test('Context processor injects variable', () => {
8
- clearContextProcessors();
9
- registerContextProcessor(() => ({ siteName: 'DemoSite' }));
10
- const tmpl = '{{ siteName }}';
11
- const rendered = compile(tmpl).render({});
12
- assert.strictEqual(rendered, 'DemoSite');
13
- });
@@ -1,61 +0,0 @@
1
- // Test ESM import support using the real-world default import pattern.
2
- import mikiTemplate from '../src/esm.mjs';
3
- import test from 'node:test';
4
- import assert from 'node:assert';
5
- import fs from 'node:fs';
6
- import path from 'node:path';
7
- import os from 'node:os';
8
-
9
- const {
10
- render,
11
- compile,
12
- SafeString,
13
- markSafe,
14
- __express,
15
- __expressAsync
16
- } = mikiTemplate;
17
-
18
- test('ESM - default named imports', () => {
19
- const result = render('Hello {{ name }}!', { name: 'ESM' });
20
- assert.strictEqual(result, 'Hello ESM!');
21
- });
22
-
23
- test('ESM - compile import', () => {
24
- const compiled = compile('Hi {{ user }}!');
25
- assert.strictEqual(compiled.render({ user: 'World' }), 'Hi World!');
26
- });
27
-
28
- test('ESM - SafeString import', () => {
29
- const html = new SafeString('<b>Bold</b>');
30
- const result = render('{{ html }}', { html });
31
- assert.strictEqual(result, '<b>Bold</b>');
32
- });
33
-
34
- test('ESM - markSafe import', () => {
35
- const safe = markSafe('<i>Italic</i>');
36
- const result = render('{{ x }}', { x: safe });
37
- assert.strictEqual(result, '<i>Italic</i>');
38
- });
39
-
40
- test('ESM - __express via default import', () => {
41
- assert.strictEqual(typeof mikiTemplate.__express, 'function');
42
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'miki-esm-'));
43
- const tplPath = path.join(tmpDir, 'hello.html');
44
- fs.writeFileSync(tplPath, 'Hi {{ name }}!');
45
- let result;
46
- mikiTemplate.__express(tplPath, {}, (err, html) => {
47
- result = html;
48
- });
49
- assert.strictEqual(result, 'Hi !');
50
- fs.rmSync(tmpDir, { recursive: true });
51
- });
52
-
53
- test('ESM - __expressAsync via default import', async () => {
54
- assert.strictEqual(typeof mikiTemplate.__expressAsync, 'function');
55
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'miki-esm-'));
56
- const tplPath = path.join(tmpDir, 'hello.html');
57
- fs.writeFileSync(tplPath, 'Hi {{ name }}!');
58
- const result = await mikiTemplate.__expressAsync(tplPath, {});
59
- assert.strictEqual(result, 'Hi !');
60
- fs.rmSync(tmpDir, { recursive: true });
61
- });
@@ -1,263 +0,0 @@
1
- const test = require('node:test');
2
- const assert = require('node:assert');
3
- const { getFilter } = require('../src/filters');
4
-
5
- test('Filters - Text filters', () => {
6
- const upper = getFilter('upper');
7
- assert.strictEqual(upper('hello'), 'HELLO');
8
-
9
- const capfirst = getFilter('capfirst');
10
- assert.strictEqual(capfirst('hello'), 'Hello');
11
-
12
- const truncatewords = getFilter('truncatewords');
13
- assert.strictEqual(truncatewords('one two three four', 2), 'one two ...');
14
-
15
- const slugify = getFilter('slugify');
16
- assert.strictEqual(slugify('Hello World! New-Post'), 'hello-world-new-post');
17
- });
18
-
19
- test('Filters - HTML / Security filters', () => {
20
- const safe = getFilter('safe');
21
- const escape = getFilter('escape');
22
-
23
- assert.strictEqual(String(escape('<script>')), '&lt;script&gt;');
24
- // Safe returns SafeString which resolves when cast to string
25
- assert.strictEqual(String(safe('<p>')), '<p>');
26
- });
27
-
28
- test('Filters - List filters', () => {
29
- const length = getFilter('length');
30
- assert.strictEqual(length([1, 2, 3]), 3);
31
-
32
- const join = getFilter('join');
33
- assert.strictEqual(join(['a', 'b', 'c'], '-'), 'a-b-c');
34
-
35
- const slice = getFilter('slice');
36
- assert.deepEqual(slice([1, 2, 3, 4], '1:3'), [2, 3]);
37
- });
38
-
39
- test('Filters - Default filters', () => {
40
- const def = getFilter('default');
41
- assert.strictEqual(def(null, 'fallback'), 'fallback');
42
- assert.strictEqual(def('value', 'fallback'), 'value');
43
- });
44
-
45
- test('Filters - Misc filters', () => {
46
- const pluralize = getFilter('pluralize');
47
- assert.strictEqual(pluralize(1), '');
48
- assert.strictEqual(pluralize(2), 's');
49
- assert.strictEqual(pluralize(1, 'y,ies'), 'y');
50
- assert.strictEqual(pluralize(2, 'y,ies'), 'ies');
51
- });
52
-
53
- test('Filters - urlencode and escapeuri', () => {
54
- const urlencode = getFilter('urlencode');
55
- assert.strictEqual(urlencode('hello world'), 'hello+world');
56
- assert.strictEqual(urlencode('a b c'), 'a+b+c');
57
-
58
- const escapeuri = getFilter('escapeuri');
59
- assert.ok(escapeuri('http://example.com/path with spaces').includes('path%20with%20spaces'));
60
- });
61
-
62
- test('Filters - stringformat', () => {
63
- const stringformat = getFilter('stringformat');
64
- assert.strictEqual(stringformat('hello', '%s'), 'hello');
65
- assert.strictEqual(stringformat(42, '%d'), '42');
66
- assert.strictEqual(stringformat(3.14159, '%.2f'), '3.14');
67
- });
68
-
69
- test('Filters - cut and addslashes', () => {
70
- const cut = getFilter('cut');
71
- assert.strictEqual(cut('hello hello', ' '), 'hellohello');
72
-
73
- const addslashes = getFilter('addslashes');
74
- assert.strictEqual(addslashes('He said "Hi"'), 'He said \\"Hi\\"');
75
- });
76
-
77
- test('Filters - length_is', () => {
78
- const length_is = getFilter('length_is');
79
- assert.strictEqual(length_is([1, 2, 3], 3), true);
80
- assert.strictEqual(length_is([1, 2], 3), false);
81
- });
82
-
83
- test('Filter chaining via template', () => {
84
- const { render } = require('../src/index');
85
- const result = render('{{ value|lower|capfirst }}', { value: 'Hello World' });
86
- assert.strictEqual(result, 'Hello world');
87
-
88
- const result2 = render('{{ items|length|add:5 }}', { items: [1, 2, 3] });
89
- assert.strictEqual(result2, '8');
90
- });
91
-
92
- test('Filter chaining on string literal', () => {
93
- const { render } = require('../src/index');
94
- const result = render('{{ "Hello World"|lower|capfirst }}', {});
95
- assert.strictEqual(result, 'Hello world');
96
-
97
- const result2 = render('{{ " trim me "|cut:" " }}', {});
98
- assert.strictEqual(result2, 'trimme');
99
- });
100
-
101
- test('Filters - Math filters', () => {
102
- const sub = getFilter('sub');
103
- assert.strictEqual(sub(10, 3), 7);
104
-
105
- const mult = getFilter('mult');
106
- assert.strictEqual(mult(4, 5), 20);
107
-
108
- const square = getFilter('square');
109
- assert.strictEqual(square(6), 36);
110
-
111
- const sqrt = getFilter('sqrt');
112
- assert.strictEqual(sqrt(9), 3);
113
- assert.strictEqual(sqrt(0), 0);
114
- assert.strictEqual(sqrt(-1), 0);
115
-
116
- const mod = getFilter('mod');
117
- assert.strictEqual(mod(10, 3), 1);
118
- assert.strictEqual(mod(10, 0), 0);
119
- });
120
-
121
- test('Filters - Data formatting filters', () => {
122
- const currency = getFilter('currency');
123
- assert.strictEqual(currency(1234.5), '$1,234.50');
124
- assert.strictEqual(currency(1234.5, '€'), '€1,234.50');
125
-
126
- const phone_number = getFilter('phone_number');
127
- assert.strictEqual(phone_number('1234567890'), '(123) 456-7890');
128
- assert.strictEqual(phone_number('11234567890'), '+1 (123) 456-7890');
129
-
130
- const email = getFilter('email');
131
- assert.strictEqual(email('user@example.com'), 'mailto:user@example.com');
132
-
133
- const url = getFilter('url');
134
- assert.strictEqual(url('example.com'), 'https://example.com');
135
- assert.strictEqual(url('https://example.com'), 'https://example.com');
136
-
137
- const mask = getFilter('mask');
138
- assert.strictEqual(mask('1234567890'), '******7890');
139
- assert.strictEqual(mask('1234567890', '#'), '######7890');
140
-
141
- const whatsapp_link = getFilter('whatsapp_link');
142
- assert.strictEqual(whatsapp_link('1234567890'), 'https://wa.me/1234567890');
143
- assert.strictEqual(whatsapp_link('1234567890', 'Hello'), 'https://wa.me/1234567890?text=Hello');
144
- });
145
-
146
- test('Filters - Additional Math filters (abs, round, floor, ceil)', () => {
147
- const abs = getFilter('abs');
148
- assert.strictEqual(abs(-5), 5);
149
- assert.strictEqual(abs(5), 5);
150
- assert.strictEqual(abs(0), 0);
151
-
152
- const round = getFilter('round');
153
- assert.strictEqual(round(3.14159, 2), 3.14);
154
- assert.strictEqual(round(3.5), 4);
155
- assert.strictEqual(round(3.4), 3);
156
-
157
- const floor = getFilter('floor');
158
- assert.strictEqual(floor(3.7), 3);
159
- assert.strictEqual(floor(-3.7), -4);
160
-
161
- const ceil = getFilter('ceil');
162
- assert.strictEqual(ceil(3.2), 4);
163
- assert.strictEqual(ceil(-3.2), -3);
164
- });
165
-
166
- test('Filters - min/max/sum/average', () => {
167
- const min = getFilter('min');
168
- assert.strictEqual(min([5, 2, 8, 1]), 1);
169
- assert.strictEqual(min(5, 2), 2);
170
-
171
- const max = getFilter('max');
172
- assert.strictEqual(max([5, 2, 8, 1]), 8);
173
- assert.strictEqual(max(5, 2), 5);
174
-
175
- const sum = getFilter('sum');
176
- assert.strictEqual(sum([1, 2, 3, 4]), 10);
177
- assert.strictEqual(sum([]), 0);
178
-
179
- const average = getFilter('average');
180
- assert.strictEqual(average([1, 2, 3, 4]), 2.5);
181
- assert.strictEqual(average([]), 0);
182
- });
183
-
184
- test('Filters - reverse, sort, unique, random', () => {
185
- const reverse = getFilter('reverse');
186
- assert.strictEqual(reverse('hello'), 'olleh');
187
- assert.deepEqual(reverse([1, 2, 3]), [3, 2, 1]);
188
-
189
- const sort = getFilter('sort');
190
- assert.deepEqual(sort([3, 1, 2]), [1, 2, 3]);
191
-
192
- const unique = getFilter('unique');
193
- assert.deepEqual(unique([1, 2, 2, 3]), [1, 2, 3]);
194
-
195
- const random = getFilter('random');
196
- const arr = [1, 2, 3, 4, 5];
197
- const r = random(arr);
198
- assert.ok(arr.includes(r));
199
- });
200
-
201
- test('Filters - split, replace', () => {
202
- const split = getFilter('split');
203
- assert.deepEqual(split('a,b,c', ','), ['a', 'b', 'c']);
204
- assert.deepEqual(split('hello world'), ['hello', 'world']);
205
-
206
- const replace = getFilter('replace');
207
- assert.strictEqual(replace('hello world', 'world,Earth'), 'hello Earth');
208
- });
209
-
210
- test('Filters - base64_encode, base64_decode', () => {
211
- const encode = getFilter('base64_encode');
212
- const decode = getFilter('base64_decode');
213
- assert.strictEqual(encode('hello'), 'aGVsbG8=');
214
- assert.strictEqual(decode('aGVsbG8='), 'hello');
215
- assert.strictEqual(decode('not-base64'), 'not-base64');
216
- });
217
-
218
- test('Filters - urlize, json, truncatechars_html', () => {
219
- const urlize = getFilter('urlize');
220
- assert.ok(urlize('visit https://example.com for more').includes('<a href="https://example.com">https://example.com</a>'));
221
-
222
- const json = getFilter('json');
223
- assert.ok(json({a: 1, b: 2}).value.includes('"a":1'));
224
-
225
- const truncatechars_html = getFilter('truncatechars_html');
226
- const result = truncatechars_html('<p>Hello world</p>', 10);
227
- assert.ok(result.value.includes('Hello worl'));
228
- assert.ok(result.value.includes('...'));
229
- });
230
-
231
- test('Filters - time_diff, ago, until', () => {
232
- const time_diff = getFilter('time_diff');
233
- assert.ok(time_diff(new Date(Date.now() - 3600000)).includes('hour'));
234
-
235
- const ago = getFilter('ago');
236
- assert.ok(ago(new Date(Date.now() - 86400000)).includes('day ago'));
237
-
238
- const until = getFilter('until');
239
- assert.ok(until(new Date(Date.now() + 86400000)).includes('day'));
240
- });
241
-
242
- test('Filters - credit_card, ssn, ip_address, uuid', () => {
243
- const credit_card = getFilter('credit_card');
244
- assert.strictEqual(credit_card('4111111111111111'), '4111-1111-1111-1111');
245
-
246
- const ssn = getFilter('ssn');
247
- assert.strictEqual(ssn('123456789'), '123-45-6789');
248
-
249
- const ip_address = getFilter('ip_address');
250
- assert.strictEqual(ip_address('192168011001'), '1921.6801.10.01');
251
-
252
- const uuid = getFilter('uuid');
253
- assert.ok(uuid().match(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/));
254
-
255
- test('Filters - repeat and range', () => {
256
- const repeat = getFilter('repeat');
257
- assert.strictEqual(repeat('a', 3), 'aaa');
258
- assert.strictEqual(repeat('', 5), '');
259
- const range = getFilter('range');
260
- assert.deepEqual(range('5'), [0,1,2,3,4]);
261
- assert.deepEqual(range('5', '2'), [2,3,4]);
262
- });
263
- });
@@ -1,19 +0,0 @@
1
- const test = require('node:test');
2
- const assert = require('node:assert');
3
- const path = require('path');
4
- const fs = require('fs');
5
- const { findTemplateInViews, setAppTemplateDirNames } = require('../src/index.js');
6
-
7
- test('Finder honors custom app template dir names', () => {
8
- const fixtures = path.join(__dirname, 'fixtures', 'views-appdirs');
9
- // Create a small fixture structure
10
- if (!fs.existsSync(path.join(fixtures, 'product', 'site'))){
11
- fs.mkdirSync(path.join(fixtures, 'product', 'site'), { recursive: true });
12
- }
13
- const fname = path.join(fixtures, 'product', 'site', 'detail.html');
14
- fs.writeFileSync(fname, '<p>detail</p>');
15
-
16
- setAppTemplateDirNames(['site']);
17
- const found = findTemplateInViews('detail', [fixtures]);
18
- assert.ok(found && fs.existsSync(found));
19
- });
@@ -1,17 +0,0 @@
1
- const test = require('node:test');
2
- const assert = require('node:assert');
3
- const path = require('path');
4
- const fs = require('fs');
5
- const { findTemplateInViews } = require('../src/index.js');
6
-
7
- test('Template finder - nested subfolder', () => {
8
- const views = [path.join(__dirname, 'fixtures', 'views')];
9
- const found = findTemplateInViews('nested/index', views);
10
- assert.ok(found && fs.existsSync(found));
11
- });
12
-
13
- test('Template finder - bare name searches subfolders', () => {
14
- const views = [path.join(__dirname, 'fixtures', 'views')];
15
- const found = findTemplateInViews('deepfile', views);
16
- assert.ok(found && fs.existsSync(found));
17
- });
@@ -1 +0,0 @@
1
- <h1>Nested Index</h1>
@@ -1 +0,0 @@
1
- <p>Included: {{ item }}</p>
@@ -1 +0,0 @@
1
- <div>Deep file</div>
@@ -1 +0,0 @@
1
- <p>detail</p>
@@ -1,9 +0,0 @@
1
- const test = require('node:test');
2
- const assert = require('node:assert');
3
- const { render } = require('../src/index');
4
-
5
- test('Security - include path traversal prevented', () => {
6
- const tpl = `{% include "../secret.html" %}`;
7
- // Expect an error indicating path traversal
8
- assert.throws(() => render(tpl, {}, { views: '.' }), /path traversal/);
9
- });
@@ -1,32 +0,0 @@
1
- # Express Integration Test (CommonJS + ESM)
2
-
3
- This is a **real**, end-to-end integration test for `miki-template` with Express. It:
4
-
5
- - Spins up **actual Express HTTP servers** (one CJS, one ESM).
6
- - Uses `app.engine('html', renderDtpl)` AND `app.engine('miki', renderDtpl)`.
7
- - Verifies both file extensions render correctly via real `res.render()`.
8
- - Performs real HTTP `fetch` requests against the listening servers and asserts the rendered HTML.
9
- - Verifies ESM `import` syntax (named + default) and CommonJS `require` syntax both work.
10
-
11
- ## What it proves to users
12
-
13
- ```js
14
- // CommonJS
15
- const express = require('express');
16
- const { __express: renderDtpl } = require('miki-template');
17
- const app = express();
18
- app.engine('html', renderDtpl);
19
- app.engine('miki', renderDtpl);
20
- ```
21
-
22
- ```js
23
- // ESM
24
- import express from 'express';
25
- import { __express as renderDtpl } from 'miki-template';
26
- import mikiTemplate from 'miki-template'; // default import also works
27
- const app = express();
28
- app.engine('html', renderDtpl);
29
- app.engine('miki', renderDtpl);
30
- ```
31
-
32
- Both forms register the engine for `.html` and `.miki` extensions, just as the README documents.