2019-11-25 02:48:12 +01:00
|
|
|
|
2019-11-25 04:35:50 +01:00
|
|
|
from spaceapi_server.template import _env_init
|
2019-11-25 02:48:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def template_function(fn):
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-25 02:48:12 +01:00
|
|
|
Register the decorated function as a callable template function.
|
2019-11-25 04:10:20 +01:00
|
|
|
:param fn: The function to register.
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-25 02:48:12 +01:00
|
|
|
# Make sure the Jinja2 environment is initialized
|
2019-11-25 04:35:50 +01:00
|
|
|
env = _env_init()
|
2019-11-25 02:48:12 +01:00
|
|
|
# Add the function to the environment's globals
|
|
|
|
env.globals[fn.__name__] = fn
|
|
|
|
return fn
|
|
|
|
|
|
|
|
|
|
|
|
def template_filter(fn):
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-25 02:48:12 +01:00
|
|
|
Register the decorated function as a template filter.
|
2019-11-25 04:10:20 +01:00
|
|
|
:param fn: The function to register.
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-25 02:48:12 +01:00
|
|
|
# Make sure the Jinja2 environment is initialized
|
2019-11-25 04:35:50 +01:00
|
|
|
env = _env_init()
|
2019-11-25 02:48:12 +01:00
|
|
|
# Add the function to the environment's filters
|
|
|
|
env.filters[fn.__name__] = fn
|
|
|
|
return fn
|
|
|
|
|
|
|
|
|
|
|
|
def template_test(fn):
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-25 02:48:12 +01:00
|
|
|
Register the decorated function as a template test.
|
2019-11-25 04:10:20 +01:00
|
|
|
:param fn: The function to register.
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-25 02:48:12 +01:00
|
|
|
# Make sure the Jinja2 environment is initialized
|
2019-11-25 04:35:50 +01:00
|
|
|
env = _env_init()
|
2019-11-25 02:48:12 +01:00
|
|
|
# Add the function to the environment's tests
|
|
|
|
env.tests[fn.__name__] = fn
|
|
|
|
return fn
|