mercurial/registrar.py
changeset 36475 e8d37838f5df
parent 35130 b22a0d9e0a83
child 36928 521f6c7e1756
--- a/mercurial/registrar.py	Sun Feb 25 12:50:30 2018 +0900
+++ b/mercurial/registrar.py	Sun Feb 25 13:24:35 2018 +0900
@@ -283,6 +283,14 @@
 
         templatekeyword = registrar.templatekeyword()
 
+        # new API (since Mercurial 4.6)
+        @templatekeyword('mykeyword', requires={'repo', 'ctx'})
+        def mykeywordfunc(context, mapping):
+            '''Explanation of this template keyword ....
+            '''
+            pass
+
+        # old API
         @templatekeyword('mykeyword')
         def mykeywordfunc(repo, ctx, templ, cache, revcache, **args):
             '''Explanation of this template keyword ....
@@ -291,6 +299,11 @@
 
     The first string argument is used also in online help.
 
+    Optional argument 'requires' should be a collection of resource names
+    which the template keyword depends on. This also serves as a flag to
+    switch to the new API. If 'requires' is unspecified, all template
+    keywords and resources are expanded to the function arguments.
+
     'templatekeyword' instance in example above can be used to
     decorate multiple functions.
 
@@ -301,6 +314,9 @@
     Otherwise, explicit 'templatekw.loadkeyword()' is needed.
     """
 
+    def _extrasetup(self, name, func, requires=None):
+        func._requires = requires
+
 class templatefilter(_templateregistrarbase):
     """Decorator to register template filer