comparison mercurial/formatter.py @ 32841:883adaea9e80

formatter: render template specified by templatespec tuple
author Yuya Nishihara <yuya@tcha.org>
date Sat, 22 Apr 2017 19:29:41 +0900
parents 57c13c0d1cde
children 2ecce24dfcd3
comparison
equal deleted inserted replaced
32840:57c13c0d1cde 32841:883adaea9e80
345 345
346 class templateformatter(baseformatter): 346 class templateformatter(baseformatter):
347 def __init__(self, ui, out, topic, opts): 347 def __init__(self, ui, out, topic, opts):
348 baseformatter.__init__(self, ui, topic, opts, _templateconverter) 348 baseformatter.__init__(self, ui, topic, opts, _templateconverter)
349 self._out = out 349 self._out = out
350 self._topic = topic
351 spec = lookuptemplate(ui, topic, opts.get('template', '')) 350 spec = lookuptemplate(ui, topic, opts.get('template', ''))
351 self._tref = spec.ref
352 self._t = loadtemplater(ui, spec, cache=templatekw.defaulttempl) 352 self._t = loadtemplater(ui, spec, cache=templatekw.defaulttempl)
353 self._counter = itertools.count() 353 self._counter = itertools.count()
354 self._cache = {} # for templatekw/funcs to store reusable data 354 self._cache = {} # for templatekw/funcs to store reusable data
355 def context(self, **ctxs): 355 def context(self, **ctxs):
356 '''insert context objects to be used to render template keywords''' 356 '''insert context objects to be used to render template keywords'''
369 if 'ctx' in self._item: 369 if 'ctx' in self._item:
370 # but template resources must be always available 370 # but template resources must be always available
371 props['templ'] = self._t 371 props['templ'] = self._t
372 props['repo'] = props['ctx'].repo() 372 props['repo'] = props['ctx'].repo()
373 props['revcache'] = {} 373 props['revcache'] = {}
374 g = self._t(self._topic, ui=self._ui, cache=self._cache, **props) 374 g = self._t(self._tref, ui=self._ui, cache=self._cache, **props)
375 self._out.write(templater.stringify(g)) 375 self._out.write(templater.stringify(g))
376 376
377 templatespec = collections.namedtuple(r'templatespec', 377 templatespec = collections.namedtuple(r'templatespec',
378 r'ref tmpl mapfile') 378 r'ref tmpl mapfile')
379 379