MCPcopy Create free account
hub / github.com/datapane/datapane / TemplatePlugin

Class TemplatePlugin

python-client/src/datapane/_vendor/bottle.py:2018–2036  ·  view source on GitHub ↗

This plugin applies the :func:`view` decorator to all routes with a `template` config parameter. If the parameter is a tuple, the second element must be a dict with additional options (e.g. `template_engine`) or default variables for the template.

Source from the content-addressed store, hash-verified

2016
2017
2018class TemplatePlugin(object):
2019 """ This plugin applies the :func:`view` decorator to all routes with a
2020 `template` config parameter. If the parameter is a tuple, the second
2021 element must be a dict with additional options (e.g. `template_engine`)
2022 or default variables for the template. """
2023 name = 'template'
2024 api = 2
2025
2026 def setup(self, app):
2027 app.tpl = self
2028
2029 def apply(self, callback, route):
2030 conf = route.config.get('template')
2031 if isinstance(conf, (tuple, list)) and len(conf) == 2:
2032 return view(conf[0], **conf[1])(callback)
2033 elif isinstance(conf, str):
2034 return view(conf)(callback)
2035 else:
2036 return callback
2037
2038
2039#: Not a plugin, but part of the plugin API. TODO: Find a better place.

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected