Commit 28569a66 by Chris Jerdonek

Moved load_template to end of Render.__init__() argument list.

parent b0e78f9a
...@@ -22,18 +22,13 @@ except ImportError: ...@@ -22,18 +22,13 @@ except ImportError:
class Renderer(object): class Renderer(object):
def __init__(self, load_template=None, output_encoding=None, escape=None, def __init__(self, output_encoding=None, escape=None,
default_encoding=None, decode_errors='strict'): default_encoding=None, decode_errors='strict', load_template=None):
""" """
Construct an instance. Construct an instance.
Arguments: Arguments:
load_template: a function for loading templates by name, for
example when loading partials. The function should accept a
single template_name parameter and return a template as a string.
Defaults to the default Loader's get() method.
output_encoding: the encoding to use when rendering to a string. output_encoding: the encoding to use when rendering to a string.
The argument should be the name of an encoding as a string, for The argument should be the name of an encoding as a string, for
example "utf-8". See the render() method's documentation for more example "utf-8". See the render() method's documentation for more
...@@ -61,17 +56,22 @@ class Renderer(object): ...@@ -61,17 +56,22 @@ class Renderer(object):
strings of type `str` encountered during the rendering process. strings of type `str` encountered during the rendering process.
Defaults to "strict". Defaults to "strict".
""" load_template: a function for loading templates by name, for
if load_template is None: example when loading partials. The function should accept a
loader = Loader() single template_name parameter and return a template as a string.
load_template = loader.get Defaults to the default Loader's get() method.
"""
if default_encoding is None: if default_encoding is None:
default_encoding = sys.getdefaultencoding() default_encoding = sys.getdefaultencoding()
if escape is None: if escape is None:
escape = markupsafe.escape if markupsafe else cgi.escape escape = markupsafe.escape if markupsafe else cgi.escape
if load_template is None:
loader = Loader()
load_template = loader.get
literal = markupsafe.Markup if markupsafe else unicode literal = markupsafe.Markup if markupsafe else unicode
self._literal = literal self._literal = literal
......
...@@ -99,7 +99,8 @@ class View(object): ...@@ -99,7 +99,8 @@ class View(object):
""" """
template = self.get_template() template = self.get_template()
renderer = Renderer(self.load_template, output_encoding=encoding, escape=escape) renderer = Renderer(output_encoding=encoding, escape=escape,
load_template=self.load_template)
return renderer.render(template, self.context) return renderer.render(template, self.context)
def get(self, key, default=None): def get(self, key, default=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment