40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
|
|
from spaceapi_server import config, 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_test
|
|
def example_test(name: str):
|
|
"""
|
|
This function is registered as a Jinja2 test. It can be used like this:
|
|
{% if 'the Spanish Inquisition' is example_test %}
|
|
"""
|
|
# Config lookup example. A plugin's config should be below
|
|
# `.plugins[plugin_name]` (JSONPath)
|
|
|
|
# Get the .plugins.example dict
|
|
conf = config.get_plugin_config('example')
|
|
# Get the .test_value property from the plugin config, falling
|
|
# back to a default value
|
|
test_value = conf.get('test_value', 'the Spanish Inquisition')
|
|
|
|
# Tests must always return a boolean or boolean-castable
|
|
# expression
|
|
return name == test_value
|