From 19f92a0fe4ec113388721488b53b1d35933f84e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=81?= Date: Thu, 26 Nov 2020 15:38:58 +0300 Subject: [PATCH] Added auto trim and lstrip for jinja template's blocks. --- calculate/templates/template_engine.py | 7 +++++-- tests/templates/test_directory_processor.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/calculate/templates/template_engine.py b/calculate/templates/template_engine.py index b3b2e17..9d906fd 100644 --- a/calculate/templates/template_engine.py +++ b/calculate/templates/template_engine.py @@ -1558,9 +1558,12 @@ class TemplateEngine: if directory_path is not None: self.environment = Environment( - loader=FileSystemLoader(directory_path)) + loader=FileSystemLoader(directory_path), + trim_blocks=True, + lstrip_blocks=True) else: - self.environment = Environment() + self.environment = Environment(trim_blocks=True, + lstrip_blocks=True) self.environment.filters = CALCULATE_FILTERS diff --git a/tests/templates/test_directory_processor.py b/tests/templates/test_directory_processor.py index 8f21116..cf692de 100644 --- a/tests/templates/test_directory_processor.py +++ b/tests/templates/test_directory_processor.py @@ -1446,7 +1446,7 @@ class TestDirectoryProcessor: '# Processed template files:\n' + f'# {template_path}\n' + '#' + '-' * 79 + - f'\n\n\ntemplate = {template_path}') + f'\n\ntemplate = {template_path}') directory_processor = DirectoryProcessor( 'install', datavars_module=datavars,