Skip to content
Myr

add lstrip_blocks environment setting, fix lexer

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

authored by Kristi Tsukida · committed by Kristi Tsukida · parent 15605a8 · Browse files · 3 files+20 added−6 removed
This commit

State

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

Diff stats

3 files+20 added−6 removed

  • other:+20 added−6 removed

3 files+20 added−6 removed

modified:jinja2/defaults.py+1 added
19 unmodified lines
20COMMENT_END_STRING = '#}'21LINE_STATEMENT_PREFIX = None22LINE_COMMENT_PREFIX = None23TRIM_BLOCKS = False24LSTRIP_BLOCKS = False25NEWLINE_SEQUENCE = '\n'262728# default filters, tests and namespace
13 unmodified lines
modified:jinja2/environment.py+10 added-1 removed
132 unmodified lines
133 `trim_blocks`134 If this is set to ``True`` the first newline after a block is135 removed (block, not variable tag!). Defaults to `False`.136137 `lstrip_blocks`138 If this is set to ``True`` leading spaces and tabs are stripped139 from a block if the block starts the line. Defaults to `False`.140141 `newline_sequence`142 The sequence that starts a newline. Must be one of ``'\r'``,143 ``'\n'`` or ``'\r\n'``. The default is ``'\n'`` which is a144 useful default for Linux and OS X systems as well as web
82 unmodified lines
227 comment_end_string=COMMENT_END_STRING,228 line_statement_prefix=LINE_STATEMENT_PREFIX,229 line_comment_prefix=LINE_COMMENT_PREFIX,230 trim_blocks=TRIM_BLOCKS,231 lstrip_blocks=LSTRIP_BLOCKS,232 newline_sequence=NEWLINE_SEQUENCE,233 extensions=(),234 optimized=True,235 undefined=Undefined,
23 unmodified lines
259 self.comment_end_string = comment_end_string260 self.line_statement_prefix = line_statement_prefix261 self.line_comment_prefix = line_comment_prefix262 self.trim_blocks = trim_blocks263 self.lstrip_blocks = lstrip_blocks264 self.newline_sequence = newline_sequence265266 # runtime information267 self.undefined = undefined
37 unmodified lines
305 def overlay(self, block_start_string=missing, block_end_string=missing,306 variable_start_string=missing, variable_end_string=missing,307 comment_start_string=missing, comment_end_string=missing,308 line_statement_prefix=missing, line_comment_prefix=missing,303 trim_blocks=missing, extensions=missing, optimized=missing,309 trim_blocks=missing, lstrip_blocks=missing,310 extensions=missing, optimized=missing,311 undefined=missing, finalize=missing, autoescape=missing,312 loader=missing, cache_size=missing, auto_reload=missing,313 bytecode_cache=missing):314 """Create a new overlay environment that shares all the data with the
507 unmodified lines
822 comment_end_string=COMMENT_END_STRING,823 line_statement_prefix=LINE_STATEMENT_PREFIX,824 line_comment_prefix=LINE_COMMENT_PREFIX,825 trim_blocks=TRIM_BLOCKS,826 lstrip_blocks=LSTRIP_BLOCKS,827 newline_sequence=NEWLINE_SEQUENCE,828 extensions=(),829 optimized=True,830 undefined=Undefined,
2 unmodified lines
833 env = get_spontaneous_environment(834 block_start_string, block_end_string, variable_start_string,835 variable_end_string, comment_start_string, comment_end_string,836 line_statement_prefix, line_comment_prefix, trim_blocks,837 lstrip_blocks,838 newline_sequence, frozenset(extensions), optimized, undefined,839 finalize, autoescape, None, 0, False, None)840 return env.from_string(source, template_class=cls)841
289 unmodified lines
modified:jinja2/lexer.py+9 added-5 removed
422 unmodified lines
423 root_tag_rules = compile_rules(environment)424425 # block suffix if trimming is enabled426 block_suffix_re = environment.trim_blocks and '\\n?' or ''427 # TODO hook environment setting428 block_prefix_re = True and '[ \\t]*' or ''427 # strip leading spaces if lstrip_blocks is enabled428 block_prefix_re = environment.lstrip_blocks and r'^[ \t]*' or ''429430 print 'block_prefix_re = %s' % block_prefix_re431432 self.newline_sequence = environment.newline_sequence433434 # global lexing rules435 self.rules = {436 'root': [437 # directives438 (c('(.*?)(?:%s)' % '|'.join(437 [r'(?P<raw_begin>(?:\s*%s\-|%s%s)\s*raw\s*(?:\-%s\s*|%s))' % (439 [r'(?P<raw_begin>(?:\s*%s\-|%s%s|%s)\s*raw\s*(?:\-%s\s*|%s))' % (440 e(environment.block_start_string),441 block_prefix_re,442 e(environment.block_start_string),443 e(environment.block_start_string),444 e(environment.block_end_string),445 e(environment.block_end_string)446 )] + [444 r'(?P<%s_begin>\s*%s\-|%s)' % (n, r, r)447 r'(?P<%s_begin>\s*%s\-|%s)' % (n, r, r if n != "block" else '%s%s|%s' % (block_prefix_re, r, r) )448 for n, r in root_tag_rules449 ])), (TOKEN_DATA, '#bygroup'), '#bygroup'),450 # data451 (c('.+'), TOKEN_DATA, None)
23 unmodified lines
475 )), TOKEN_VARIABLE_END, '#pop')476 ] + tag_rules,477 # raw block478 TOKEN_RAW_BEGIN: [476 (c('(.*?)((?:\s*%s\-|%s%s)\s*endraw\s*(?:\-%s\s*|%s%s))' % (479 (c('(.*?)((?:\s*%s\-|%s%s|%s)\s*endraw\s*(?:\-%s\s*|%s%s))' % (480 e(environment.block_start_string),481 block_prefix_re,482 e(environment.block_start_string),483 e(environment.block_start_string),484 e(environment.block_end_string),485 e(environment.block_end_string),486 block_suffix_re487 )), (TOKEN_DATA, TOKEN_RAW_END), '#pop'),
202 unmodified lines