Don't rely on Jinja2's lstrip_blocks

Travis has Jinja 2.6 but the option appeared in Jinj 2.7. Manually
perform the stripping in the preprocessing step instead.
This commit is contained in:
Corentin Wallez 2017-05-30 18:14:01 -04:00 committed by Corentin Wallez
parent 97bc020cf4
commit 698c2d1d8d
1 changed files with 9 additions and 2 deletions

View File

@ -213,7 +213,14 @@ class PreprocessingLoader(jinja2.BaseLoader):
numends = (len(self.blockend.split(line)) - 1) // 2 numends = (len(self.blockend.split(line)) - 1) // 2
indentation_level -= numends indentation_level -= numends
result.append(self.remove_indentation(line, indentation_level)) line = self.remove_indentation(line, indentation_level)
# Manually perform the lstrip_blocks jinja2 env options as it available starting from 2.7
# and Travis only has Jinja 2.6
if line.lstrip().startswith('{%'):
line = line.lstrip()
result.append(line)
numstarts = (len(self.blockstart.split(line)) - 1) // 2 numstarts = (len(self.blockstart.split(line)) - 1) // 2
indentation_level += numstarts indentation_level += numstarts
@ -233,7 +240,7 @@ class PreprocessingLoader(jinja2.BaseLoader):
FileRender = namedtuple('FileRender', ['template', 'output', 'params_dicts']) FileRender = namedtuple('FileRender', ['template', 'output', 'params_dicts'])
def do_renders(renders, template_dir, output_dir): def do_renders(renders, template_dir, output_dir):
env = jinja2.Environment(loader=PreprocessingLoader(template_dir), trim_blocks=True, lstrip_blocks=True, line_comment_prefix='//*') env = jinja2.Environment(loader=PreprocessingLoader(template_dir), trim_blocks=True, line_comment_prefix='//*')
for render in renders: for render in renders:
params = {} params = {}
for param_dict in render.params_dicts: for param_dict in render.params_dicts: