Show More
@@ -78,25 +78,6 b' def staticfile(directory, fname, req):' | |||
|
78 | 78 | else: |
|
79 | 79 | raise ErrorResponse(HTTP_SERVER_ERROR, err.strerror) |
|
80 | 80 | |
|
81 | def style_map(templatepath, style): | |
|
82 | """Return path to mapfile for a given style. | |
|
83 | ||
|
84 | Searches mapfile in the following locations: | |
|
85 | 1. templatepath/style/map | |
|
86 | 2. templatepath/map-style | |
|
87 | 3. templatepath/map | |
|
88 | """ | |
|
89 | locations = style and [os.path.join(style, "map"), "map-"+style] or [] | |
|
90 | locations.append("map") | |
|
91 | if isinstance(templatepath, str): | |
|
92 | templatepath = [templatepath] | |
|
93 | for path in templatepath: | |
|
94 | for location in locations: | |
|
95 | mapfile = os.path.join(path, location) | |
|
96 | if os.path.isfile(mapfile): | |
|
97 | return mapfile | |
|
98 | raise RuntimeError("No hgweb templates found in %r" % templatepath) | |
|
99 | ||
|
100 | 81 | def paritygen(stripecount, offset=0): |
|
101 | 82 | """count parity of horizontal stripes for easier reading""" |
|
102 | 83 | if stripecount and offset: |
@@ -9,7 +9,7 b'' | |||
|
9 | 9 | import os |
|
10 | 10 | from mercurial import ui, hg, util, hook, error, encoding |
|
11 | 11 | from mercurial import templater, templatefilters |
|
12 |
from common import get_mtime, |
|
|
12 | from common import get_mtime, ErrorResponse | |
|
13 | 13 | from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
|
14 | 14 | from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED |
|
15 | 15 | from request import wsgirequest |
@@ -37,9 +37,7 b' class hgweb(object):' | |||
|
37 | 37 | self.stripecount = 1 |
|
38 | 38 | # a repo owner may set web.templates in .hg/hgrc to get any file |
|
39 | 39 | # readable by the user running the CGI script |
|
40 |
self.templatepath = self.config( |
|
|
41 | templater.templatepath(), | |
|
42 | untrusted=False) | |
|
40 | self.templatepath = self.config('web', 'templates') | |
|
43 | 41 | |
|
44 | 42 | # The CGI scripts are often run by a user different from the repo owner. |
|
45 | 43 | # Trust the settings from the .hg/hgrc files by default. |
@@ -237,7 +235,7 b' class hgweb(object):' | |||
|
237 | 235 | |
|
238 | 236 | start = req.url[-1] == '?' and '&' or '?' |
|
239 | 237 | sessionvars = webutil.sessionvars(vars, start) |
|
240 |
mapfile = style |
|
|
238 | mapfile = templater.stylemap(style, self.templatepath) | |
|
241 | 239 | |
|
242 | 240 | if not self.reponame: |
|
243 | 241 | self.reponame = (self.config("web", "name") |
@@ -9,7 +9,7 b'' | |||
|
9 | 9 | import os |
|
10 | 10 | from mercurial.i18n import _ |
|
11 | 11 | from mercurial import ui, hg, util, templater, templatefilters, error, encoding |
|
12 |
from common import ErrorResponse, get_mtime, staticfile, |
|
|
12 | from common import ErrorResponse, get_mtime, staticfile, paritygen,\ | |
|
13 | 13 | get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
|
14 | 14 | from hgweb_mod import hgweb |
|
15 | 15 | from request import wsgirequest |
@@ -317,7 +317,7 b' class hgwebdir(object):' | |||
|
317 | 317 | style = req.form['style'][0] |
|
318 | 318 | if self.stripecount is None: |
|
319 | 319 | self.stripecount = int(config('web', 'stripes', 1)) |
|
320 |
mapfile = |
|
|
320 | mapfile = templater.stylemap(style) | |
|
321 | 321 | tmpl = templater.templater(mapfile, templatefilters.filters, |
|
322 | 322 | defaults={"header": header, |
|
323 | 323 | "footer": footer, |
@@ -7,7 +7,7 b'' | |||
|
7 | 7 | |
|
8 | 8 | import os, mimetypes, re, cgi, copy |
|
9 | 9 | import webutil |
|
10 | from mercurial import error, archival, templatefilters | |
|
10 | from mercurial import error, archival, templater, templatefilters | |
|
11 | 11 | from mercurial.node import short, hex |
|
12 | 12 | from mercurial.util import binary |
|
13 | 13 | from common import paritygen, staticfile, get_contact, ErrorResponse |
@@ -610,7 +610,7 b' def static(web, req, tmpl):' | |||
|
610 | 610 | # readable by the user running the CGI script |
|
611 | 611 | static = web.config("web", "static", None, untrusted=False) |
|
612 | 612 | if not static: |
|
613 | tp = web.templatepath | |
|
613 | tp = web.templatepath or templater.templatepath() | |
|
614 | 614 | if isinstance(tp, str): |
|
615 | 615 | tp = [tp] |
|
616 | 616 | static = [os.path.join(p, 'static') for p in tp] |
@@ -183,9 +183,32 b' def templatepath(name=None):' | |||
|
183 | 183 | |
|
184 | 184 | return normpaths |
|
185 | 185 | |
|
186 | def stylemap(style, paths=None): | |
|
187 | """Return path to mapfile for a given style. | |
|
188 | ||
|
189 | Searches mapfile in the following locations: | |
|
190 | 1. templatepath/style/map | |
|
191 | 2. templatepath/map-style | |
|
192 | 3. templatepath/map | |
|
193 | """ | |
|
194 | ||
|
195 | if paths is None: | |
|
196 | paths = templatepath() | |
|
197 | elif isinstance(paths, str): | |
|
198 | paths = [templatepath] | |
|
199 | ||
|
200 | locations = style and [os.path.join(style, "map"), "map-" + style] or [] | |
|
201 | locations.append("map") | |
|
202 | for path in paths: | |
|
203 | for location in locations: | |
|
204 | mapfile = os.path.join(path, location) | |
|
205 | if os.path.isfile(mapfile): | |
|
206 | return mapfile | |
|
207 | ||
|
208 | raise RuntimeError("No hgweb templates found in %r" % paths) | |
|
209 | ||
|
186 | 210 | def stringify(thing): |
|
187 | 211 | '''turn nested template iterator into string.''' |
|
188 | 212 | if hasattr(thing, '__iter__'): |
|
189 | 213 | return "".join([stringify(t) for t in thing if t is not None]) |
|
190 | 214 | return str(thing) |
|
191 |
General Comments 0
You need to be logged in to leave comments.
Login now