Skip to content

Commit

Permalink
feat: add beet.contrib.template_sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Apr 23, 2021
1 parent 00ca7e9 commit 55fbe92
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions beet/contrib/template_sandbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Plugin that configures the sandboxed jinja environment."""


from jinja2.sandbox import SandboxedEnvironment

from beet import Context


def beet_default(ctx: Context):
ctx.template.reset_environment(SandboxedEnvironment)
12 changes: 12 additions & 0 deletions examples/load_template_sandbox/beet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"require": ["beet.contrib.template_sandbox"],
"data_pack": {
"load": ["src"],
"render": {
"functions": ["*"]
}
},
"meta": {
"something": 6
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!from "config.txt" import message
say {{ message * something }} "{{ something.__class__ }}"
1 change: 1 addition & 0 deletions examples/load_template_sandbox/templates/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!set message = "hello"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say hellohellohellohellohellohello ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 6,
"description": ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 6,
"description": ""
}
}

0 comments on commit 55fbe92

Please sign in to comment.