##// 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 if 'ctx' in item or 'fctx' in item:
401 if 'ctx' in item or 'fctx' in item:
402 # but template resources must be always available
402 # but template resources must be always available
403 props['revcache'] = {}
403 props['revcache'] = {}
404 props = pycompat.strkwargs(props)
404 self._out.write(self._t.render(ref, props))
405 g = self._t(ref, **props)
406 self._out.write(templateutil.stringify(g))
407
405
408 def end(self):
406 def end(self):
409 baseformatter.end(self)
407 baseformatter.end(self)
@@ -30,7 +30,6 b' from .. import ('
30 repoview,
30 repoview,
31 templatefilters,
31 templatefilters,
32 templater,
32 templater,
33 templateutil,
34 ui as uimod,
33 ui as uimod,
35 util,
34 util,
36 wireprotoserver,
35 wireprotoserver,
@@ -378,8 +377,8 b' class hgweb(object):'
378
377
379 try:
378 try:
380 rctx.tmpl = rctx.templater(req)
379 rctx.tmpl = rctx.templater(req)
381 ctype = rctx.tmpl('mimetype', encoding=encoding.encoding)
380 ctype = rctx.tmpl.render('mimetype',
382 ctype = templateutil.stringify(ctype)
381 {'encoding': encoding.encoding})
383
382
384 # check read permissions non-static content
383 # check read permissions non-static content
385 if cmd != 'static':
384 if cmd != 'static':
@@ -35,7 +35,6 b' from .. import ('
35 pycompat,
35 pycompat,
36 scmutil,
36 scmutil,
37 templater,
37 templater,
38 templateutil,
39 ui as uimod,
38 ui as uimod,
40 util,
39 util,
41 )
40 )
@@ -381,8 +380,7 b' class hgwebdir(object):'
381
380
382 virtual = req.dispatchpath.strip('/')
381 virtual = req.dispatchpath.strip('/')
383 tmpl = self.templater(req, nonce)
382 tmpl = self.templater(req, nonce)
384 ctype = tmpl('mimetype', encoding=encoding.encoding)
383 ctype = tmpl.render('mimetype', {'encoding': encoding.encoding})
385 ctype = templateutil.stringify(ctype)
386
384
387 # Global defaults. These can be overridden by any handler.
385 # Global defaults. These can be overridden by any handler.
388 res.status = '200 Script output follows'
386 res.status = '200 Script output follows'
@@ -33,7 +33,6 b' from . import ('
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
@@ -450,15 +449,13 b' class changesettemplater(changesetprinte'
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):
@@ -467,18 +464,16 b' class changesettemplater(changesetprinte'
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:
@@ -488,13 +483,12 b' class changesettemplater(changesetprinte'
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:
@@ -725,8 +725,12 b' class templater(object):'
725
725
726 def renderdefault(self, mapping):
726 def renderdefault(self, mapping):
727 """Render the default unnamed template and return result as string"""
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 mapping = pycompat.strkwargs(mapping)
732 mapping = pycompat.strkwargs(mapping)
729 return templateutil.stringify(self('', **mapping))
733 return templateutil.stringify(self(t, **mapping))
730
734
731 def __call__(self, t, **mapping):
735 def __call__(self, t, **mapping):
732 mapping = pycompat.byteskwargs(mapping)
736 mapping = pycompat.byteskwargs(mapping)
General Comments 0
You need to be logged in to leave comments. Login now