##// END OF EJS Templates
formatter: extract helper function to render template
Yuya Nishihara -
r32948:12a0794f default
parent child Browse files
Show More
@@ -357,23 +357,28 b' class templateformatter(baseformatter):'
357 ctxs = pycompat.byteskwargs(ctxs)
357 ctxs = pycompat.byteskwargs(ctxs)
358 assert all(k == 'ctx' for k in ctxs)
358 assert all(k == 'ctx' for k in ctxs)
359 self._item.update(ctxs)
359 self._item.update(ctxs)
360
360 def _showitem(self):
361 def _showitem(self):
362 item = self._item.copy()
363 item['index'] = next(self._counter)
364 self._renderitem(self._tref, item)
365
366 def _renderitem(self, ref, item):
361 # TODO: add support for filectx. probably each template keyword or
367 # TODO: add support for filectx. probably each template keyword or
362 # function will have to declare dependent resources. e.g.
368 # function will have to declare dependent resources. e.g.
363 # @templatekeyword(..., requires=('ctx',))
369 # @templatekeyword(..., requires=('ctx',))
364 props = {}
370 props = {}
365 if 'ctx' in self._item:
371 if 'ctx' in item:
366 props.update(templatekw.keywords)
372 props.update(templatekw.keywords)
367 props['index'] = next(self._counter)
368 # explicitly-defined fields precede templatekw
373 # explicitly-defined fields precede templatekw
369 props.update(self._item)
374 props.update(item)
370 if 'ctx' in self._item:
375 if 'ctx' in item:
371 # but template resources must be always available
376 # but template resources must be always available
372 props['templ'] = self._t
377 props['templ'] = self._t
373 props['repo'] = props['ctx'].repo()
378 props['repo'] = props['ctx'].repo()
374 props['revcache'] = {}
379 props['revcache'] = {}
375 props = pycompat.strkwargs(props)
380 props = pycompat.strkwargs(props)
376 g = self._t(self._tref, ui=self._ui, cache=self._cache, **props)
381 g = self._t(ref, ui=self._ui, cache=self._cache, **props)
377 self._out.write(templater.stringify(g))
382 self._out.write(templater.stringify(g))
378
383
379 templatespec = collections.namedtuple(r'templatespec',
384 templatespec = collections.namedtuple(r'templatespec',
General Comments 0
You need to be logged in to leave comments. Login now