comparison mercurial/templater.py @ 32873:2ecce24dfcd3

templater: add simple interface for unnamed template (API) This provides a simpler API for callers which don't need full templating stack. Instead of storing the given template as the name specified by topic, use '' as the default template to be rendered.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 22 Apr 2017 19:56:47 +0900
parents af854b1b36f8
children 11c0bb4ccc76
comparison
equal deleted inserted replaced
32872:9fcb6df413c9 32873:2ecce24dfcd3
1296 except IOError as inst: 1296 except IOError as inst:
1297 raise IOError(inst.args[0], _('template file %s: %s') % 1297 raise IOError(inst.args[0], _('template file %s: %s') %
1298 (self.map[t][1], inst.args[1])) 1298 (self.map[t][1], inst.args[1]))
1299 return self.cache[t] 1299 return self.cache[t]
1300 1300
1301 def render(self, mapping):
1302 """Render the default unnamed template and return result as string"""
1303 return stringify(self('', **mapping))
1304
1301 def __call__(self, t, **mapping): 1305 def __call__(self, t, **mapping):
1302 ttype = t in self.map and self.map[t][0] or 'default' 1306 ttype = t in self.map and self.map[t][0] or 'default'
1303 if ttype not in self.ecache: 1307 if ttype not in self.ecache:
1304 try: 1308 try:
1305 ecls = engines[ttype] 1309 ecls = engines[ttype]