2019-11-25 02:48:12 +01:00
|
|
|
|
2019-11-30 04:49:01 +01:00
|
|
|
from spaceapi_server import config, template
|
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-30 04:49:01 +01:00
|
|
|
env = template._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-30 04:49:01 +01:00
|
|
|
env = template._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
|
|
|
|
|
|
|
|
|
2019-11-30 04:49:01 +01:00
|
|
|
def get_plugin_config(name: str):
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-30 04:49:01 +01:00
|
|
|
Return a plugin's configuration under .plugins[name]
|
|
|
|
:param name: The plugin name.
|
2019-11-25 03:14:14 +01:00
|
|
|
"""
|
2019-11-30 04:49:01 +01:00
|
|
|
return config.get().get('plugins', {}).get(name, {})
|