Mercurial > hg-stable
changeset 3276:db9d2a624521
hgweb: Search templates in templatepath/style/map, too, using a common function.
This allows for web templates to be self-contained in a directory, which makes
copying and modifying them easier.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 06 Oct 2006 18:28:50 +0200 |
parents | 7ae37d99d47e |
children | 105253b30239 |
files | mercurial/hgweb/common.py mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py |
diffstat | 3 files changed, 23 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/common.py Fri Oct 06 16:24:14 2006 +0200 +++ b/mercurial/hgweb/common.py Fri Oct 06 18:28:50 2006 +0200 @@ -42,3 +42,20 @@ except (TypeError, OSError): # illegal fname or unreadable file return "" + +def style_map(templatepath, style): + """Return path to mapfile for a given style. + + Searches mapfile in the following locations: + 1. templatepath/style/map + 2. templatepath/map-style + 3. templatepath/map + """ + locations = style and [os.path.join(style, "map"), "map-"+style] or [] + locations.append("map") + for location in locations: + mapfile = os.path.join(templatepath, location) + if os.path.isfile(mapfile): + return mapfile + raise RuntimeError("No hgweb templates found in %r" % templatepath) +
--- a/mercurial/hgweb/hgweb_mod.py Fri Oct 06 16:24:14 2006 +0200 +++ b/mercurial/hgweb/hgweb_mod.py Fri Oct 06 18:28:50 2006 +0200 @@ -14,7 +14,7 @@ demandload(globals(), 'urllib') demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,streamclone,patch") demandload(globals(), "mercurial:templater") -demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile") +demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile,style_map") from mercurial.node import * from mercurial.i18n import gettext as _ @@ -743,15 +743,10 @@ expand_form(req.form) rewrite_request(req) - m = os.path.join(self.templatepath, "map") style = self.repo.ui.config("web", "style", "") if req.form.has_key('style'): style = req.form['style'][0] - if style: - b = os.path.basename("map-" + style) - p = os.path.join(self.templatepath, b) - if os.path.isfile(p): - m = p + mapfile = style_map(self.templatepath, style) if not req.url: port = req.env["SERVER_PORT"] @@ -766,7 +761,7 @@ or req.env.get('REPO_NAME') or req.url.strip('/') or self.repo.root) - self.t = templater.templater(m, templater.common_filters, + self.t = templater.templater(mapfile, templater.common_filters, defaults={"url": req.url, "repo": self.reponame, "header": header,
--- a/mercurial/hgweb/hgwebdir_mod.py Fri Oct 06 16:24:14 2006 +0200 +++ b/mercurial/hgweb/hgwebdir_mod.py Fri Oct 06 18:28:50 2006 +0200 @@ -11,7 +11,7 @@ demandload(globals(), "ConfigParser mimetools cStringIO") demandload(globals(), "mercurial:ui,hg,util,templater") demandload(globals(), "mercurial.hgweb.hgweb_mod:hgweb") -demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile") +demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile,style_map") from mercurial.i18n import gettext as _ # This is a stopgap @@ -69,17 +69,11 @@ def footer(**map): yield tmpl("footer", motd=self.motd, **map) - m = os.path.join(templater.templatepath(), "map") style = self.style if req.form.has_key('style'): style = req.form['style'][0] - if style != "": - b = os.path.basename("map-" + style) - p = os.path.join(templater.templatepath(), b) - if os.path.isfile(p): - m = p - - tmpl = templater.templater(m, templater.common_filters, + mapfile = style_map(templater.templatepath(), style) + tmpl = templater.templater(mapfile, templater.common_filters, defaults={"header": header, "footer": footer})