Mercurial > hg
comparison mercurial/logcmdutil.py @ 36989:de117f579431
templater: factor out helper that renders named template as string
This is quite common in non-web templating, and **kwargs expansion is annoying
because of the unicode-ness of Python3.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 16 Mar 2018 21:24:12 +0900 |
parents | 317382151ac3 |
children | d64ae4fef471 |
comparison
equal
deleted
inserted
replaced
36988:317382151ac3 | 36989:de117f579431 |
---|---|
31 revsetlang, | 31 revsetlang, |
32 scmutil, | 32 scmutil, |
33 smartset, | 33 smartset, |
34 templatekw, | 34 templatekw, |
35 templater, | 35 templater, |
36 templateutil, | |
37 util, | 36 util, |
38 ) | 37 ) |
39 from .utils import dateutil | 38 from .utils import dateutil |
40 | 39 |
41 def getlimit(opts): | 40 def getlimit(opts): |
448 partnames = [p for p in self._parts.keys() if p != tmplspec.ref] | 447 partnames = [p for p in self._parts.keys() if p != tmplspec.ref] |
449 m = formatter.templatepartsmap(tmplspec, self.t, partnames) | 448 m = formatter.templatepartsmap(tmplspec, self.t, partnames) |
450 self._parts.update(m) | 449 self._parts.update(m) |
451 | 450 |
452 if self._parts['docheader']: | 451 if self._parts['docheader']: |
453 self.ui.write( | 452 self.ui.write(self.t.render(self._parts['docheader'], {})) |
454 templateutil.stringify(self.t(self._parts['docheader']))) | |
455 | 453 |
456 def close(self): | 454 def close(self): |
457 if self._parts['docfooter']: | 455 if self._parts['docfooter']: |
458 if not self.footer: | 456 if not self.footer: |
459 self.footer = "" | 457 self.footer = "" |
460 self.footer += templateutil.stringify( | 458 self.footer += self.t.render(self._parts['docfooter'], {}) |
461 self.t(self._parts['docfooter'])) | |
462 return super(changesettemplater, self).close() | 459 return super(changesettemplater, self).close() |
463 | 460 |
464 def _show(self, ctx, copies, props): | 461 def _show(self, ctx, copies, props): |
465 '''show a single changeset or file revision''' | 462 '''show a single changeset or file revision''' |
466 props = props.copy() | 463 props = props.copy() |
467 props['ctx'] = ctx | 464 props['ctx'] = ctx |
468 props['index'] = index = next(self._counter) | 465 props['index'] = index = next(self._counter) |
469 props['revcache'] = {'copies': copies} | 466 props['revcache'] = {'copies': copies} |
470 props = pycompat.strkwargs(props) | |
471 | 467 |
472 # write separator, which wouldn't work well with the header part below | 468 # write separator, which wouldn't work well with the header part below |
473 # since there's inherently a conflict between header (across items) and | 469 # since there's inherently a conflict between header (across items) and |
474 # separator (per item) | 470 # separator (per item) |
475 if self._parts['separator'] and index > 0: | 471 if self._parts['separator'] and index > 0: |
476 self.ui.write( | 472 self.ui.write(self.t.render(self._parts['separator'], {})) |
477 templateutil.stringify(self.t(self._parts['separator']))) | |
478 | 473 |
479 # write header | 474 # write header |
480 if self._parts['header']: | 475 if self._parts['header']: |
481 h = templateutil.stringify(self.t(self._parts['header'], **props)) | 476 h = self.t.render(self._parts['header'], props) |
482 if self.buffered: | 477 if self.buffered: |
483 self.header[ctx.rev()] = h | 478 self.header[ctx.rev()] = h |
484 else: | 479 else: |
485 if self.lastheader != h: | 480 if self.lastheader != h: |
486 self.lastheader = h | 481 self.lastheader = h |
487 self.ui.write(h) | 482 self.ui.write(h) |
488 | 483 |
489 # write changeset metadata, then patch if requested | 484 # write changeset metadata, then patch if requested |
490 key = self._parts[self._tref] | 485 key = self._parts[self._tref] |
491 self.ui.write(templateutil.stringify(self.t(key, **props))) | 486 self.ui.write(self.t.render(key, props)) |
492 self._showpatch(ctx) | 487 self._showpatch(ctx) |
493 | 488 |
494 if self._parts['footer']: | 489 if self._parts['footer']: |
495 if not self.footer: | 490 if not self.footer: |
496 self.footer = templateutil.stringify( | 491 self.footer = self.t.render(self._parts['footer'], props) |
497 self.t(self._parts['footer'], **props)) | |
498 | 492 |
499 def templatespec(tmpl, mapfile): | 493 def templatespec(tmpl, mapfile): |
500 if mapfile: | 494 if mapfile: |
501 return formatter.templatespec('changeset', tmpl, mapfile) | 495 return formatter.templatespec('changeset', tmpl, mapfile) |
502 else: | 496 else: |