##// END OF EJS Templates
Allow hgweb to search for templates in more than one path....
Brendan Cully -
r7107:125c8fed default
parent child Browse files
Show More
@@ -82,10 +82,13 b' def style_map(templatepath, style):'
82 82 """
83 83 locations = style and [os.path.join(style, "map"), "map-"+style] or []
84 84 locations.append("map")
85 for location in locations:
86 mapfile = os.path.join(templatepath, location)
87 if os.path.isfile(mapfile):
88 return mapfile
85 if isinstance(templatepath, str):
86 templatepath = [templatepath]
87 for path in templatepath:
88 for location in locations:
89 mapfile = os.path.join(path, location)
90 if os.path.isfile(mapfile):
91 return mapfile
89 92 raise RuntimeError("No hgweb templates found in %r" % templatepath)
90 93
91 94 def paritygen(stripecount, offset=0):
@@ -84,11 +84,11 b' class hgwebdir(object):'
84 84
85 85 # a static file
86 86 if virtual.startswith('static/') or 'static' in req.form:
87 static = os.path.join(templater.templatepath(), 'static')
88 87 if virtual.startswith('static/'):
89 88 fname = virtual[7:]
90 89 else:
91 90 fname = req.form['static'][0]
91 static = templater.templatepath('static')
92 92 return staticfile(static, fname, req)
93 93
94 94 # top-level index
@@ -566,9 +566,15 b' def static(web, req, tmpl):'
566 566 fname = req.form['file'][0]
567 567 # a repo owner may set web.static in .hg/hgrc to get any file
568 568 # readable by the user running the CGI script
569 static = web.config("web", "static",
570 os.path.join(web.templatepath, "static"),
571 untrusted=False)
569 static = web.config("web", "static", None, untrusted=False)
570 if not static:
571 tp = web.templatepath
572 if isinstance(tp, str):
573 tp = [tp]
574 for path in tp:
575 static = os.path.join(path, 'static')
576 if os.path.isdir(static):
577 break
572 578 return [staticfile(static, fname, req)]
573 579
574 580 def graph(web, req, tmpl):
@@ -9,6 +9,8 b' from i18n import _'
9 9 import re, sys, os
10 10 from mercurial import util
11 11
12 path = ['templates', '../templates']
13
12 14 def parsestring(s, quoted=True):
13 15 '''parse a string using simple c-like syntax.
14 16 string must be in quotes if quoted is True.'''
@@ -150,18 +152,27 b' class templater(object):'
150 152 def templatepath(name=None):
151 153 '''return location of template file or directory (if no name).
152 154 returns None if not found.'''
155 normpaths = []
153 156
154 157 # executable version (py2exe) doesn't support __file__
155 158 if hasattr(sys, 'frozen'):
156 159 module = sys.executable
157 160 else:
158 161 module = __file__
159 for f in 'templates', '../templates':
160 fl = f.split('/')
161 if name: fl.append(name)
162 p = os.path.join(os.path.dirname(module), *fl)
163 if (name and os.path.exists(p)) or os.path.isdir(p):
162 for f in path:
163 if f.startswith('/'):
164 p = f
165 else:
166 fl = f.split('/')
167 p = os.path.join(os.path.dirname(module), *fl)
168 if name:
169 p = os.path.join(p, name)
170 if name and os.path.exists(p):
164 171 return os.path.normpath(p)
172 elif os.path.isdir(p):
173 normpaths.append(os.path.normpath(p))
174
175 return normpaths
165 176
166 177 def stringify(thing):
167 178 '''turn nested template iterator into string.'''
General Comments 0
You need to be logged in to leave comments. Login now