Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #65 from talos/mustache

pystache 0.5.0 support, much cleaner, but breaks compatibility with older pystache
  • Loading branch information...
commit 523daf3cb21a1094c4dee0f6f493e45c06f27420 2 parents 2162010 + 2e83d0f
James Dennis authored
View
22 brubeck/templating.py
@@ -127,25 +127,11 @@ def load_mustache_env(template_dir, *args, **kwargs):
anything until the caller is ready.
"""
def loader():
- return MustacheEnvironment(template_dir)
-
- return loader
-
-class MustacheEnvironment(object):
- """
- An environment to render mustache templates.
- """
- def __init__(self, template_dirs):
import pystache
- self.pystache = pystache
- self.template_dirs = template_dirs
+ return pystache.Renderer(search_dirs=[template_dir])
- def render(self, template_file, context):
- view = self.pystache.View(context=context)
- view.template_name = template_file
- view.template_path = self.template_dirs
- return view.render()
+ return loader
class MustacheRendering(WebMessageHandler):
@@ -163,7 +149,9 @@ def render_template(self, template_file,
Renders payload as a mustache template
"""
mustache_env = self.application.template_env
- body = mustache_env.render(template_file, context or {})
+
+ template = mustache_env.load_template(template_file)
+ body = mustache_env.render(template, context or {})
self.set_body(body, status_code=_status_code)
return self.render()
View
1  demos/templates/mustache/nested_partial.mustache
@@ -0,0 +1 @@
+<p>And take five more.</p>
View
2  demos/templates/mustache/success.mustache
@@ -3,6 +3,6 @@
<title>Successful Mustache Template Render</title>
</head>
<body>
- <p>Take five, {{name}}!</p>
+ {{> take_five}}
</body>
</html>
View
2  demos/templates/mustache/take_five.mustache
@@ -0,0 +1,2 @@
+<p>Take five, {{name}}!</p>
+{{> nested_partial}}
Please sign in to comment.
Something went wrong with that request. Please try again.