Skip to content

Commit

Permalink
Merge pull request j2labs#65 from talos/mustache
Browse files Browse the repository at this point in the history
pystache 0.5.0 support, much cleaner, but breaks compatibility with older pystache
  • Loading branch information
James Dennis committed Apr 20, 2012
2 parents 2162010 + 2e83d0f commit 523daf3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
22 changes: 5 additions & 17 deletions brubeck/templating.py
Expand Up @@ -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):
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions demos/templates/mustache/nested_partial.mustache
@@ -0,0 +1 @@
<p>And take five more.</p>
2 changes: 1 addition & 1 deletion demos/templates/mustache/success.mustache
Expand Up @@ -3,6 +3,6 @@
<title>Successful Mustache Template Render</title>
</head>
<body>
<p>Take five, {{name}}!</p>
{{> take_five}}
</body>
</html>
2 changes: 2 additions & 0 deletions demos/templates/mustache/take_five.mustache
@@ -0,0 +1,2 @@
<p>Take five, {{name}}!</p>
{{> nested_partial}}

0 comments on commit 523daf3

Please sign in to comment.