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