diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-01 20:59:30 -0700 |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-01 20:59:30 -0700 |
commit | e87e859f524031c20fff5aeea5ec00cd00cc1664 (patch) | |
tree | a3e54da7aab63135f40a8181bd1b72146ab7069b /pystache | |
parent | 49c1d7a9521ae9e20202ddb25d9b9d30ad85d016 (diff) | |
download | pystache-e87e859f524031c20fff5aeea5ec00cd00cc1664.tar.gz |
Removed View class (finally!).
Diffstat (limited to 'pystache')
-rw-r--r-- | pystache/init.py | 3 | ||||
-rw-r--r-- | pystache/template_spec.py | 3 | ||||
-rw-r--r-- | pystache/view.py | 82 |
3 files changed, 2 insertions, 86 deletions
diff --git a/pystache/init.py b/pystache/init.py index b629150..f227f78 100644 --- a/pystache/init.py +++ b/pystache/init.py @@ -7,10 +7,9 @@ This module contains the initialization logic called by __init__.py. from .renderer import Renderer from .template_spec import TemplateSpec -from .view import View -__all__ = ['render', 'Renderer', 'View', 'TemplateSpec'] +__all__ = ['render', 'Renderer', 'TemplateSpec'] def render(template, context=None, **kwargs): diff --git a/pystache/template_spec.py b/pystache/template_spec.py index 68dc52d..1e3695f 100644 --- a/pystache/template_spec.py +++ b/pystache/template_spec.py @@ -52,8 +52,7 @@ class TemplateSpec(object): template_encoding = None -# TODO: add test cases for this class, and then refactor while replacing the -# View class. +# TODO: add test cases for this class. class SpecLoader(object): """ diff --git a/pystache/view.py b/pystache/view.py deleted file mode 100644 index 1aa31be..0000000 --- a/pystache/view.py +++ /dev/null @@ -1,82 +0,0 @@ -# coding: utf-8 - -""" -This module exposes the deprecated View class. - -TODO: remove this module. - -""" - -from .context import Context -from .locator import Locator -from .renderer import Renderer -from .template_spec import TemplateSpec - - -# TODO: remove this class. -class View(TemplateSpec): - - _renderer = None - - locator = Locator() - - def __init__(self, context=None): - """ - Construct a View instance. - - """ - context = Context.create(self, context) - - self.context = context - - def _get_renderer(self): - if self._renderer is None: - # We delay setting self._renderer until now (instead of, say, - # setting it in the constructor) in case the user changes after - # instantiation some of the attributes on which the Renderer - # depends. This lets users set the template_extension attribute, - # etc. after View.__init__() has already been called. - renderer = Renderer(file_encoding=self.template_encoding, - search_dirs=self.template_path, - file_extension=self.template_extension) - self._renderer = renderer - - return self._renderer - - def get_template(self): - """ - Return the current template after setting it, if necessary. - - """ - if not self.template: - template_name = self._get_template_name() - renderer = self._get_renderer() - self.template = renderer.load_template(template_name) - - return self.template - - def _get_template_name(self): - """ - Return the name of the template to load. - - If the template_name attribute is not set, then this method constructs - the template name from the class name as follows, for example: - - TemplatePartial => template_partial - - Otherwise, this method returns the template_name. - - """ - if self.template_name: - return self.template_name - - return self.locator.make_template_name(self) - - def render(self): - """ - Return the view rendered using the current context. - - """ - template = self.get_template() - renderer = self._get_renderer() - return renderer.render(template, self.context) |