Skip to content
Myr

[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

3 files+71 added−70 removed

modified:docs/src/frameworks.txt+2 added-2 removed
1=====================2Framework Integration3=====================45Jinja registers itself in the baker template plugin system. If your framework6supports baker (currently `TurboGears`_ and `pylons`_) you can add it very5Jinja registers itself in the buffet template plugin system. If your framework6supports buffet (currently `TurboGears`_ and `pylons`_) you can add it very7easily.89Pylons10------
77 unmodified lines
deleted:jinja/bakerplugin.py-68 removed
1# -*- coding: utf-8 -*-2"""3 jinja.bakerplugin4 ~~~~~~~~~~~~~~~~~56 Provide a bridge to baker. Baker is used by some frameworks (namely7 CherryPy, TurboGears and Pylons) to load templates.89 :copyright: 2007 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""12from jinja import Environment131415class ConfigurationError(ValueError):16 """17 Raised if an configuration error occoured.18 """192021class JinjaPlugin(object):22 """23 Implementation of the Plugin API24 """25 extension = 'html'2627 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']4142 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)4950 # Translate TG dot notation to normal / template path51 if templatename.startswith('/'):52 templatename = templatename[1:]53 else:54 templatename = templatename.replace('.', '/') + '.' + self.extension5556 return self.environment.get_template(templatename)5758 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)6465 if self.get_extra_vars:66 info.update(self.get_extra_vars())6768 return template.render(**info)
added:jinja/plugin.py+69 added
1# -*- coding: utf-8 -*-2"""3 jinja.plugin4 ~~~~~~~~~~~~56 Provide a bridge to buffet. Buffet is used by some frameworks (namely7 CherryPy, TurboGears and Pylons) to load templates.89 :copyright: 2007 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""1213from jinja import Environment141516class ConfigurationError(ValueError):17 """18 Raised if an configuration error occoured.19 """202122class JinjaPlugin(object):23 """24 Implementation of the Plugin API25 """26 extension = 'html'2728 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']4243 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)5051 # Translate TG dot notation to normal / template path52 if templatename.startswith('/'):53 templatename = templatename[1:]54 else:55 templatename = templatename.replace('.', '/') + '.' + self.extension5657 return self.environment.get_template(templatename)5859 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)6566 if self.get_extra_vars:67 info.update(self.get_extra_vars())6869 return template.render(**info)