spaceapi-server/spaceapi_server/plugins/__init__.py

34 lines
913 B
Python

from spaceapi_server import config, template
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 = template._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 = template._env_init()
# Add the function to the environment's filters
env.filters[fn.__name__] = fn
return fn
def get_plugin_config(name: str):
"""
Return a plugin's configuration under .plugins[name]
:param name: The plugin name.
"""
return config.get().get('plugins', {}).get(name, {})