mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Added decorator jinja_global to add functions as jinja globals
This commit is contained in:
parent
286eaf9237
commit
93640d1b02
@ -691,3 +691,28 @@ class JinjaTest(object):
|
||||
|
||||
|
||||
jinja_test = JinjaTest
|
||||
|
||||
|
||||
class JinjaGlobal(object):
|
||||
'''
|
||||
This decorator is used to specify that a function is to be loaded as a
|
||||
Jinja global.
|
||||
'''
|
||||
salt_jinja_globals = {}
|
||||
|
||||
def __init__(self, name=None):
|
||||
'''
|
||||
'''
|
||||
self.name = name
|
||||
|
||||
def __call__(self, function):
|
||||
'''
|
||||
'''
|
||||
name = self.name or function.__name__
|
||||
if name not in self.salt_jinja_globals:
|
||||
log.debug('Marking "{0}" as a jinja global'.format(name))
|
||||
self.salt_jinja_globals[name] = function
|
||||
return function
|
||||
|
||||
|
||||
jinja_global = JinjaGlobal
|
||||
|
Loading…
Reference in New Issue
Block a user