Commit 4c22f137 by vrde

ok fail, forgot to add files.

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