[svn] too stupid to spell things
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk rename : jinja/bakerplugin.py => jinja/plugin.py
authored by Armin Ronacher · committed by Armin Ronacher · parent 0b66657 · Browse files · 3 files·+71 added−70 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+71 added−70 removed
- other:+71 added−70 removed
Provenance
- Commit
252f321- Tree
69cde2a- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
0b66657
3 files changed+71 added−70 removed
modified:docs/src/frameworks.txt+2 added-2 removed
1 =====================2 Framework Integration3 =====================4 5-Jinja registers itself in the baker template plugin system. If your framework6-supports baker (currently `TurboGears`_ and `pylons`_) you can add it very5+Jinja registers itself in the buffet template plugin system. If your framework6+supports buffet (currently `TurboGears`_ and `pylons`_) you can add it very7 easily.8 9 Pylons10 ------77 unmodified linesdeleted:jinja/bakerplugin.py-68 removed
1-# -*- coding: utf-8 -*-2-"""3- jinja.bakerplugin4- ~~~~~~~~~~~~~~~~~5-6- Provide a bridge to baker. Baker is used by some frameworks (namely7- CherryPy, TurboGears and Pylons) to load templates.8-9- :copyright: 2007 by Armin Ronacher.10- :license: BSD, see LICENSE for more details.11-"""12-from jinja import Environment13-14-15-class ConfigurationError(ValueError):16- """17- Raised if an configuration error occoured.18- """19-20-21-class JinjaPlugin(object):22- """23- Implementation of the Plugin API24- """25- extension = 'html'26-27- def __init__(self, extra_vars_func=None, options=None):28- self.get_extra_vars = extra_vars_func29- options = options or {}30- if 'jinja.environment' in options:31- self.environment = options['jinja.environment']32- elif 'jinja.init_callback' in options:33- name = options['jinja.init_callback']34- p = name.rsplit('.', 1)35- func = getattr(__import__(p[0], '', '', ['']), p[1])36- self.environment = func(options)37- else:38- raise ConfigurationError('no jinja environment defined')39- if 'jinja.extension' in options:40- self.extension = options['jinja.extension']41-42- def load_template(self, templatename, template_string=None):43- """44- Find a template specified in python 'dot' notation, or load one from45- a string.46- """47- if template_string is not None:48- return self.environment.from_string(template_string)49-50- # Translate TG dot notation to normal / template path51- if templatename.startswith('/'):52- templatename = templatename[1:]53- else:54- templatename = templatename.replace('.', '/') + '.' + self.extension55-56- return self.environment.get_template(templatename)57-58- def render(self, info, format='html', fragment=False, template=None):59- """60- Render a template.61- """62- if isinstance(template, basestring):63- template = self.load_template(template)64-65- if self.get_extra_vars:66- info.update(self.get_extra_vars())67-68- return template.render(**info)added:jinja/plugin.py+69 added
1+# -*- coding: utf-8 -*-2+"""3+ jinja.plugin4+ ~~~~~~~~~~~~5+6+ Provide a bridge to buffet. Buffet is used by some frameworks (namely7+ CherryPy, TurboGears and Pylons) to load templates.8+9+ :copyright: 2007 by Armin Ronacher.10+ :license: BSD, see LICENSE for more details.11+"""12+13+from jinja import Environment14+15+16+class ConfigurationError(ValueError):17+ """18+ Raised if an configuration error occoured.19+ """20+21+22+class JinjaPlugin(object):23+ """24+ Implementation of the Plugin API25+ """26+ extension = 'html'27+28+ def __init__(self, extra_vars_func=None, options=None):29+ self.get_extra_vars = extra_vars_func30+ options = options or {}31+ if 'jinja.environment' in options:32+ self.environment = options['jinja.environment']33+ elif 'jinja.init_callback' in options:34+ name = options['jinja.init_callback']35+ p = name.rsplit('.', 1)36+ func = getattr(__import__(p[0], '', '', ['']), p[1])37+ self.environment = func(options)38+ else:39+ raise ConfigurationError('no jinja environment defined')40+ if 'jinja.extension' in options:41+ self.extension = options['jinja.extension']42+43+ def load_template(self, templatename, template_string=None):44+ """45+ Find a template specified in python 'dot' notation, or load one from46+ a string.47+ """48+ if template_string is not None:49+ return self.environment.from_string(template_string)50+51+ # Translate TG dot notation to normal / template path52+ if templatename.startswith('/'):53+ templatename = templatename[1:]54+ else:55+ templatename = templatename.replace('.', '/') + '.' + self.extension56+57+ return self.environment.get_template(templatename)58+59+ def render(self, info, format='html', fragment=False, template=None):60+ """61+ Render a template.62+ """63+ if isinstance(template, basestring):64+ template = self.load_template(template)65+66+ if self.get_extra_vars:67+ info.update(self.get_extra_vars())68+69+ return template.render(**info)