comparison mercurial/templater.py @ 37022:c97b936d8bb5

templater: use named function to expand template against mapping dict (API) And replace __call__(t, **mapping) in favor of generate(t, mapping). I prefer a named function here since the templater isn't a simple function-like object. .. api:: The templater is no longer callable. Use ``templater.generate(t, mapping)`` instead of ``templater(t, **pycompat.strkwargs(mapping))``.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 16 Mar 2018 21:39:32 +0900
parents a5311d7f4af8
children 04aafcec00b9
comparison
equal deleted inserted replaced
37021:3e74d3cc500f 37022:c97b936d8bb5
768 """Render the default unnamed template and return result as string""" 768 """Render the default unnamed template and return result as string"""
769 return self.render('', mapping) 769 return self.render('', mapping)
770 770
771 def render(self, t, mapping): 771 def render(self, t, mapping):
772 """Render the specified named template and return result as string""" 772 """Render the specified named template and return result as string"""
773 mapping = pycompat.strkwargs(mapping) 773 return templateutil.stringify(self.generate(t, mapping))
774 return templateutil.stringify(self(t, **mapping)) 774
775 775 def generate(self, t, mapping):
776 def __call__(self, t, **mapping): 776 """Return a generator that renders the specified named template and
777 mapping = pycompat.byteskwargs(mapping) 777 yields chunks"""
778 ttype = t in self.map and self.map[t][0] or 'default' 778 ttype = t in self.map and self.map[t][0] or 'default'
779 if ttype not in self.ecache: 779 if ttype not in self.ecache:
780 try: 780 try:
781 ecls = engines[ttype] 781 ecls = engines[ttype]
782 except KeyError: 782 except KeyError: