spaceapi-server/spaceapi_server/plugins/__init__.py

35 lines
913 B
Python
Raw Normal View History

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