##// END OF EJS Templates
templater: factor out helper that renders named template as string...
Yuya Nishihara -
r37004:de117f57 default
parent child Browse files
Show More
@@ -401,9 +401,7 b' class templateformatter(baseformatter):'
401 401 if 'ctx' in item or 'fctx' in item:
402 402 # but template resources must be always available
403 403 props['revcache'] = {}
404 props = pycompat.strkwargs(props)
405 g = self._t(ref, **props)
406 self._out.write(templateutil.stringify(g))
404 self._out.write(self._t.render(ref, props))
407 405
408 406 def end(self):
409 407 baseformatter.end(self)
@@ -30,7 +30,6 b' from .. import ('
30 30 repoview,
31 31 templatefilters,
32 32 templater,
33 templateutil,
34 33 ui as uimod,
35 34 util,
36 35 wireprotoserver,
@@ -378,8 +377,8 b' class hgweb(object):'
378 377
379 378 try:
380 379 rctx.tmpl = rctx.templater(req)
381 ctype = rctx.tmpl('mimetype', encoding=encoding.encoding)
382 ctype = templateutil.stringify(ctype)
380 ctype = rctx.tmpl.render('mimetype',
381 {'encoding': encoding.encoding})
383 382
384 383 # check read permissions non-static content
385 384 if cmd != 'static':
@@ -35,7 +35,6 b' from .. import ('
35 35 pycompat,
36 36 scmutil,
37 37 templater,
38 templateutil,
39 38 ui as uimod,
40 39 util,
41 40 )
@@ -381,8 +380,7 b' class hgwebdir(object):'
381 380
382 381 virtual = req.dispatchpath.strip('/')
383 382 tmpl = self.templater(req, nonce)
384 ctype = tmpl('mimetype', encoding=encoding.encoding)
385 ctype = templateutil.stringify(ctype)
383 ctype = tmpl.render('mimetype', {'encoding': encoding.encoding})
386 384
387 385 # Global defaults. These can be overridden by any handler.
388 386 res.status = '200 Script output follows'
@@ -33,7 +33,6 b' from . import ('
33 33 smartset,
34 34 templatekw,
35 35 templater,
36 templateutil,
37 36 util,
38 37 )
39 38 from .utils import dateutil
@@ -450,15 +449,13 b' class changesettemplater(changesetprinte'
450 449 self._parts.update(m)
451 450
452 451 if self._parts['docheader']:
453 self.ui.write(
454 templateutil.stringify(self.t(self._parts['docheader'])))
452 self.ui.write(self.t.render(self._parts['docheader'], {}))
455 453
456 454 def close(self):
457 455 if self._parts['docfooter']:
458 456 if not self.footer:
459 457 self.footer = ""
460 self.footer += templateutil.stringify(
461 self.t(self._parts['docfooter']))
458 self.footer += self.t.render(self._parts['docfooter'], {})
462 459 return super(changesettemplater, self).close()
463 460
464 461 def _show(self, ctx, copies, props):
@@ -467,18 +464,16 b' class changesettemplater(changesetprinte'
467 464 props['ctx'] = ctx
468 465 props['index'] = index = next(self._counter)
469 466 props['revcache'] = {'copies': copies}
470 props = pycompat.strkwargs(props)
471 467
472 468 # write separator, which wouldn't work well with the header part below
473 469 # since there's inherently a conflict between header (across items) and
474 470 # separator (per item)
475 471 if self._parts['separator'] and index > 0:
476 self.ui.write(
477 templateutil.stringify(self.t(self._parts['separator'])))
472 self.ui.write(self.t.render(self._parts['separator'], {}))
478 473
479 474 # write header
480 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 477 if self.buffered:
483 478 self.header[ctx.rev()] = h
484 479 else:
@@ -488,13 +483,12 b' class changesettemplater(changesetprinte'
488 483
489 484 # write changeset metadata, then patch if requested
490 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 487 self._showpatch(ctx)
493 488
494 489 if self._parts['footer']:
495 490 if not self.footer:
496 self.footer = templateutil.stringify(
497 self.t(self._parts['footer'], **props))
491 self.footer = self.t.render(self._parts['footer'], props)
498 492
499 493 def templatespec(tmpl, mapfile):
500 494 if mapfile:
@@ -725,8 +725,12 b' class templater(object):'
725 725
726 726 def renderdefault(self, mapping):
727 727 """Render the default unnamed template and return result as string"""
728 return self.render('', mapping)
729
730 def render(self, t, mapping):
731 """Render the specified named template and return result as string"""
728 732 mapping = pycompat.strkwargs(mapping)
729 return templateutil.stringify(self('', **mapping))
733 return templateutil.stringify(self(t, **mapping))
730 734
731 735 def __call__(self, t, **mapping):
732 736 mapping = pycompat.byteskwargs(mapping)
General Comments 0
You need to be logged in to leave comments. Login now