##// END OF EJS Templates
hgweb: Search templates in templatepath/style/map, too, using a common function....
Thomas Arendsen Hein -
r3276:db9d2a62 default
parent child Browse files
Show More
@@ -42,3 +42,20 b' def staticfile(directory, fname, req):'
42 except (TypeError, OSError):
42 except (TypeError, OSError):
43 # illegal fname or unreadable file
43 # illegal fname or unreadable file
44 return ""
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 demandload(globals(), 'urllib')
14 demandload(globals(), 'urllib')
15 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,streamclone,patch")
15 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,streamclone,patch")
16 demandload(globals(), "mercurial:templater")
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 from mercurial.node import *
18 from mercurial.node import *
19 from mercurial.i18n import gettext as _
19 from mercurial.i18n import gettext as _
20
20
@@ -743,15 +743,10 b' class hgweb(object):'
743 expand_form(req.form)
743 expand_form(req.form)
744 rewrite_request(req)
744 rewrite_request(req)
745
745
746 m = os.path.join(self.templatepath, "map")
747 style = self.repo.ui.config("web", "style", "")
746 style = self.repo.ui.config("web", "style", "")
748 if req.form.has_key('style'):
747 if req.form.has_key('style'):
749 style = req.form['style'][0]
748 style = req.form['style'][0]
750 if style:
749 mapfile = style_map(self.templatepath, 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
755
750
756 if not req.url:
751 if not req.url:
757 port = req.env["SERVER_PORT"]
752 port = req.env["SERVER_PORT"]
@@ -766,7 +761,7 b' class hgweb(object):'
766 or req.env.get('REPO_NAME')
761 or req.env.get('REPO_NAME')
767 or req.url.strip('/') or self.repo.root)
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 defaults={"url": req.url,
765 defaults={"url": req.url,
771 "repo": self.reponame,
766 "repo": self.reponame,
772 "header": header,
767 "header": header,
@@ -11,7 +11,7 b' from mercurial.demandload import demandl'
11 demandload(globals(), "ConfigParser mimetools cStringIO")
11 demandload(globals(), "ConfigParser mimetools cStringIO")
12 demandload(globals(), "mercurial:ui,hg,util,templater")
12 demandload(globals(), "mercurial:ui,hg,util,templater")
13 demandload(globals(), "mercurial.hgweb.hgweb_mod:hgweb")
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 from mercurial.i18n import gettext as _
15 from mercurial.i18n import gettext as _
16
16
17 # This is a stopgap
17 # This is a stopgap
@@ -69,17 +69,11 b' class hgwebdir(object):'
69 def footer(**map):
69 def footer(**map):
70 yield tmpl("footer", motd=self.motd, **map)
70 yield tmpl("footer", motd=self.motd, **map)
71
71
72 m = os.path.join(templater.templatepath(), "map")
73 style = self.style
72 style = self.style
74 if req.form.has_key('style'):
73 if req.form.has_key('style'):
75 style = req.form['style'][0]
74 style = req.form['style'][0]
76 if style != "":
75 mapfile = style_map(templater.templatepath(), style)
77 b = os.path.basename("map-" + style)
76 tmpl = templater.templater(mapfile, templater.common_filters,
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,
83 defaults={"header": header,
77 defaults={"header": header,
84 "footer": footer})
78 "footer": footer})
85
79
General Comments 0
You need to be logged in to leave comments. Login now