mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Implement tojson jinja filter for those using Jinja < 2.9
This commit is contained in:
parent
5b8d55428e
commit
1499c6abcf
1 changed files with 20 additions and 0 deletions
|
@ -278,6 +278,26 @@ def to_bool(val):
|
|||
return False
|
||||
|
||||
|
||||
@jinja_filter('tojson')
|
||||
def tojson(val, indent=None):
|
||||
'''
|
||||
Implementation of tojson filter (only present in Jinja 2.9 and later). If
|
||||
Jinja 2.9 or later is installed, then the upstream version of this filter
|
||||
will be used.
|
||||
'''
|
||||
options = {'ensure_ascii': True}
|
||||
if indent is not None:
|
||||
options['indent'] = indent
|
||||
return (
|
||||
salt.utils.json.dumps(
|
||||
val, **options
|
||||
).replace('<', '\\u003c')
|
||||
.replace('>', '\\u003e')
|
||||
.replace('&', '\\u0026')
|
||||
.replace("'", '\\u0027')
|
||||
)
|
||||
|
||||
|
||||
@jinja_filter('quote')
|
||||
def quote(txt):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue