creole_legacy and creole have differents compilers

This commit is contained in:
Emmanuel Garette 2022-03-05 11:16:58 +01:00
parent 5c526cf2b4
commit 9de06705e8
3 changed files with 11 additions and 9 deletions

View File

@ -38,12 +38,12 @@ from ...error import TemplateError
def cl_compile(kls, *args, **kwargs): def cl_compile(kls, *args, **kwargs):
"""Rewrite compile methode to force some settings """Rewrite compile methode to force some settings
""" """
kwargs['compilerSettings'] = {'directiveStartToken' : '%', kwargs['compilerSettings'] = {'directiveStartToken': '%',
'cheetahVarStartToken' : '%%', 'cheetahVarStartToken': '%%',
'EOLSlurpToken' : '%', 'EOLSlurpToken': '%',
'commentStartToken' : '#', 'commentStartToken': '#',
'multiLineCommentStartToken' : '#*', 'multiLineCommentStartToken': '#*',
'multiLineCommentEndToken' : '*#', 'multiLineCommentEndToken': '*#',
} }
return kls.old_compile(*args, **kwargs) # pylint: disable=E1101 return kls.old_compile(*args, **kwargs) # pylint: disable=E1101
Template.old_compile = Template.compile Template.old_compile = Template.compile

View File

@ -49,7 +49,6 @@ def cl_compile(kls, *args, **kwargs):
'multiLineCommentStartToken' : u'µ' * 10, 'multiLineCommentStartToken' : u'µ' * 10,
'multiLineCommentEndToken' : u'µ' * 10} 'multiLineCommentEndToken' : u'µ' * 10}
return kls.old_compile(*args, **kwargs) # pylint: disable=E1101 return kls.old_compile(*args, **kwargs) # pylint: disable=E1101
oriCheetahTemplate.compile = cl_compile
class IsDefined: class IsDefined:
@ -126,6 +125,8 @@ def process(filename: str,
"""Process a cheetah template """Process a cheetah template
""" """
# full path of the destination file # full path of the destination file
ori_compile = oriCheetahTemplate.compile
oriCheetahTemplate.compile = cl_compile
try: try:
extra_context = {'normalize_family': normalize_family, extra_context = {'normalize_family': normalize_family,
'rougail_filename': true_destfilename, 'rougail_filename': true_destfilename,
@ -148,13 +149,16 @@ def process(filename: str,
msg = f"Error: unknown variable used in template {filename} to {destfilename}: {varname}" msg = f"Error: unknown variable used in template {filename} to {destfilename}: {varname}"
else: else:
msg = f"Error: unknown variable used in file {destfilename}: {varname}" msg = f"Error: unknown variable used in file {destfilename}: {varname}"
oriCheetahTemplate.compile = ori_compile
raise TemplateError(_(msg)) from err raise TemplateError(_(msg)) from err
except Exception as err: # pragma: no cover except Exception as err: # pragma: no cover
if filename: if filename:
msg = _(f"Error while instantiating template {filename} to {destfilename}: {err}") msg = _(f"Error while instantiating template {filename} to {destfilename}: {err}")
else: else:
msg = _(f"Error while instantiating filename {destfilename}: {err}") msg = _(f"Error while instantiating filename {destfilename}: {err}")
oriCheetahTemplate.compile = ori_compile
raise TemplateError(msg) from err raise TemplateError(msg) from err
with open(destfilename, 'w') as file_h: with open(destfilename, 'w') as file_h:
file_h.write(data) file_h.write(data)
oriCheetahTemplate.compile = ori_compile

View File

@ -1,6 +1,4 @@
#attr
leader: a leader: a
follower2: follower2:
#key
leader: a leader: a
follower2: follower2: