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