def load(self, name, translator=PythonTranslator): """ Translate a template and return it. This must not necesarily be a template class. The javascript translator for example will just output a string with the translated code. """ # just ascii chars are allowed as template names name = str(name) try: return self.loader.load(self.environment, name, translator) except TemplateSyntaxError, e: if not self.environment.friendly_traceback: raise __traceback_hide__ = True from jinja.debugger import raise_syntax_error raise_syntax_error(e, self.environment)
def from_string(self, source): """ Load and parse a template source and translate it into eval-able Python code. This code is wrapped within a `Template` class that allows you to render it. """ from jinja.translators.python import PythonTranslator try: rv = PythonTranslator.process(self, Parser(self, source).parse(), source) except TemplateSyntaxError, e: # on syntax errors rewrite the traceback if wanted if not self.friendly_traceback: raise from jinja.debugger import raise_syntax_error if __debug__: __traceback_hide__ = True raise_syntax_error(e, self, source)