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.
| 1764 | |
| 1765 | |
| 1766 | class TemplatePlugin(object): |
| 1767 | ''' This plugin applies the :func:`view` decorator to all routes with a |
| 1768 | `template` config parameter. If the parameter is a tuple, the second |
| 1769 | element must be a dict with additional options (e.g. `template_engine`) |
| 1770 | or default variables for the template. ''' |
| 1771 | name = 'template' |
| 1772 | api = 2 |
| 1773 | |
| 1774 | def apply(self, callback, route): |
| 1775 | conf = route.config.get('template') |
| 1776 | if isinstance(conf, (tuple, list)) and len(conf) == 2: |
| 1777 | return view(conf[0], **conf[1])(callback) |
| 1778 | elif isinstance(conf, str): |
| 1779 | return view(conf)(callback) |
| 1780 | else: |
| 1781 | return callback |
| 1782 | |
| 1783 | |
| 1784 | #: Not a plugin, but part of the plugin API. TODO: Find a better place. |