Commit b80d2e94 by Chris Jerdonek

README tweaks and added a TODO.

parent a0feb641
...@@ -65,19 +65,18 @@ Use It ...@@ -65,19 +65,18 @@ Use It
You can also create dedicated view classes to hold your view logic. You can also create dedicated view classes to hold your view logic.
Here's your view class (in examples/readme.py):: Here's your view class (in .../examples/readme.py)::
class SayHello(object): class SayHello(object):
def to(self): def to(self):
return "Pizza" return "Pizza"
Like so:: Instantiating like so::
>>> from pystache.tests.examples.readme import SayHello >>> from pystache.tests.examples.readme import SayHello
>>> hello = SayHello() >>> hello = SayHello()
Then your template, say_hello.mustache (in the same directory by default Then your template, say_hello.mustache (by default in the same directory
as your class definition):: as your class definition)::
Hello, {{to}}! Hello, {{to}}!
...@@ -89,16 +88,15 @@ Pull it together:: ...@@ -89,16 +88,15 @@ Pull it together::
Hello, Pizza! Hello, Pizza!
For greater control over rendering (e.g. to specify a custom template directory), For greater control over rendering (e.g. to specify a custom template directory),
use the ``Renderer`` class directly. One can pass attributes to the class's use the ``Renderer`` class like above. One can pass attributes to the
constructor or set them on an instance. Renderer class constructor or set them on a Renderer instance.
To customize template loading on a per-view basis, subclass ``TemplateSpec``. To customize template loading on a per-view basis, subclass ``TemplateSpec``.
See the docstrings of the Renderer_ class and TemplateSpec_ class for See the docstrings of the Renderer_ class and TemplateSpec_ class for
more information. more information.
Try parsing a template: :: You can also parse a template: ::
>>> from pystache import parse >>> pystache.parse("Hey {{#you}}{{.}}!{{/you}}")
>>> parse("Hey {{#you}}{{.}}!{{/you}}")
['Hey ', _SectionNode(key='you', index_begin=12, index_end=18, parsed=[_EscapeNode(key='.'), '!'])] ['Hey ', _SectionNode(key='you', index_begin=12, index_end=18, parsed=[_EscapeNode(key='.'), '!'])]
......
...@@ -17,6 +17,7 @@ NON_BLANK_RE = re.compile(ur'^(.)', re.M) ...@@ -17,6 +17,7 @@ NON_BLANK_RE = re.compile(ur'^(.)', re.M)
# TODO: add some unit tests for this. # TODO: add some unit tests for this.
# TODO: add a test case that checks for spurious spaces. # TODO: add a test case that checks for spurious spaces.
# TODO: add test cases for delimiters.
def parse(template, delimiters=None): def parse(template, delimiters=None):
""" """
Parse a unicode template string and return a ParsedTemplate instance. Parse a unicode template string and return a ParsedTemplate instance.
......
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