support heritage

This commit is contained in:
Emmanuel Garette 2021-02-28 20:38:45 +01:00
parent 651d89dd04
commit af8f0bfc9a
2 changed files with 39 additions and 26 deletions

View file

@ -34,16 +34,25 @@ from ...utils import normalize_family
from ...error import TemplateError
@classmethod
def cl_compile(kls, *args, **kwargs):
"""Rewrite compile methode to force some settings
"""
kwargs['compilerSettings'] = {'directiveStartToken' : '%',
'cheetahVarStartToken' : '%%',
'EOLSlurpToken' : '%',
'commentStartToken' : '#',
'multiLineCommentStartToken' : '#*',
'multiLineCommentEndToken' : '*#',
}
return kls.old_compile(*args, **kwargs) # pylint: disable=E1101
Template.old_compile = Template.compile
Template.compile = cl_compile
class CheetahTemplate(Template): # pylint: disable=W0223
"""Construct a cheetah templating object
"""
compilerSettings = {'directiveStartToken' : '%',
'cheetahVarStartToken' : '%%',
'EOLSlurpToken' : '%',
'commentStartToken' : '#',
'multiLineCommentStartToken' : '#*',
'multiLineCommentEndToken' : '*#',
}
def __init__(self,
filename: str,
source: str,
@ -54,17 +63,13 @@ class CheetahTemplate(Template): # pylint: disable=W0223
"""Initialize Creole CheetahTemplate
"""
if filename is not None:
Template.__init__(self,
file=filename,
searchList=[context, eosfunc, extra_context],
compilerSettings=self.compilerSettings,
)
super().__init__(file=filename,
searchList=[context, eosfunc, extra_context],
)
else:
Template.__init__(self,
source=source,
searchList=[context, eosfunc, extra_context],
compilerSettings=self.compilerSettings,
)
super().__init__(source=source,
searchList=[context, eosfunc, extra_context],
)
# FORK of Cheetah function, do not replace '\\' by '/'
def serverSidePath(self,

View file

@ -35,6 +35,23 @@ from ...utils import normalize_family
from ...error import TemplateError
@classmethod
def cl_compile(kls, *args, **kwargs):
"""Rewrite compile methode to force some settings
"""
kwargs['compilerSettings'] = {'directiveStartToken' : u'%',
'cheetahVarStartToken' : u'%%',
'EOLSlurpToken' : u'%',
'PSPStartToken' : u'µ' * 10,
'PSPEndToken' : u'µ' * 10,
'commentStartToken' : u'µ' * 10,
'commentEndToken' : u'µ' * 10,
'multiLineCommentStartToken' : u'µ' * 10,
'multiLineCommentEndToken' : u'µ' * 10}
return kls.old_compile(*args, **kwargs) # pylint: disable=E1101
oriCheetahTemplate.compile = cl_compile
class IsDefined:
"""
filtre permettant de ne pas lever d'exception au cas où
@ -58,15 +75,6 @@ class IsDefined:
class CheetahTemplate(oriCheetahTemplate):
compilerSettings = {'directiveStartToken' : '%',
'cheetahVarStartToken' : '%%',
'EOLSlurpToken' : '%',
'PSPStartToken' : 'µ' * 10,
'PSPEndToken' : 'µ' * 10,
'commentStartToken' : 'µ' * 10,
'commentEndToken' : 'µ' * 10,
'multiLineCommentStartToken' : 'µ' * 10,
'multiLineCommentEndToken' : 'µ' * 10}
def __init__(self,
filename: str,
source: str,