miki-template 1.2.0 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/release-notes/v1.3.1.md +55 -0
- package/.github/release-notes/v1.3.3.md +77 -0
- package/.github/workflows/ci.yml +38 -54
- package/.github/workflows/release.yml +106 -0
- package/AGENT.md +71 -71
- package/API_REFERENCE.md +314 -314
- package/CHANGELOG.md +173 -97
- package/CODE_OF_CONDUCT.md +14 -14
- package/CONTRIBUTING.md +27 -27
- package/README.md +342 -304
- package/ROADMAP.md +40 -40
- package/assets/banner.png +0 -0
- package/benchmarks/report.json +16 -16
- package/benchmarks/run.js +49 -49
- package/benchmarks/stress.mjs +647 -0
- package/benchmarks/templates/large.dtpl +7 -7
- package/benchmarks/templates/medium.dtpl +3 -3
- package/benchmarks/templates/small.dtpl +7 -7
- package/context/component.md +109 -109
- package/context/prd.md +131 -131
- package/context/project-structure.md +33 -33
- package/dir/base.html +23 -0
- package/dir/cmpnt.html +11 -0
- package/dir/footer.html +3 -0
- package/dir/home.html +80 -0
- package/dir/index.html +80 -0
- package/dir/navbar.html +9 -0
- package/docs/README.md +18 -18
- package/docs/advanced_usage.md +71 -71
- package/docs/api.md +119 -102
- package/docs/filters.md +708 -540
- package/docs/installation.md +106 -106
- package/docs/overview.md +57 -57
- package/docs/partialdef.md +70 -41
- package/docs/security.md +27 -27
- package/docs/tags.md +673 -610
- package/docs/usage.md +646 -599
- package/eslint.config.mjs +42 -34
- package/ex.mjs +33 -0
- package/miki-template-extension/.github/workflows/ci.yml +116 -0
- package/miki-template-extension/.vscodeignore +7 -0
- package/miki-template-extension/CHANGELOG.md +99 -0
- package/miki-template-extension/LICENSE +21 -21
- package/miki-template-extension/README.md +273 -82
- package/miki-template-extension/extension.js +1013 -0
- package/miki-template-extension/icon.png +0 -0
- package/miki-template-extension/icon.svg +10 -10
- package/miki-template-extension/miki-template-1.7.1.vsix +0 -0
- package/miki-template-extension/package.json +280 -46
- package/miki-template-extension/snippets/miki-template.json +717 -177
- package/miki-template-extension/syntaxes/language-configuration.json +114 -26
- package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +355 -146
- package/miki-template-extension/tests/grammar-tests.json +162 -0
- package/miki-template-extension/tests/run-grammar-tests.js +82 -0
- package/package.json +37 -31
- package/sample-app/package-lock.json +901 -0
- package/sample-app/package.json +9 -0
- package/sample-app/server.js +14 -0
- package/sample-app/views/index.html +1 -0
- package/scripts/build-vsix.js +129 -0
- package/scripts/build-vsix.ps1 +15 -0
- package/snippets/miki-template.json +177 -177
- package/src/asyncRender.js +20 -20
- package/src/cache.js +80 -41
- package/src/context.js +126 -122
- package/src/context_processors.js +48 -41
- package/src/esm.mjs +84 -72
- package/src/filters.js +975 -527
- package/src/i18n.js +171 -171
- package/src/index.js +974 -454
- package/src/lexer.js +114 -92
- package/src/libraries.js +371 -240
- package/src/parser.js +270 -250
- package/src/security.js +53 -51
- package/src/tags/control.js +719 -590
- package/src/tags/extra.js +154 -0
- package/src/tags/helpers.js +26 -26
- package/src/tags/i18n.js +256 -230
- package/src/tags/inheritance.js +335 -216
- package/src/tags/registry.js +18 -18
- package/src/tags/util.js +400 -322
- package/src/types.d.ts +107 -107
- package/syntaxes/language-configuration.json +26 -26
- package/syntaxes/miki-template.tmLanguage.json +146 -146
- package/tests/asyncRender.test.js +17 -17
- package/tests/base.html +6 -6
- package/tests/child.html +3 -3
- package/tests/context_processors.test.js +13 -13
- package/tests/esm.test.mjs +61 -26
- package/tests/filters.test.js +254 -99
- package/tests/include_security.test.js +9 -9
- package/tests/integration/README.md +32 -0
- package/tests/integration/features.test.cjs +1681 -0
- package/tests/integration/features.test.mjs +1697 -0
- package/tests/integration/templates/base.miki +6 -0
- package/tests/integration/templates/child.miki +6 -0
- package/tests/integration/templates/index.html +17 -0
- package/tests/lexer.test.js +45 -45
- package/tests/parser.test.js +57 -55
- package/tests/partial.html +1 -1
- package/tests/partialdef.test.js +79 -40
- package/tests/production_checks.js +57 -57
- package/tests/security.test.js +28 -28
- package/tests/tags.test.js +233 -203
- package/miki-template-1.2.0.vsix +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
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'));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<html><head><title>{{ name }}</title></head><body><h1>Hello {{ name }}</h1></body></html>
|
|
@@ -0,0 +1,129 @@
|
|
|
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);
|
|
@@ -0,0 +1,15 @@
|
|
|
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 +1,177 @@
|
|
|
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
|
+
{
|
|
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
|
+
}
|
package/src/asyncRender.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
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
|
-
|
|
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
21
|
module.exports = { asyncRenderAST };
|