spaceapi-server/spaceapi_server/plugins/__init__.py
2019-11-25 02:48:12 +01:00

38 lines
1,000 B
Python

from spaceapi_server.template import env_init
def template_function(fn):
'''
Register the decorated function as a callable template function.
@param fn The function to register.
'''
# Make sure the Jinja2 environment is initialized
env = env_init()
# Add the function to the environment's globals
env.globals[fn.__name__] = fn
return fn
def template_filter(fn):
'''
Register the decorated function as a template filter.
@param fn The function to register.
'''
# Make sure the Jinja2 environment is initialized
env = env_init()
# Add the function to the environment's filters
env.filters[fn.__name__] = fn
return fn
def template_test(fn):
'''
Register the decorated function as a template test.
@param fn The function to register.
'''
# Make sure the Jinja2 environment is initialized
env = env_init()
# Add the function to the environment's tests
env.tests[fn.__name__] = fn
return fn