templater: add context.preload(t) to test if the specified template exists
authorYuya Nishihara <yuya@tcha.org>
Fri, 16 Mar 2018 22:36:40 +0900
changeset 37067 04aafcec00b9
parent 37066 b33b91ca2ec2
child 37068 aa97e06a1912
templater: add context.preload(t) to test if the specified template exists I'm going to remove 'templ' from the resources dict because it is the only resource that the caller can't provide. This also implies that putting 'templ' into the resources dict creates a reference cycle. context.preload(t) will be used in place of templater.__contains__().
mercurial/templater.py
--- a/mercurial/templater.py	Sun Mar 18 12:28:19 2018 +0900
+++ b/mercurial/templater.py	Fri Mar 16 22:36:40 2018 +0900
@@ -627,6 +627,14 @@
                 raise
         return self._cache[t]
 
+    def preload(self, t):
+        """Load, parse, and cache the specified template if available"""
+        try:
+            self._load(t)
+            return True
+        except templateutil.TemplateNotFound:
+            return False
+
     def process(self, t, mapping):
         '''Perform expansion. t is name of map element to expand.
         mapping contains added elements for use during expansion. Is a