Commit 9d2da6ae by Chris Jerdonek

Renamed the loader argument of View.__init__() to "partials".

parent aaed5225
...@@ -25,23 +25,20 @@ class View(object): ...@@ -25,23 +25,20 @@ class View(object):
_loader = None _loader = None
_renderer = None _renderer = None
def __init__(self, template=None, context=None, loader=None, **kwargs): def __init__(self, template=None, context=None, partials=None, **kwargs):
""" """
Construct a View instance. Construct a View instance.
Arguments: Arguments:
loader: the object (e.g. pystache.Loader or dictionary) responsible partials: the object (e.g. pystache.Loader or dictionary)
for loading templates during the rendering process, for example responsible for loading partials during the rendering process.
when loading partials. The object should have a get() method The object should have a get() method that accepts a string and
that accepts a string and returns the corresponding template returns the corresponding template as a string, preferably as a
as a string, preferably as a unicode string. The method should unicode string. The method should return None if there is no
return None if there is no template with that name. template with that name, or raise an exception.
""" """
if loader is not None:
self._loader = loader
if template is not None: if template is not None:
self.template = template self.template = template
...@@ -51,6 +48,8 @@ class View(object): ...@@ -51,6 +48,8 @@ class View(object):
if kwargs: if kwargs:
_context.push(kwargs) _context.push(kwargs)
self._partials = partials
self.context = _context self.context = _context
def _get_renderer(self): def _get_renderer(self):
...@@ -60,7 +59,7 @@ class View(object): ...@@ -60,7 +59,7 @@ class View(object):
# instantiation some of the attributes on which the Renderer # instantiation some of the attributes on which the Renderer
# depends. This lets users set the template_extension attribute, # depends. This lets users set the template_extension attribute,
# etc. after View.__init__() has already been called. # etc. after View.__init__() has already been called.
renderer = Renderer(partials=self._loader, renderer = Renderer(partials=self._partials,
file_encoding=self.template_encoding, file_encoding=self.template_encoding,
search_dirs=self.template_path, search_dirs=self.template_path,
file_extension=self.template_extension) file_extension=self.template_extension)
......
...@@ -53,7 +53,7 @@ class ViewTestCase(unittest.TestCase): ...@@ -53,7 +53,7 @@ class ViewTestCase(unittest.TestCase):
""" """
template = "{{>partial}}" template = "{{>partial}}"
partials = {"partial": "Loaded from dictionary"} partials = {"partial": "Loaded from dictionary"}
view = Simple(template=template, loader=partials) view = Simple(template=template, partials=partials)
actual = view.render() actual = view.render()
self.assertEquals(actual, "Loaded from dictionary") self.assertEquals(actual, "Loaded from dictionary")
......
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