w000t. first template
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent bcb7c53 · Browse files · 4 files·+22 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+22 added−4 removed
- other:+22 added−4 removed
Provenance
- Commit
46f5f98- Tree
7a39f6e- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
bcb7c53
4 files changed+22 added−4 removed
modified:jinja2/compiler.py+3 added-3 removed
277 unmodified lines278 for name in frame.identifiers.undeclared:279 self.writeline('l_%s = context[%r]' % (name, name))280 for name, count in frame.identifiers.undeclared_filter.iteritems():281 if count > 1:282- self.writeline('f_%s = context[%r]' % (name, name))282+ self.writeline('f_%s = environment.filters[%r]' % (name, name))283 if not no_indent:284 self.outdent()285 286 # -- Visitors426 unmodified lines713 def visit_Filter(self, node, frame):714 if node.name in frame.identifiers.declared_filter:715 self.write('f_%s(' % node.name)716 else:717- self.write('context.filter[%r](' % node.name)717+ self.write('environment.filters[%r](' % node.name)718 self.visit(node.node, frame)719 self.signature(node, frame)720 self.write(')')721 722 def visit_Test(self, node, frame):723- self.write('context.tests[%r](')723+ self.write('environment.tests[%r](')724 self.visit(node.node, frame)725 self.signature(node, frame)726 self.write(')')727 10 unmodified linesmodified:jinja2/environment.py+6 added-1 removed
102 unmodified lines103 """Compile a node or source."""104 if isinstance(source, basestring):105 source = self.parse(source, filename)106 node = optimize(source, self)107- source = generate(node, self)107+ source = generate(node, self, filename)108 if raw:109 return source110+ print source111 if isinstance(filename, unicode):112 filename = filename.encode('utf-8')113 return compile(source, filename, 'exec')114 10 unmodified lines125 if parent is not None:126 name = self.join_path(name, parent)127 return self.loader.load(self, name)128 129+ def from_string(self, source, filename='<string>'):130+ """Load a template from a string."""131+ return Template(self, self.compile(source, filename))132 133+134 class Template(object):135 """Represents a template."""136 137 def __init__(self, environment, code):12 unmodified linesmodified:jinja2/loaders.py+1 added
12 unmodified lines13 from jinja2.environment import Template14 15 16 class BaseLoader(object):17+ """Baseclass for all loaders."""18 19 def get_source(self, environment, template):20 raise TemplateNotFound()21 27 unmodified linesadded:test.py+12 added
1+from jinja2 import Environment2+3+env = Environment()4+tmpl = env.from_string("""5+<ul>6+{% for item in seq %}7+ <li>{{ item|e }}</li>8+{% endfor %}9+</ul>10+""")11+12+print tmpl.render(seq=range(10))