Skip to content
Myr

[svn] added support for comments and some doc changes

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 9061e54 · Browse files · 7 files+66 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+66 added−7 removed

  • other:+66 added−7 removed

7 files+66 added−7 removed

added:docs/src/frameworks.txt+33 added
1=====================2Framework Integration3=====================45Jinja registers itself in the baker template plugin system. If your framework6supports baker (currently `TurboGears`_ and `pylons`_) you can add it very7easy.89Pylons10------1112Edit ``yourproject/config/middleware.py`` and add the following lines to13`config.init_app...`:1415.. sourcecode:: python1617 from jinja import Environment, FileSystemLoader1819 config.add_template_engine('jinja', {20 'jinja.environment': Environment(loader=FileSystemLoader('path/to/templates'))21 })2223To make Jinja the default template engine change the `init_app` call to24something like this:2526.. sourcecode:: python2728 config.init_app(global_conf, app_conf, package='yourproject',29 template_engine='jinja')303132.. _TurboGears: http://www.turbogears.org/33.. _pylons: http://www.pylonshq.com/
modified:docs/src/index.txt+2 added
16 unmodified lines
17 - `Test Functions <tests.txt>`_1819 - `Translators <translators.txt>`_2021 - `Framework Integration <frameworks.txt>`_2223- Template Designer Documentation:2425 - `Syntax Reference <designerdoc.txt>`_26
1 unmodified line
modified:jinja/translators/python.py+2 added
413 unmodified lines
414 defaults.append(self.handle_node(n))415416 write('def macro(*args):')417 self.indention += 1418 write('context.push()')419 write('%s = (args + %s[len(args):])' % (_to_tuple(args), _to_tuple(defaults)))420 write('macrobuffer = []')421 write('write = macrobuffer.append')422 buf.append(self.handle_node(node.body))423 write('context.pop()')424 write('return u\'\'.join(macrobuffer)')425 self.indention -= 1426 buf.append(self.indent('context[%r] = macro' % node.name))427
367 unmodified lines
modified:jinja/datastructure.py+7 added-1 removed
284 unmodified lines
285 return False286 return True287288 eos = property(lambda x: not x.__nonzero__(), doc=__nonzero__.__doc__)289 289290 def next(self):291 """Return the next token from the stream."""292 if self._pushed:293 rv = self._pushed.pop()
21 unmodified lines
315 yield token316 except StopIteration:317 raise IndexError('end of stream reached')318319 def drop_until(self, test, drop_needle=False):320 """Fetch tokens until a function matches and drop all321 tokens."""322 for token in self.fetch_until(test, drop_needle):323 pass324325 def push(self, lineno, token, data):326 """Push an yielded token back to the stream."""327 self._pushed.append((lineno, token, data))
modified:jinja/filters.py+4 added-4 removed
167 unmodified lines
168 {{ [1, 2, 3]|join }}169 -> 123170 """171 def wrapped(env, context, value):172 d = env.to_unicode(d)173 return d.join([env.to_unicode(x) for x in value])172 return env.to_unicode(d).join([env.to_unicode(x) for x in value])173 return wrapped174175176def do_count():
4 unmodified lines
181 """182 def wrapped(env, context, value):183 try:184 if type(value) in (int, float, long):186 return len(str(var))187 return len(var)185 return len(str(value))186 return len(value)187 except TypeError:188 return 0189 return wrapped190
114 unmodified lines
305 'title': do_title,306 'default': do_default,307 'join': do_join,308 'count': do_count,309 'length': do_count,310 'reverse': do_reverse,311 'center': do_center,312 'title': do_title,313 'capitalize': do_capitalize,
6 unmodified lines
modified:jinja/parser.py+10 added-2 removed
17 unmodified lines
1819# callback functions for the subparse method20end_of_block = lambda p, t, d: t == 'block_end'21end_of_variable = lambda p, t, d: t == 'variable_end'22end_of_comment = lambda p, t, d: t == 'comment_end'23switch_for = lambda p, t, d: t == 'name' and d in ('else', 'endfor')24end_of_for = lambda p, t, d: t == 'name' and d == 'endfor'25switch_if = lambda p, t, d: t == 'name' and d in ('else', 'elif', 'endif')26end_of_if = lambda p, t, d: t == 'name' and d == 'endif'
272 unmodified lines
299 plural = indicator = None300301 while True:302 lineno, token, data = self.tokenstream.next()303 # comments304 if token == 'comment_begin':305 self.tokenstream.drop_until(end_of_comment, True)306 # nested variables303 if token == 'variable_begin':307 elif token == 'variable_begin':308 _, variable_token, variable_name = self.tokenstream.next()309 if variable_token != 'name' or variable_name not in replacements:310 raise TemplateSyntaxError('unregistered translation '311 'variable %r.' % variable_name,
101 unmodified lines
413414 lineno = self.tokenstream.last[0]415 result = nodes.NodeList(lineno)416 for lineno, token, data in self.tokenstream:417 # comments418 if token == 'comment_begin':419 self.tokenstream.drop_until(end_of_comment, True)420421 # this token marks the begin or a variable section.422 # parse everything till the end of it.415 if token == 'variable_begin':423 elif token == 'variable_begin':424 gen = self.tokenstream.fetch_until(end_of_variable, True)425 result.append(self.directives['print'](lineno, gen))426427 # this token marks the start of a block. like for variables
61 unmodified lines
added:TODO+8 added
1===================2TODO List for Jinja3===================45- Requirements in Jinja (blocks and set directives) outside of renderable6 blocks should become part of the module not the generate function.78- Improve the context lookup (maybe with an optional C extension)