Skip to content

Commit 9c8762a

Browse files
committed
feat: add basic util methods
1 parent 0f9a29d commit 9c8762a

File tree

5 files changed

+775
-356
lines changed

5 files changed

+775
-356
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@typescript-eslint"
1010
],
1111
"rules": {
12-
"@typescript-eslint/class-name-casing": "warn",
12+
"@typescript-eslint/naming-convention": "warn",
1313
"@typescript-eslint/semi": "warn",
1414
"curly": "warn",
1515
"eqeqeq": "warn",

package.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,27 +117,28 @@
117117
"devDependencies": {
118118
"@semantic-release/changelog": "^5.0.1",
119119
"@semantic-release/commit-analyzer": "^8.0.1",
120-
"@semantic-release/github": "^7.0.5",
120+
"@semantic-release/github": "^7.1.1",
121121
"@semantic-release/release-notes-generator": "^9.0.1",
122-
"@types/glob": "^7.1.1",
123-
"@types/mocha": "^7.0.2",
124-
"@types/node": "^13.11.0",
125-
"@types/vscode": "^1.44.0",
126-
"@typescript-eslint/eslint-plugin": "^2.26.0",
127-
"@typescript-eslint/parser": "^2.26.0",
128-
"commitizen": "^4.0.4",
129-
"cz-conventional-changelog": "^3.1.0",
130-
"eslint": "^6.8.0",
122+
"@types/glob": "^7.1.3",
123+
"@types/mocha": "^8.0.3",
124+
"@types/node": "^14.11.1",
125+
"@types/vscode": "^1.49.0",
126+
"@typescript-eslint/eslint-plugin": "^4.1.1",
127+
"@typescript-eslint/parser": "^4.1.1",
128+
"commitizen": "^4.2.1",
129+
"cz-conventional-changelog": "^3.3.0",
130+
"eslint": "^7.9.0",
131131
"glob": "^7.1.6",
132-
"mocha": "^7.1.1",
133-
"prettier": "^2.0.5",
134-
"semantic-release": "^17.0.4",
132+
"mocha": "^8.1.3",
133+
"prettier": "^2.1.2",
134+
"semantic-release": "^17.1.2",
135135
"semantic-release-vsce": "^3.0.1",
136-
"typescript": "^3.8.3",
137-
"vsce": "^1.75.0",
138-
"vscode-test": "^1.3.0"
136+
"typescript": "^4.0.2",
137+
"vsce": "^1.79.5",
138+
"vscode-test": "^1.4.0"
139139
},
140140
"dependencies": {
141-
"velocityjs": "^2.0.0"
141+
"aws-sdk": "^2.755.0",
142+
"velocityjs": "^2.0.1"
142143
}
143144
}

src/previewContentProvider.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from "vscode";
2+
import {Converter} from "aws-sdk/clients/dynamodb";
23
import {render as renderVelocity} from "velocityjs";
34

45
function isVelocityFile(document?: vscode.TextDocument): boolean {
@@ -32,7 +33,29 @@ export class VelocityPreviewProvider
3233

3334
const content = editor?.document?.getText() ?? ``;
3435

35-
return renderVelocity(content);
36+
const renderContext = {
37+
util: {
38+
toJson(vmString: any, context: any): string {
39+
return JSON.stringify(vmString);
40+
},
41+
dynamodb: {
42+
toMap(vmString: any, context: any): object {
43+
return Converter.input(vmString);
44+
},
45+
toMapValues(vmString: any, context: any): object {
46+
return Converter.marshall(vmString);
47+
},
48+
toMapJson(vmString: any, context: any): string {
49+
return JSON.stringify(Converter.input(vmString));
50+
},
51+
toMapValuesJson(vmString: any, context: any): string {
52+
return JSON.stringify(Converter.marshall(vmString));
53+
}
54+
}
55+
}
56+
};
57+
58+
return renderVelocity(content, renderContext);
3659
}
3760

3861
async updatePreview() {}

test_templates/dynamo.vtl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#set($range = [0..5])
22

3+
$util.toJson({
4+
"foo": "bar"
5+
})
6+
37
{
48
"test": true
59
#foreach($i in $range)

0 commit comments

Comments
 (0)