Skip to content
Myr

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

4 files+22 added−4 removed

modified:jinja2/compiler.py+3 added-3 removed
277 unmodified lines
278 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()285286 # -- Visitors
426 unmodified lines
713 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(')')721722 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 lines
modified:jinja2/environment.py+6 added-1 removed
102 unmodified lines
103 """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 lines
125 if parent is not None:126 name = self.join_path(name, parent)127 return self.loader.load(self, name)128129 def from_string(self, source, filename='<string>'):130 """Load a template from a string."""131 return Template(self, self.compile(source, filename))132133134class Template(object):135 """Represents a template."""136137 def __init__(self, environment, code):
12 unmodified lines
modified:jinja2/loaders.py+1 added
12 unmodified lines
13from jinja2.environment import Template141516class BaseLoader(object):17 """Baseclass for all loaders."""1819 def get_source(self, environment, template):20 raise TemplateNotFound()21
27 unmodified lines
added:test.py+12 added
1from jinja2 import Environment23env = Environment()4tmpl = env.from_string("""5<ul>6{% for item in seq %}7 <li>{{ item|e }}</li>8{% endfor %}9</ul>10""")1112print tmpl.render(seq=range(10))