diff mercurial/templater.py @ 7107:125c8fedcbe0

Allow hgweb to search for templates in more than one path. This patch is constructed to make it easy for external extensions to provide their own templates, by updating templater.path.
author Brendan Cully <brendan@kublai.com>
date Fri, 17 Oct 2008 11:34:31 -0700
parents 6d824dc86907
children 526c40a74bd0
line wrap: on
line diff
--- a/mercurial/templater.py	Sun Oct 05 21:35:26 2008 +0200
+++ b/mercurial/templater.py	Fri Oct 17 11:34:31 2008 -0700
@@ -9,6 +9,8 @@
 import re, sys, os
 from mercurial import util
 
+path = ['templates', '../templates']
+
 def parsestring(s, quoted=True):
     '''parse a string using simple c-like syntax.
     string must be in quotes if quoted is True.'''
@@ -150,18 +152,27 @@
 def templatepath(name=None):
     '''return location of template file or directory (if no name).
     returns None if not found.'''
+    normpaths = []
 
     # executable version (py2exe) doesn't support __file__
     if hasattr(sys, 'frozen'):
         module = sys.executable
     else:
         module = __file__
-    for f in 'templates', '../templates':
-        fl = f.split('/')
-        if name: fl.append(name)
-        p = os.path.join(os.path.dirname(module), *fl)
-        if (name and os.path.exists(p)) or os.path.isdir(p):
+    for f in path:
+        if f.startswith('/'):
+            p = f
+        else:
+            fl = f.split('/')
+            p = os.path.join(os.path.dirname(module), *fl)
+        if name:
+            p = os.path.join(p, name)
+        if name and os.path.exists(p):
             return os.path.normpath(p)
+        elif os.path.isdir(p):
+            normpaths.append(os.path.normpath(p))
+
+    return normpaths
 
 def stringify(thing):
     '''turn nested template iterator into string.'''