Exporters: make jinja engine strict

- configure the jinja Environment to raise exception when substitution
variables are not defined
- trim spaces and lines, to avoid empty lines in generated files
pull/3660/head
Liviu Ionescu 2017-01-18 19:31:59 +02:00 committed by Anna Bridge
parent c173a14f0b
commit 03d2cb8f03
1 changed files with 2 additions and 2 deletions

View File

@ -4,7 +4,7 @@ from abc import abstractmethod, ABCMeta
import logging import logging
from os.path import join, dirname, relpath, basename, realpath, normpath from os.path import join, dirname, relpath, basename, realpath, normpath
from itertools import groupby from itertools import groupby
from jinja2 import FileSystemLoader from jinja2 import FileSystemLoader, StrictUndefined
from jinja2.environment import Environment from jinja2.environment import Environment
import copy import copy
@ -115,7 +115,7 @@ class Exporter(object):
"""Generates a project file from a template using jinja""" """Generates a project file from a template using jinja"""
jinja_loader = FileSystemLoader( jinja_loader = FileSystemLoader(
os.path.dirname(os.path.abspath(__file__))) os.path.dirname(os.path.abspath(__file__)))
jinja_environment = Environment(loader=jinja_loader) jinja_environment = Environment(loader=jinja_loader, undefined=StrictUndefined, trim_blocks=True, lstrip_blocks=True)
template = jinja_environment.get_template(template_file) template = jinja_environment.get_template(template_file)
target_text = template.render(data) target_text = template.render(data)