spaceapi-server/examples/plugins/example.py

36 lines
1 KiB
Python

from spaceapi_server import plugins
@plugins.template_function
def example_function(name: str):
"""
This function is registered as a Jinja2 function. It can be used like this:
{{ example_function('the Spanish Inquisition') }}
"""
return f'Nobody expects {name}'
@plugins.template_filter
def example_filter(name: str):
"""
This function is registered as a Jinja2 filter. It can be used like this:
{{ 'the Spanish Inquisition' | example_filter }}
"""
return f'Nobody expects {name}'
@plugins.template_function
def example_config_function():
"""
This function demonstrates the use of configuration.
{( example_config_function() }}
"""
# Config lookup example. A plugin's config should be below
# `.plugins[plugin_name]` (JSONPath)
# Get the .plugins.example dict
conf = plugins.get_plugin_config('example')
# Get the .test_value property from the plugin config, falling
# back to a default value
return conf.get('test_value', 'the Spanish Inquisition')