diff mercurial/registrar.py @ 28692:6b3b958daf03

registrar: add templatefilter to mark a function as template filter (API) This patch also adds loadfilter() to templatefilters, because this combination helps to figure out how they cooperate with each other. Listing up loadfilter() in dispatch.extraloaders causes implicit loading template filter functions at loading (3rd party) extension. This change requires that "templatefilter" attribute of (3rd party) extension is registrar.templatefilter or so.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 30 Mar 2016 02:10:44 +0900
parents 009f58f1ea75
children cc103bd0dbf9
line wrap: on
line diff
--- a/mercurial/registrar.py	Sun Feb 14 20:43:30 2016 +0900
+++ b/mercurial/registrar.py	Wed Mar 30 02:10:44 2016 +0900
@@ -191,3 +191,28 @@
 
     Otherwise, explicit 'templatekw.loadkeyword()' is needed.
     """
+
+class templatefilter(_templateregistrarbase):
+    """Decorator to register template filer
+
+    Usage::
+
+        templatefilter = registrar.templatefilter()
+
+        @templatefilter('myfilter')
+        def myfilterfunc(text):
+            '''Explanation of this template filter ....
+            '''
+            pass
+
+    The first string argument is used also in online help.
+
+    'templatefilter' instance in example above can be used to
+    decorate multiple functions.
+
+    Decorated functions are registered automatically at loading
+    extension, if an instance named as 'templatefilter' is used for
+    decorating in extension.
+
+    Otherwise, explicit 'templatefilters.loadkeyword()' is needed.
+    """