コード例 #1
0
    def prepare(self, **options):
        from pystache import Template, View

        View.template_path = self.lookup
        self.context = threading.local()
        self.context.vars = {}
        if self.source:
            self.tpl = Template(self.source)
        else:
            view = View()
            view.template_file = self.filename
            view.template_name = self.name
            view.template_encoding = self.encoding
            template = view.load_template()
            self.tpl = Template(template)
コード例 #2
0
class PystacheTemplate(bottle.BaseTemplate):
    """ Pystache is a Python Mustache implementation.
        Set `View.template_extension` to be able to use partials,
        because partial calls are not handled by Bottle and Pystache works
        with only one extension, defined as `mustache` by default.
    """

    try:
        extensions = bottle.BaseTemplate.extensions
    except AttributeError:
        # Bottle had a misspelling in BaseTemplate.
        # It is fixed in Bottle v0.10.
        extensions = bottle.BaseTemplate.extentions
    extensions.insert(0, "mustache")

    def prepare(self, **options):
        from pystache import Template, View

        View.template_path = self.lookup
        self.context = threading.local()
        self.context.vars = {}
        if self.source:
            self.tpl = Template(self.source)
        else:
            view = View()
            view.template_file = self.filename
            view.template_name = self.name
            view.template_encoding = self.encoding
            template = view.load_template()
            self.tpl = Template(template)

    def render(self, *args, **kwargs):
        for dictarg in args:
            kwargs.update(dictarg)
        self.context.vars.update(self.defaults)
        self.context.vars.update(kwargs)
        out = self.tpl.render(context=self.context.vars, encoding=self.encoding)
        self.context.vars.clear()
        return out
コード例 #3
0
ファイル: view.py プロジェクト: optixx/django-pystache
 def render(self, encoding=None):
     return Template(self.get_template(self.template_name),
                     self).render(encoding=encoding)
コード例 #4
0
 def render(self, encoding=None):
     template = self.load_template()
     return Template(template, self).render(encoding=encoding)
コード例 #5
0
ファイル: view.py プロジェクト: jhurt/pystache
 def renderOnlyLocalization(self):
     return Template(self.get_template(self.template_name),
                     self).renderOnlyLocalization()