Commit 9d082532 by Chris Jerdonek

Added CustomizedTemplate class.

parent 9148826d
<h1>{{title}}{{! just something interesting... #or not... }}</h1>
<h1>{{title}}{{! just something interesting... #or not... }}</h1>
\ No newline at end of file
import pystache
from pystache import CustomizedTemplate
class Comments(pystache.View):
class Comments(CustomizedTemplate):
template_path = 'examples'
def title(self):
......
......@@ -7,9 +7,10 @@ This module contains the initialization logic called by __init__.py.
from .renderer import Renderer
from .view import View
from .view import CustomizedTemplate
__all__ = ['render', 'Renderer', 'View']
__all__ = ['render', 'Renderer', 'View', 'CustomizedTemplate']
def render(template, context=None, **kwargs):
......
......@@ -13,8 +13,7 @@ from .reader import Reader
from .renderer import Renderer
# TODO: rename this class to something else (e.g. ITemplateInfo)
class View(object):
class CustomizedTemplate(object):
"""
Subclass this class only if template customizations are needed.
......@@ -48,6 +47,10 @@ class View(object):
template_encoding = None
# TODO: remove this class.
class View(CustomizedTemplate):
_renderer = None
locator = TemplateLocator()
......
# encoding: utf-8
import unittest
import pystache
from examples.comments import Comments
from examples.double_section import DoubleSection
......@@ -12,14 +11,16 @@ from examples.delimiters import Delimiters
from examples.unicode_output import UnicodeOutput
from examples.unicode_input import UnicodeInput
from examples.nested_context import NestedContext
from pystache.renderer import Renderer
from tests.common import assert_strings
class TestView(unittest.TestCase):
def test_comments(self):
self.assertEquals(Comments().render(), """<h1>A Comedy of Errors</h1>
""")
renderer = Renderer()
expected = renderer.render(Comments())
self.assertEquals(expected, "<h1>A Comedy of Errors</h1>")
def test_double_section(self):
self.assertEquals(DoubleSection().render(),"""* first\n* second\n* third""")
......
......@@ -11,7 +11,6 @@ import sys
import unittest
from examples.simple import Simple
from pystache import renderer
from pystache.renderer import Renderer
from pystache.locator import Locator
......
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