Show More
@@ -42,3 +42,20 b' def staticfile(directory, fname, req):' | |||
|
42 | 42 | except (TypeError, OSError): |
|
43 | 43 | # illegal fname or unreadable file |
|
44 | 44 | return "" |
|
45 | ||
|
46 | def style_map(templatepath, style): | |
|
47 | """Return path to mapfile for a given style. | |
|
48 | ||
|
49 | Searches mapfile in the following locations: | |
|
50 | 1. templatepath/style/map | |
|
51 | 2. templatepath/map-style | |
|
52 | 3. templatepath/map | |
|
53 | """ | |
|
54 | locations = style and [os.path.join(style, "map"), "map-"+style] or [] | |
|
55 | locations.append("map") | |
|
56 | for location in locations: | |
|
57 | mapfile = os.path.join(templatepath, location) | |
|
58 | if os.path.isfile(mapfile): | |
|
59 | return mapfile | |
|
60 | raise RuntimeError("No hgweb templates found in %r" % templatepath) | |
|
61 |
@@ -14,7 +14,7 b' demandload(globals(), "re zlib ConfigPar' | |||
|
14 | 14 | demandload(globals(), 'urllib') |
|
15 | 15 | demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,streamclone,patch") |
|
16 | 16 | demandload(globals(), "mercurial:templater") |
|
17 | demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile") | |
|
17 | demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile,style_map") | |
|
18 | 18 | from mercurial.node import * |
|
19 | 19 | from mercurial.i18n import gettext as _ |
|
20 | 20 | |
@@ -743,15 +743,10 b' class hgweb(object):' | |||
|
743 | 743 | expand_form(req.form) |
|
744 | 744 | rewrite_request(req) |
|
745 | 745 | |
|
746 | m = os.path.join(self.templatepath, "map") | |
|
747 | 746 | style = self.repo.ui.config("web", "style", "") |
|
748 | 747 | if req.form.has_key('style'): |
|
749 | 748 | style = req.form['style'][0] |
|
750 | if style: | |
|
751 | b = os.path.basename("map-" + style) | |
|
752 | p = os.path.join(self.templatepath, b) | |
|
753 | if os.path.isfile(p): | |
|
754 | m = p | |
|
749 | mapfile = style_map(self.templatepath, style) | |
|
755 | 750 | |
|
756 | 751 | if not req.url: |
|
757 | 752 | port = req.env["SERVER_PORT"] |
@@ -766,7 +761,7 b' class hgweb(object):' | |||
|
766 | 761 | or req.env.get('REPO_NAME') |
|
767 | 762 | or req.url.strip('/') or self.repo.root) |
|
768 | 763 | |
|
769 | self.t = templater.templater(m, templater.common_filters, | |
|
764 | self.t = templater.templater(mapfile, templater.common_filters, | |
|
770 | 765 | defaults={"url": req.url, |
|
771 | 766 | "repo": self.reponame, |
|
772 | 767 | "header": header, |
@@ -11,7 +11,7 b' from mercurial.demandload import demandl' | |||
|
11 | 11 | demandload(globals(), "ConfigParser mimetools cStringIO") |
|
12 | 12 | demandload(globals(), "mercurial:ui,hg,util,templater") |
|
13 | 13 | demandload(globals(), "mercurial.hgweb.hgweb_mod:hgweb") |
|
14 | demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile") | |
|
14 | demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile,style_map") | |
|
15 | 15 | from mercurial.i18n import gettext as _ |
|
16 | 16 | |
|
17 | 17 | # This is a stopgap |
@@ -69,17 +69,11 b' class hgwebdir(object):' | |||
|
69 | 69 | def footer(**map): |
|
70 | 70 | yield tmpl("footer", motd=self.motd, **map) |
|
71 | 71 | |
|
72 | m = os.path.join(templater.templatepath(), "map") | |
|
73 | 72 | style = self.style |
|
74 | 73 | if req.form.has_key('style'): |
|
75 | 74 | style = req.form['style'][0] |
|
76 | if style != "": | |
|
77 | b = os.path.basename("map-" + style) | |
|
78 | p = os.path.join(templater.templatepath(), b) | |
|
79 | if os.path.isfile(p): | |
|
80 | m = p | |
|
81 | ||
|
82 | tmpl = templater.templater(m, templater.common_filters, | |
|
75 | mapfile = style_map(templater.templatepath(), style) | |
|
76 | tmpl = templater.templater(mapfile, templater.common_filters, | |
|
83 | 77 | defaults={"header": header, |
|
84 | 78 | "footer": footer}) |
|
85 | 79 |
General Comments 0
You need to be logged in to leave comments.
Login now