spaceapi-server/spaceapi_server/plugins/__init__.py

39 lines
1,000 B
Python
Raw Normal View History

2019-11-25 02:48:12 +01:00
from spaceapi_server.template import env_init
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 03:14:14 +01:00
:type fn: The function to register.
"""
2019-11-25 02:48:12 +01:00
# 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):
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 03:14:14 +01:00
:type fn: The function to register.
"""
2019-11-25 02:48:12 +01:00
# 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):
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 03:14:14 +01:00
:type fn: The function to register.
"""
2019-11-25 02:48:12 +01:00
# 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