changeset 37067:04aafcec00b9

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__().
author Yuya Nishihara <yuya@tcha.org>
date Fri, 16 Mar 2018 22:36:40 +0900
parents b33b91ca2ec2
children aa97e06a1912
files mercurial/templater.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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