Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/hgwebdir_mod.py @ 37019:c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
And replace __call__(t, **mapping) in favor of generate(t, mapping). I prefer
a named function here since the templater isn't a simple function-like object.
.. api::
The templater is no longer callable. Use ``templater.generate(t, mapping)``
instead of ``templater(t, **pycompat.strkwargs(mapping))``.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 16 Mar 2018 21:39:32 +0900 |
parents | de117f579431 |
children | 30a7b32897f1 |
comparison
equal
deleted
inserted
replaced
37018:3e74d3cc500f | 37019:c97b936d8bb5 |
---|---|
450 if [r for r in repos if r.startswith(subdir)]: | 450 if [r for r in repos if r.startswith(subdir)]: |
451 return self.makeindex(req, res, tmpl, subdir) | 451 return self.makeindex(req, res, tmpl, subdir) |
452 | 452 |
453 # prefixes not found | 453 # prefixes not found |
454 res.status = '404 Not Found' | 454 res.status = '404 Not Found' |
455 res.setbodygen(tmpl('notfound', repo=virtual)) | 455 res.setbodygen(tmpl.generate('notfound', {'repo': virtual})) |
456 return res.sendresponse() | 456 return res.sendresponse() |
457 | 457 |
458 except ErrorResponse as e: | 458 except ErrorResponse as e: |
459 res.status = statusmessage(e.code, pycompat.bytestr(e)) | 459 res.status = statusmessage(e.code, pycompat.bytestr(e)) |
460 res.setbodygen(tmpl('error', error=e.message or '')) | 460 res.setbodygen(tmpl.generate('error', {'error': e.message or ''})) |
461 return res.sendresponse() | 461 return res.sendresponse() |
462 finally: | 462 finally: |
463 tmpl = None | 463 tmpl = None |
464 | 464 |
465 def makeindex(self, req, res, tmpl, subdir=""): | 465 def makeindex(self, req, res, tmpl, subdir=""): |
483 | 483 |
484 entries = indexentries(self.ui, self.repos, req, | 484 entries = indexentries(self.ui, self.repos, req, |
485 self.stripecount, sortcolumn=sortcolumn, | 485 self.stripecount, sortcolumn=sortcolumn, |
486 descending=descending, subdir=subdir) | 486 descending=descending, subdir=subdir) |
487 | 487 |
488 res.setbodygen(tmpl( | 488 mapping = { |
489 'index', | 489 'entries': entries, |
490 entries=entries, | 490 'subdir': subdir, |
491 subdir=subdir, | 491 'pathdef': hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), |
492 pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), | 492 'sortcolumn': sortcolumn, |
493 sortcolumn=sortcolumn, | 493 'descending': descending, |
494 descending=descending, | 494 } |
495 **dict(sort))) | 495 mapping.update(sort) |
496 | 496 res.setbodygen(tmpl.generate('index', mapping)) |
497 return res.sendresponse() | 497 return res.sendresponse() |
498 | 498 |
499 def templater(self, req, nonce): | 499 def templater(self, req, nonce): |
500 | 500 |
501 def motd(**map): | 501 def motd(**map): |