Commit 4c22f137 by vrde

ok fail, forgot to add files.

parent 7667a95e
......@@ -6,3 +6,4 @@ def render(template, context=None, **kwargs):
context = context and context.copy() or {}
context.update(kwargs)
return Template(template, context).render()
......@@ -2,14 +2,15 @@ import os
class Loader(object):
template_extension = 'mustache'
template_path = '.'
template_encoding = None
def __init__(self, paths='.', extension='mustache', encoding=None):
self.template_paths = paths
self.template_extension = extension
self.template_encoding = encoding
def load_template(self, template_name, template_dirs=None, encoding=None, extension=None):
'''Returns the template string from a file or throws IOError if it non existent'''
if None == template_dirs:
template_dirs = self.template_path
template_dirs = self.template_paths
if encoding is not None:
self.template_encoding = encoding
......@@ -44,4 +45,4 @@ class Loader(object):
finally:
f.close()
return template
\ No newline at end of file
return template
......@@ -45,10 +45,11 @@ class Template(object):
modifiers = Modifiers()
def __init__(self, template=None, context=None, **kwargs):
def __init__(self, template=None, context=None, partials=None, **kwargs):
from view import View
self.template = template
self.partials = partials
if kwargs:
context.update(kwargs)
......@@ -118,7 +119,7 @@ class Template(object):
def _render_dictionary(self, template, context):
self.view.context_list.insert(0, context)
template = Template(template, self.view)
template = Template(template, self.view, self.partials)
out = template.render()
self.view.context_list.pop(0)
return out
......@@ -149,9 +150,12 @@ class Template(object):
@modifiers.set('>')
def _render_partial(self, template_name):
from pystache import Loader
markup = Loader().load_template(template_name, self.view.template_path, encoding=self.view.template_encoding)
template = Template(markup, self.view)
if self.partials:
template = Template(self.partials[template_name], self.view, self.partials)
else:
from pystache import Loader
markup = Loader().load_template(template_name, self.view.template_path, encoding=self.view.template_encoding)
template = Template(markup, self.view)
return template.render()
@modifiers.set('=')
......
......@@ -91,4 +91,5 @@ class View(object):
raise AttributeError("Attribute '%s' does not exist in View" % attr)
def __str__(self):
return self.render()
\ No newline at end of file
return self.render()
......@@ -25,6 +25,8 @@ setup(name='pystache',
url='http://github.com/defunkt/pystache',
packages=['pystache'],
license='MIT',
entry_points = {
'console_scripts': ['pystache=pystache.commands:main']},
classifiers = (
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
......
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