comparison mercurial/hgweb/hgwebdir_mod.py @ 38928:4167437a45dd

hgweb: use registrar to add "motd" template keyword This prepares for deprecation of old-style keyword functions.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 28 Jul 2018 21:02:05 +0900
parents 258d90f69076
children 536f22d6c2c5
comparison
equal deleted inserted replaced
38927:aebfc4c5c855 38928:4167437a45dd
31 encoding, 31 encoding,
32 error, 32 error,
33 hg, 33 hg,
34 profiling, 34 profiling,
35 pycompat, 35 pycompat,
36 registrar,
36 scmutil, 37 scmutil,
37 templater, 38 templater,
38 templateutil, 39 templateutil,
39 ui as uimod, 40 ui as uimod,
40 util, 41 util,
493 res.setbodygen(tmpl.generate('index', mapping)) 494 res.setbodygen(tmpl.generate('index', mapping))
494 return res.sendresponse() 495 return res.sendresponse()
495 496
496 def templater(self, req, nonce): 497 def templater(self, req, nonce):
497 498
498 def motd(**map):
499 if self.motd is not None:
500 yield self.motd
501 else:
502 yield config('web', 'motd')
503
504 def config(section, name, default=uimod._unset, untrusted=True): 499 def config(section, name, default=uimod._unset, untrusted=True):
505 return self.ui.config(section, name, default, untrusted) 500 return self.ui.config(section, name, default, untrusted)
506 501
507 vars = {} 502 vars = {}
508 styles, (style, mapfile) = hgweb_mod.getstyle(req, config, 503 styles, (style, mapfile) = hgweb_mod.getstyle(req, config,
518 if not staticurl.endswith('/'): 513 if not staticurl.endswith('/'):
519 staticurl += '/' 514 staticurl += '/'
520 515
521 defaults = { 516 defaults = {
522 "encoding": encoding.encoding, 517 "encoding": encoding.encoding,
523 "motd": motd,
524 "url": req.apppath + '/', 518 "url": req.apppath + '/',
525 "logourl": logourl, 519 "logourl": logourl,
526 "logoimg": logoimg, 520 "logoimg": logoimg,
527 "staticurl": staticurl, 521 "staticurl": staticurl,
528 "sessionvars": sessionvars, 522 "sessionvars": sessionvars,
529 "style": style, 523 "style": style,
530 "nonce": nonce, 524 "nonce": nonce,
531 } 525 }
526 templatekeyword = registrar.templatekeyword(defaults)
527 @templatekeyword('motd', requires=())
528 def motd(context, mapping):
529 if self.motd is not None:
530 yield self.motd
531 else:
532 yield config('web', 'motd')
533
532 tmpl = templater.templater.frommapfile(mapfile, defaults=defaults) 534 tmpl = templater.templater.frommapfile(mapfile, defaults=defaults)
533 return tmpl 535 return tmpl