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.
| 2414 | |
| 2415 | |
| 2416 | class TemplatePlugin(object): |
| 2417 | """ This plugin applies the :func:`view` decorator to all routes with a |
| 2418 | `template` config parameter. If the parameter is a tuple, the second |
| 2419 | element must be a dict with additional options (e.g. `template_engine`) |
| 2420 | or default variables for the template. """ |
| 2421 | name = 'template' |
| 2422 | api = 2 |
| 2423 | |
| 2424 | def setup(self, app): |
| 2425 | app.tpl = self |
| 2426 | |
| 2427 | def apply(self, callback, route): |
| 2428 | conf = route.config.get('template') |
| 2429 | if isinstance(conf, (tuple, list)) and len(conf) == 2: |
| 2430 | return view(conf[0], **conf[1])(callback) |
| 2431 | elif isinstance(conf, str): |
| 2432 | return view(conf)(callback) |
| 2433 | else: |
| 2434 | return callback |
| 2435 | |
| 2436 | |
| 2437 | #: Not a plugin, but part of the plugin API. TODO: Find a better place. |
no outgoing calls
no test coverage detected
searching dependent graphs…