Skip to content

Commit

Permalink
Merge branch 'master' of github.com:j2labs/brubeck
Browse files Browse the repository at this point in the history
  • Loading branch information
James Dennis committed May 10, 2012
2 parents f4273c4 + 00c4b6a commit 6f3a280
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 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}}
2 changes: 1 addition & 1 deletion envs/brubeck.reqs
Expand Up @@ -2,7 +2,7 @@ Cython==0.15.1
Jinja2==2.6
#Mako==0.7.0
#tornado==2.2
#pystache==0.4.1
#pystache==0.5.1
dictshield==0.4.3
py-bcrypt==0.2
pymongo==2.1.1
Expand Down
5 changes: 3 additions & 2 deletions setup.py
@@ -1,11 +1,12 @@
#!/usr/bin/env python

from distutils.core import setup
from setuptools import setup

setup(name='brubeck',
version='0.4.0',
description='Python Library for building Mongrel2 / ZeroMQ message handlers',
author='James Dennis',
author_email='jdennis@gmail.com',
url='http://github.com/j2labs/brubeck',
packages=['brubeck'])
packages=['brubeck'],
install_requires=['ujson', 'dictshield'])

0 comments on commit 6f3a280

Please sign in to comment.