diff 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
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py	Sun Jul 22 11:21:43 2018 +0900
+++ b/mercurial/hgweb/hgwebdir_mod.py	Sat Jul 28 21:02:05 2018 +0900
@@ -33,6 +33,7 @@
     hg,
     profiling,
     pycompat,
+    registrar,
     scmutil,
     templater,
     templateutil,
@@ -495,12 +496,6 @@
 
     def templater(self, req, nonce):
 
-        def motd(**map):
-            if self.motd is not None:
-                yield self.motd
-            else:
-                yield config('web', 'motd')
-
         def config(section, name, default=uimod._unset, untrusted=True):
             return self.ui.config(section, name, default, untrusted)
 
@@ -520,7 +515,6 @@
 
         defaults = {
             "encoding": encoding.encoding,
-            "motd": motd,
             "url": req.apppath + '/',
             "logourl": logourl,
             "logoimg": logoimg,
@@ -529,5 +523,13 @@
             "style": style,
             "nonce": nonce,
         }
+        templatekeyword = registrar.templatekeyword(defaults)
+        @templatekeyword('motd', requires=())
+        def motd(context, mapping):
+            if self.motd is not None:
+                yield self.motd
+            else:
+                yield config('web', 'motd')
+
         tmpl = templater.templater.frommapfile(mapfile, defaults=defaults)
         return tmpl