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
@@ -1,9 +0,0 @@
1
- {
2
- "name": "sample-app",
3
- "version": "1.0.0",
4
- "private": true,
5
- "dependencies": {
6
- "express": "^5.2.1",
7
- "miki-template": "file:.."
8
- }
9
- }
@@ -1,14 +0,0 @@
1
- const express = require('express');
2
- const path = require('path');
3
- const miki = require('miki-template');
4
-
5
- const app = express();
6
- const views = path.join(__dirname, 'views');
7
-
8
- miki.setupExpress(app, { extension: 'html', views });
9
-
10
- app.get('/', (req, res) => {
11
- res.render('index', { name: 'Host App' });
12
- });
13
-
14
- app.listen(3001, () => console.log('Sample app listening on 3001'));
@@ -1 +0,0 @@
1
- <html><head><title>{{ name }}</title></head><body><h1>Hello {{ name }}</h1></body></html>
@@ -1,129 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const zlib = require('zlib');
4
-
5
- const extDir = 'miki-template-extension';
6
- const buildDir = 'miki-template-extension/.vsix-build';
7
- const vsixPath = 'miki-template-1.2.0.vsix';
8
-
9
- if (fs.existsSync(buildDir)) fs.rmSync(buildDir, { recursive: true });
10
- if (fs.existsSync(vsixPath)) fs.unlinkSync(vsixPath);
11
-
12
- fs.mkdirSync(buildDir, { recursive: true });
13
- const extTarget = path.join(buildDir, 'extension');
14
- fs.mkdirSync(extTarget, { recursive: true });
15
-
16
- function copyDirSync(src, dest) {
17
- fs.readdirSync(src).forEach(item => {
18
- const s = path.join(src, item);
19
- const d = path.join(dest, item);
20
- if (fs.statSync(s).isDirectory()) {
21
- fs.mkdirSync(d, { recursive: true });
22
- copyDirSync(s, d);
23
- } else {
24
- fs.copyFileSync(s, d);
25
- }
26
- });
27
- }
28
-
29
- copyDirSync(extDir, extTarget);
30
-
31
- const manifest = '<?xml version="1.0" encoding="utf-8"?><PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011"><Metadata><Identity Id="alainmiki.miki-template" Version="1.2.0" Language="en-US" Publisher="alainmiki" /><DisplayName>miki-template</DisplayName><Description>Django-style template language syntax highlighting and snippets for miki-template</Description><Tags>django template miki syntax highlight snippet</Tags><Categories>Programming Languages,Snippets</Categories><GalleryFlags>Public</GalleryFlags><License>LICENSE</License><Icon>extension/icon.png</Icon></Metadata><Installation><InstallationTarget Id="Microsoft.VisualStudio.Code" /></Installation><Dependencies /><Assets><Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Content" Path="extension/syntaxes/miki-template.tmLanguage.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Content" Path="extension/syntaxes/language-configuration.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Snippet" Path="extension/snippets/miki-template.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Image" Path="extension/icon.png" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Image" Path="extension/icon.svg" Addressable="true" /></Assets></PackageManifest>';
32
- const ct = '<?xml version="1.0" encoding="utf-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="json" ContentType="application/json" /><Default Extension="png" ContentType="image/png" /><Default Extension="svg" ContentType="image/svg+xml" /><Default Extension="md" ContentType="text/markdown" /></Types>';
33
- fs.writeFileSync(path.join(buildDir, 'extension.vsixmanifest'), manifest);
34
- fs.writeFileSync(path.join(buildDir, '[Content_Types].xml'), ct);
35
-
36
- const files = [];
37
- function collectFiles(dir, base) {
38
- fs.readdirSync(dir).forEach(item => {
39
- const s = path.join(dir, item);
40
- const d = path.join(base, item);
41
- if (fs.statSync(s).isDirectory()) {
42
- collectFiles(s, d);
43
- } else {
44
- files.push({ path: d, content: fs.readFileSync(s) });
45
- }
46
- });
47
- }
48
- collectFiles(buildDir, '');
49
-
50
- function crc32(buf) {
51
- let crc = 0xFFFFFFFF;
52
- const table = new Uint32Array(256);
53
- for (let i = 0; i < 256; i++) {
54
- let c = i;
55
- for (let j = 0; j < 8; j++) c = (c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1);
56
- table[i] = c;
57
- }
58
- for (let i = 0; i < buf.length; i++) crc = table[(crc ^ buf[i]) & 0xFF] ^ (crc >>> 8);
59
- return (crc ^ 0xFFFFFFFF) >>> 0;
60
- }
61
-
62
- const localFiles = [];
63
- const centralDir = [];
64
- let offset = 0;
65
-
66
- for (const file of files) {
67
- const pathBytes = Buffer.from(file.path);
68
- const data = file.content;
69
- const compressed = zlib.deflateSync(data);
70
- const crc = crc32(data);
71
-
72
- const localHeader = Buffer.alloc(30);
73
- localHeader.writeUInt32LE(0x04034b50, 0);
74
- localHeader.writeUInt16LE(20, 4);
75
- localHeader.writeUInt16LE(0, 6);
76
- localHeader.writeUInt16LE(8, 8);
77
- localHeader.writeUInt16LE(0, 10);
78
- localHeader.writeUInt16LE(0, 12);
79
- localHeader.writeUInt32LE(crc, 14);
80
- localHeader.writeUInt32LE(compressed.length, 18);
81
- localHeader.writeUInt32LE(data.length, 22);
82
- localHeader.writeUInt16LE(pathBytes.length, 26);
83
- localHeader.writeUInt16LE(0, 28);
84
-
85
- const localFile = Buffer.concat([localHeader, pathBytes, compressed]);
86
- localFiles.push(localFile);
87
-
88
- const centralHeader = Buffer.alloc(46);
89
- centralHeader.writeUInt32LE(0x02014b50, 0);
90
- centralHeader.writeUInt16LE(20, 4);
91
- centralHeader.writeUInt16LE(20, 6);
92
- centralHeader.writeUInt16LE(0, 8);
93
- centralHeader.writeUInt16LE(8, 10);
94
- centralHeader.writeUInt16LE(0, 12);
95
- centralHeader.writeUInt16LE(0, 14);
96
- centralHeader.writeUInt32LE(crc, 16);
97
- centralHeader.writeUInt32LE(compressed.length, 20);
98
- centralHeader.writeUInt32LE(data.length, 24);
99
- centralHeader.writeUInt16LE(pathBytes.length, 28);
100
- centralHeader.writeUInt16LE(0, 30);
101
- centralHeader.writeUInt16LE(0, 32);
102
- centralHeader.writeUInt16LE(0, 34);
103
- centralHeader.writeUInt16LE(0, 36);
104
- centralHeader.writeUInt32LE(0, 38);
105
- centralHeader.writeUInt32LE(offset, 42);
106
-
107
- const centralEntry = Buffer.concat([centralHeader, pathBytes]);
108
- centralDir.push(centralEntry);
109
-
110
- offset += localFile.length;
111
- }
112
-
113
- const centralDirOffset = offset;
114
- const centralDirSize = centralDir.reduce((sum, entry) => sum + entry.length, 0);
115
- const endRecord = Buffer.alloc(22);
116
- endRecord.writeUInt32LE(0x06054b50, 0);
117
- endRecord.writeUInt16LE(0, 4);
118
- endRecord.writeUInt16LE(0, 6);
119
- endRecord.writeUInt16LE(centralDir.length, 8);
120
- endRecord.writeUInt16LE(centralDir.length, 10);
121
- endRecord.writeUInt32LE(centralDirSize, 12);
122
- endRecord.writeUInt32LE(centralDirOffset, 16);
123
- endRecord.writeUInt16LE(0, 20);
124
-
125
- const zipBuffer = Buffer.concat([...localFiles, ...centralDir, endRecord]);
126
- fs.writeFileSync(vsixPath, zipBuffer);
127
-
128
- if (fs.existsSync(buildDir)) fs.rmSync(buildDir, { recursive: true });
129
- console.log('VSIX created:', vsixPath, 'size:', zipBuffer.length);
@@ -1,15 +0,0 @@
1
- $ErrorActionPreference = 'Stop'
2
- $extDir = Join-Path $PWD 'miki-template-extension'
3
- $vsixPath = Join-Path $PWD 'miki-template-1.2.0.vsix'
4
- if (Test-Path $vsixPath) { Remove-Item $vsixPath -Force }
5
- $tempDir = Join-Path $env:TEMP ('vsix-build-' + [Guid]::NewGuid().ToString('N').Substring(0,8))
6
- New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
7
- $extTarget = Join-Path $tempDir 'extension'
8
- Copy-Item -Path $extDir -Destination $extTarget -Recurse -Force
9
- $manifest = '<?xml version="1.0" encoding="utf-8"?><PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011"><Metadata><Identity Id="alainmiki.miki-template" Version="1.2.0" Language="en-US" Publisher="alainmiki" /><DisplayName>miki-template</DisplayName><Description>Django-style template language syntax highlighting and snippets for miki-template</Description><Tags>django template miki syntax highlight snippet</Tags><Categories>Programming Languages,Snippets</Categories><GalleryFlags>Public</GalleryFlags><License>LICENSE</License><Icon>extension/icon.png</Icon></Metadata><Installation><InstallationTarget Id="Microsoft.VisualStudio.Code" /></Installation><Dependencies /><Assets><Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Content" Path="extension/syntaxes/miki-template.tmLanguage.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Content" Path="extension/syntaxes/language-configuration.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Snippet" Path="extension/snippets/miki-template.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Image" Path="extension/icon.png" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Image" Path="extension/icon.svg" Addressable="true" /></Assets></PackageManifest>'
10
- Set-Content -Path (Join-Path $tempDir 'extension.vsixmanifest') -Value $manifest -Encoding UTF8
11
- $ct = '<?xml version="1.0" encoding="utf-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="json" ContentType="application/json" /><Default Extension="png" ContentType="image/png" /><Default Extension="svg" ContentType="image/svg+xml" /><Default Extension="md" ContentType="text/markdown" /></Types>'
12
- Set-Content -Path (Join-Path $tempDir '[Content_Types].xml') -Value $ct -Encoding UTF8
13
- Compress-Archive -Path (Join-Path $tempDir '*') -DestinationPath $vsixPath -Force
14
- Remove-Item $tempDir -Recurse -Force
15
- Write-Host "VSIX created at $vsixPath"
@@ -1,177 +0,0 @@
1
- {
2
- "miki-template": {
3
- "if": {
4
- "prefix": "if",
5
- "body": [
6
- "{% if ${1:condition} %}",
7
- " ${2:content}",
8
- "{% endif %}"
9
- ],
10
- "description": "If block"
11
- },
12
- "ifelse": {
13
- "prefix": "ifelse",
14
- "body": [
15
- "{% if ${1:condition} %}",
16
- " ${2:content}",
17
- "{% else %}",
18
- " ${3:fallback}",
19
- "{% endif %}"
20
- ],
21
- "description": "If/else block"
22
- },
23
- "for": {
24
- "prefix": "for",
25
- "body": [
26
- "{% for ${1:item} in ${2:items} %}",
27
- " ${3:{{ ${1} }}}",
28
- "{% empty %}",
29
- " ${4:No items}",
30
- "{% endfor %}"
31
- ],
32
- "description": "For loop"
33
- },
34
- "block": {
35
- "prefix": "block",
36
- "body": [
37
- "{% block ${1:name} %}",
38
- " ${2:content}",
39
- "{% endblock %}"
40
- ],
41
- "description": "Block definition"
42
- },
43
- "extends": {
44
- "prefix": "extends",
45
- "body": "{% extends \"${1:base.html}\" %}",
46
- "description": "Extends parent template"
47
- },
48
- "include": {
49
- "prefix": "include",
50
- "body": "{% include \"${1:header.html}\" %}",
51
- "description": "Include template"
52
- },
53
- "with": {
54
- "prefix": "with",
55
- "body": [
56
- "{% with ${1:var} as ${2:alias} %}",
57
- " ${3:{{ ${2} }}}",
58
- "{% endwith %}"
59
- ],
60
- "description": "With block"
61
- },
62
- "cycle": {
63
- "prefix": "cycle",
64
- "body": "{% cycle '${1:odd}' '${2:even}' %}",
65
- "description": "Cycle tag"
66
- },
67
- "trans": {
68
- "prefix": "trans",
69
- "body": "{% trans \"${1:Hello, World!}\" %}",
70
- "description": "Translate string"
71
- },
72
- "blocktrans": {
73
- "prefix": "blocktrans",
74
- "body": [
75
- "{% blocktrans with ${1:name}=${2:user.name} %}",
76
- " ${3:Hello {{ ${1} }}}",
77
- "{% endblocktrans %}"
78
- ],
79
- "description": "Translate block"
80
- },
81
- "language": {
82
- "prefix": "language",
83
- "body": [
84
- "{% language \"${1:fr}\" %}",
85
- " ${2}",
86
- "{% endlanguage %}"
87
- ],
88
- "description": "Switch language"
89
- },
90
- "partialdef": {
91
- "prefix": "partialdef",
92
- "body": [
93
- "{% partialdef ${1:name} %}",
94
- " ${2}",
95
- "{% endpartialdef %}"
96
- ],
97
- "description": "Define partial"
98
- },
99
- "partial": {
100
- "prefix": "partial",
101
- "body": "{% partial ${1:name} %}",
102
- "description": "Render partial"
103
- },
104
- "csrf": {
105
- "prefix": "csrf",
106
- "body": "{% csrf_token %}",
107
- "description": "CSRF token input"
108
- },
109
- "csp": {
110
- "prefix": "csp",
111
- "body": "<script {% csp_nonce_attr %}></script>",
112
- "description": "CSP nonce attribute"
113
- },
114
- "static": {
115
- "prefix": "static",
116
- "body": "{% static \"${1:css/app.css}\" %}",
117
- "description": "Static file URL"
118
- },
119
- "url": {
120
- "prefix": "url",
121
- "body": "{% url \"${1:route_name}\" ${2:args} %}",
122
- "description": "URL for named route"
123
- },
124
- "widthratio": {
125
- "prefix": "widthratio",
126
- "body": "{% widthratio ${1:value} ${2:max} ${3:max_width} %}",
127
- "description": "Proportional width"
128
- },
129
- "debug": {
130
- "prefix": "debug",
131
- "body": "{% debug %}",
132
- "description": "Dump template context"
133
- },
134
- "load": {
135
- "prefix": "load",
136
- "body": "{% load ${1:i18n} %}",
137
- "description": "Load tag library"
138
- },
139
- "comment": {
140
- "prefix": "comment",
141
- "body": [
142
- "{#",
143
- " ${1:comment}",
144
- "#}"
145
- ],
146
- "description": "Comment block"
147
- },
148
- "verbatim": {
149
- "prefix": "verbatim",
150
- "body": [
151
- "{% verbatim %}",
152
- " ${1}",
153
- "{% endverbatim %}"
154
- ],
155
- "description": "Verbatim block"
156
- },
157
- "regroup": {
158
- "prefix": "regroup",
159
- "body": "{% for ${1:group} in ${2:items}|regroup:\"${3:category}\" %}{{ ${1}.grouper }}{% endfor %}",
160
- "description": "Regroup by attribute"
161
- },
162
- "firstof": {
163
- "prefix": "firstof",
164
- "body": "{% firstof ${1:var1} ${2:var2} \"${3:fallback}\" %}",
165
- "description": "First truthy value"
166
- },
167
- "filter_block": {
168
- "prefix": "filter",
169
- "body": [
170
- "{% filter ${1:lower} %}",
171
- " ${2}",
172
- "{% endfilter %}"
173
- ],
174
- "description": "Filter block"
175
- }
176
- }
177
- }
@@ -1,21 +0,0 @@
1
- // Async rendering utilities
2
-
3
- /**
4
- * Async version of renderAST that awaits any Promise returned by node.render.
5
- * Handles async nodes anywhere in the AST (inside conditionals, loops, etc.)
6
- */
7
- async function asyncRenderAST(nodes, context) {
8
- // Helper to render a single node, awaiting if needed, and recursively handling children
9
- const renderNode = async (node) => {
10
- const result = node.render(context);
11
- return result instanceof Promise ? await result : result;
12
- };
13
-
14
- const parts = [];
15
- for (const node of nodes) {
16
- parts.push(await renderNode(node));
17
- }
18
- return parts.join('');
19
- }
20
-
21
- module.exports = { asyncRenderAST };
package/src/types.d.ts DELETED
@@ -1,107 +0,0 @@
1
- /**
2
- * TypeScript definitions for miki-template
3
- * Generated manually to match the actual runtime API.
4
- */
5
-
6
- declare namespace miki {
7
- /**
8
- * A compiled template instance returned by `compile()`.
9
- */
10
- interface CompiledTemplate {
11
- /** Synchronously render the template. */
12
- render(context?: TemplateContext): string;
13
- /** Asynchronously render the template (awaits Promise helpers). */
14
- asyncRender(context?: TemplateContext): Promise<string>;
15
- /** Render a single named block. */
16
- renderBlock(blockName: string, context?: TemplateContext): string;
17
- /** Render a defined `{% partialdef %}` by name. */
18
- renderPartial(partialName: string, context?: TemplateContext): string;
19
- }
20
-
21
- /** Context object passed to render functions. */
22
- interface TemplateContext {
23
- [key: string]: any;
24
- }
25
-
26
- /** Options for `compile()` and `render()`. */
27
- interface CompileOptions {
28
- /** Directories to search for `extends`/`include` templates. */
29
- views?: string | string[];
30
- /** Prefix for the `{% static %}` tag. */
31
- staticUrl?: string;
32
- /** Custom URL resolver for `{% url %}` tag. */
33
- urlHelper?: (routeName: string, ...args: any[]) => string;
34
- }
35
-
36
- /** A custom filter function. */
37
- type FilterFunction = (value: any, arg?: any) => any;
38
-
39
- /** A custom tag parser function. */
40
- type TagParserFunction = (tagContent: string, parser: any) => ASTNode;
41
-
42
- /** A custom helper function (block tag). */
43
- type HelperFunction = (content: string, context: any) => string | Promise<string>;
44
-
45
- /** A context processor. */
46
- type ContextProcessor = (context: TemplateContext) => TemplateContext | void;
47
-
48
- /** An AST node with a `render(context)` method. */
49
- interface ASTNode {
50
- render(context: any): string | Promise<string>;
51
- }
52
-
53
- /**
54
- * SafeString — a string marker that bypasses HTML auto-escaping.
55
- */
56
- class SafeString {
57
- constructor(value: string);
58
- toString(): string;
59
- }
60
- }
61
-
62
- declare module "miki-template" {
63
- export = miki;
64
- export as namespace miki;
65
-
66
- /** Compile a template string into a reusable renderable object. */
67
- export function compile(templateStr: string, options?: miki.CompileOptions): miki.CompiledTemplate;
68
-
69
- /** One-off template render. */
70
- export function render(templateStr: string, context?: miki.TemplateContext, options?: miki.CompileOptions): string;
71
-
72
- /** Async one-off render (supports async helpers). */
73
- export function asyncRender(templateStr: string, context?: miki.TemplateContext, options?: miki.CompileOptions): Promise<string>;
74
-
75
- /** Express view engine adapter. */
76
- export function __express(filePath: string, options: miki.TemplateContext, callback: (err: Error | null, html?: string) => void): void;
77
-
78
- /** Async Express view engine adapter (Express 5+). */
79
- export function __expressAsync(filePath: string, options: miki.TemplateContext): Promise<string>;
80
-
81
- /** Clear the in-memory compiled template cache. */
82
- export function clearCache(): void;
83
-
84
- /** Register a custom tag parser. */
85
- export function registerTag(name: string, parserFn: miki.TagParserFunction): void;
86
-
87
- /** Register a custom filter. */
88
- export function registerFilter(name: string, filterFn: miki.FilterFunction): void;
89
-
90
- /** Register a custom block helper. */
91
- export function registerHelper(name: string, fn: miki.HelperFunction): void;
92
-
93
- /** Register a context processor. */
94
- export function registerContextProcessor(fn: miki.ContextProcessor): void;
95
-
96
- /** Mark a value as HTML-safe (bypasses auto-escaping). */
97
- export function markSafe(value: any): miki.SafeString;
98
-
99
- /** Check if a value is a SafeString. */
100
- export function isSafe(value: any): boolean;
101
-
102
- /** Escape HTML special characters. */
103
- export function escapeHtml(str: string): string;
104
-
105
- /** SafeString class for marking values as safe. */
106
- export const SafeString: typeof miki.SafeString;
107
- }
@@ -1,26 +0,0 @@
1
- {
2
- "comments": {
3
- "lineComment": "{#",
4
- "blockComment": ["{#", "#}"]
5
- },
6
- "brackets": [
7
- ["{", "}"],
8
- ["[", "]"],
9
- ["(", ")"]
10
- ],
11
- "autoClosingPairs": [
12
- { "open": "{", "close": "}" },
13
- { "open": "[", "close": "]" },
14
- { "open": "(", "close": ")" },
15
- { "open": "\"", "close": "\"", "notIn": ["string"] },
16
- { "open": "'", "close": "'", "notIn": ["string", "comment"] }
17
- ],
18
- "surroundingPairs": [
19
- { "open": "{", "close": "}" },
20
- { "open": "[", "close": "]" },
21
- { "open": "(", "close": ")" },
22
- { "open": "\"", "close": "\"" },
23
- { "open": "'", "close": "'" }
24
- ],
25
- "wordPattern": "[a-zA-Z_][a-zA-Z0-9_.]*"
26
- }
@@ -1,146 +0,0 @@
1
- {
2
- "scopeName": "text.html.miki",
3
- "name": "miki-template",
4
- "patterns": [
5
- {
6
- "include": "#comment"
7
- },
8
- {
9
- "include": "#tag"
10
- },
11
- {
12
- "include": "#variable"
13
- },
14
- {
15
- "include": "#string"
16
- }
17
- ],
18
- "repository": {
19
- "comment": {
20
- "name": "comment.block.miki",
21
- "begin": "\\{#",
22
- "end": "#\\}",
23
- "beginCaptures": {
24
- "0": { "name": "punctuation.definition.comment.begin.miki" }
25
- },
26
- "endCaptures": {
27
- "0": { "name": "punctuation.definition.comment.end.miki" }
28
- }
29
- },
30
- "tag": {
31
- "name": "meta.tag.miki",
32
- "begin": "\\{%",
33
- "end": "%\\}",
34
- "beginCaptures": {
35
- "0": { "name": "punctuation.definition.tag.begin.miki" }
36
- },
37
- "endCaptures": {
38
- "0": { "name": "punctuation.definition.tag.end.miki" }
39
- },
40
- "patterns": [
41
- {
42
- "name": "entity.name.tag.miki",
43
- "match": "(?i)\\b(if|elif|else|endif|for|empty|endfor|with|endwith|cycle|comment|endcomment|verbatim|endverbatim|include|extends|block|endblock|partialdef|endpartialdef|partial|load|templatetag|trans|blocktrans|language|endlanguage|plural|widthratio|debug|endif|endfor|endwith|endblock|endcomment|endverbatim|endpartialdef|endblocktrans|endlanguage|endcache|endmarkdown)\\b"
44
- },
45
- {
46
- "name": "string.quoted.double.miki",
47
- "match": "\"[^\"]*\""
48
- },
49
- {
50
- "name": "string.quoted.single.miki",
51
- "match": "'[^']*'"
52
- },
53
- {
54
- "name": "constant.numeric.miki",
55
- "match": "\\b\\d+\\b"
56
- },
57
- {
58
- "name": "keyword.operator.miki",
59
- "match": "(?i)\\b(and|or|not|in|not in)\\b"
60
- },
61
- {
62
- "name": "punctuation.separator.miki",
63
- "match": "="
64
- }
65
- ]
66
- },
67
- "variable": {
68
- "name": "variable.other.miki",
69
- "begin": "\\{\\{",
70
- "end": "\\}\\}",
71
- "beginCaptures": {
72
- "0": { "name": "punctuation.definition.variable.begin.miki" }
73
- },
74
- "endCaptures": {
75
- "0": { "name": "punctuation.definition.variable.end.miki" }
76
- },
77
- "patterns": [
78
- {
79
- "name": "variable.other.miki",
80
- "match": "[a-zA-Z_][a-zA-Z0-9_.]*"
81
- },
82
- {
83
- "include": "#filter"
84
- },
85
- {
86
- "name": "string.quoted.double.miki",
87
- "match": "\"[^\"]*\""
88
- },
89
- {
90
- "name": "string.quoted.single.miki",
91
- "match": "'[^']*'"
92
- }
93
- ]
94
- },
95
- "filter": {
96
- "name": "meta.filter.miki",
97
- "begin": "\\|",
98
- "end": "(?=\\}|$)",
99
- "beginCaptures": {
100
- "0": { "name": "punctuation.separator.filter.miki" }
101
- },
102
- "patterns": [
103
- {
104
- "name": "support.function.miki",
105
- "match": "[a-zA-Z_][a-zA-Z0-9_]*"
106
- },
107
- {
108
- "begin": ":",
109
- "beginCaptures": {
110
- "0": { "name": "punctuation.separator.filter.argument.miki" }
111
- },
112
- "end": "(?=\\||\\}\\})",
113
- "patterns": [
114
- {
115
- "name": "string.quoted.double.miki",
116
- "match": "\"[^\"]*\""
117
- },
118
- {
119
- "name": "string.quoted.single.miki",
120
- "match": "'[^']*'"
121
- },
122
- {
123
- "name": "constant.numeric.miki",
124
- "match": "\\b\\d+\\b"
125
- },
126
- {
127
- "name": "variable.other.miki",
128
- "match": "[a-zA-Z_][a-zA-Z0-9_.]*"
129
- }
130
- ]
131
- }
132
- ]
133
- },
134
- "string": {
135
- "name": "string.quoted.double.miki",
136
- "begin": "\"",
137
- "end": "\"",
138
- "beginCaptures": {
139
- "0": { "name": "punctuation.definition.string.begin.miki" }
140
- },
141
- "endCaptures": {
142
- "0": { "name": "punctuation.definition.string.end.miki" }
143
- }
144
- }
145
- }
146
- }
@@ -1,17 +0,0 @@
1
- // tests/asyncRender.test.js
2
- const test = require('node:test');
3
- const { asyncRender, registerHelper } = require('../src');
4
-
5
- // Register a simple async helper that sleeps
6
- registerHelper('sleep', async (content) => {
7
- const ms = parseInt(content, 10) || 0;
8
- await new Promise(r => setTimeout(r, ms));
9
- return `slept ${ms}ms`;
10
- });
11
-
12
- test('asyncRender with sleep helper', async () => {
13
- const tmpl = `{% sleep %}30{% endsleep %}`;
14
- const result = await asyncRender(tmpl, {});
15
- const assert = require('node:assert');
16
- assert.strictEqual(result, 'slept 30ms');
17
- });