]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Merge remote-tracking branch 'wking/keep-trailing-newline'
authorArmin Ronacher <armin.ronacher@active-4.com>
Sun, 19 May 2013 10:09:19 +0000 (11:09 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sun, 19 May 2013 10:09:19 +0000 (11:09 +0100)
1  2 
CHANGES
docs/templates.rst
jinja2/defaults.py
jinja2/environment.py
jinja2/ext.py
jinja2/lexer.py
jinja2/testsuite/lexnparse.py

diff --cc CHANGES
index b7f28dde50ad9243902fb2f0e6fd8526841fc676,43f5e8ff08cba51ff07f28ca29e5fee8cc4ba57f..c6f95bcc351a99e496890c7d312ffca81ab0abf4
+++ b/CHANGES
@@@ -13,14 -13,10 +13,16 @@@ Version 2.
  - Added `urlencode` filter that automatically quotes values for
    URL safe usage with utf-8 as only supported encoding.  If applications
    want to change this encoding they can override the filter.
+ - Added `keep-trailing-newline` configuration to environments and
+   templates to optionally preserve the final trailing newline.
  - Accessing `last` on the loop context no longer causes the iterator
    to be consumed into a list.
 +- Python requirement changed: 2.6, 2.7 or >= 3.3 are required now,
 +  supported by same source code, using the "six" compatibility library.
 +- Allow `contextfunction` and other decorators to be applied to `__call__`.
 +- Added support for changing from newline to different signs in the `wordwrap`
 +  filter.
 +- Added support for ignoring memcache errors silently.
  
  Version 2.6
  -----------
Simple merge
Simple merge
index 58573a29ca3af62bf3d33747f3760532d326a5e6,fb04e64c32a7704dc65dbc7459a3b3cc50063191..23d00aa8a094f20da8aea309f0cccbce99f1d54d
  import os
  import sys
  from jinja2 import nodes
 -from jinja2.defaults import *
 +from jinja2.defaults import BLOCK_START_STRING, \
 +     BLOCK_END_STRING, VARIABLE_START_STRING, VARIABLE_END_STRING, \
 +     COMMENT_START_STRING, COMMENT_END_STRING, LINE_STATEMENT_PREFIX, \
 +     LINE_COMMENT_PREFIX, TRIM_BLOCKS, NEWLINE_SEQUENCE, \
-      DEFAULT_FILTERS, DEFAULT_TESTS, DEFAULT_NAMESPACE
++     DEFAULT_FILTERS, DEFAULT_TESTS, DEFAULT_NAMESPACE, \
++     KEEP_TRAILING_NEWLINE
  from jinja2.lexer import get_lexer, TokenStream
  from jinja2.parser import Parser
  from jinja2.optimizer import optimize
diff --cc jinja2/ext.py
Simple merge
diff --cc jinja2/lexer.py
index bd2e8616ba216ea7ff4d8e94c0fe219372ccec3e,0eb19f74706e9b2d2e3824924471db4bf7996d51..5594e0a64b6cac9a7185c18c36651452cae6479e
@@@ -557,7 -551,14 +559,14 @@@ class Lexer(object)
          """This method tokenizes the text and returns the tokens in a
          generator.  Use this method if you just want to tokenize a template.
          """
-         source = '\n'.join(six.text_type(source).splitlines())
 -        source = unicode(source)
++        source = six.text_type(source)
+         lines = source.splitlines()
+         if self.keep_trailing_newline and source:
+             for newline in ('\r\n', '\r', '\n'):
+                 if source.endswith(newline):
+                     lines.append('')
+                     break
+         source = '\n'.join(lines)
          pos = 0
          lineno = 1
          stack = ['root']
Simple merge