Skip to content

Commit 6c11480

Browse files
committed
added file, jsondecode, jsonencode jinja filters
1 parent fc3625f commit 6c11480

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/stacks/filters/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from .checksum import md5, sha1, sha256, sha512
22
from .deepformat import deepformat
3+
from .encoding import jsondecode, jsonencode
4+
from .filesystem import file
35
from .lookup import variable, output, resource
46
from .throw import throw
57

@@ -10,6 +12,9 @@
1012
sha256,
1113
sha512,
1214
deepformat,
15+
jsondecode,
16+
jsonencode,
17+
file,
1318
variable,
1419
output,
1520
resource,

src/stacks/filters/encoding.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import json
2+
3+
4+
def jsondecode(ctx, data, *args, **kwargs):
5+
return json.loads(data)
6+
7+
8+
def jsonencode(ctx, data, *args, **kwargs):
9+
return json.dumps(data)

src/stacks/filters/filesystem.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def file(ctx, path, *args, **kwargs):
2+
with open(path) as f:
3+
return f.read()

0 commit comments

Comments
 (0)