Exemple #1
0
    def render(self, cls=None):
        """Render template for specified class"""
        if cls is None:
            # pick first subclass of View
            cls = self.__class__.mro()[:-2][-1]

        self._render_calls = set()
        expected_render_calls = func_names_on_class(cls)

        with SandboxCallState(self):
            view = PystacheView(context=self)
            view.template_name = self._resolve_name(cls)
            for v in 'template_path', 'template_extension', \
                     'template_file', 'template':
                attr = getattr(self, v)
                if cls in attr:
                    setattr(view, v, attr[cls])

            rendered = view.render()

        if not self.options & View.OPT_IGNORE_UNREQUESTED and \
            self._render_calls != expected_render_calls:

            raise KeyError("Missing calls to: %s" % \
                ', '.join(expected_render_calls -\
                    self._render_calls))

        return rendered
    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)
Exemple #3
0
 def __init__(self, template, config):
   View.__init__(self, template, config)
   SyntaxHighlighter.tab_length = int(config.get('tab_length', '2'))
   SyntaxHighlighter.linenos    = config.get('linenos', 'no') == 'yes'
   SyntaxHighlighter.css_class  = config.get('css_class', 'highlight')
   SyntaxHighlighter.prefix     = config.get('syntax_prefix', 'highlight_')