Mercurial > hg
changeset 7966:aa983c3d94a9
templater: move stylemap function from hgweb to templater
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Sat, 04 Apr 2009 17:46:11 +0200 |
parents | 8503adbd9d49 |
children | c03f42159afa |
files | mercurial/hgweb/common.py mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py mercurial/hgweb/webcommands.py mercurial/templater.py |
diffstat | 5 files changed, 31 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/common.py Sat Apr 04 10:51:52 2009 +0200 +++ b/mercurial/hgweb/common.py Sat Apr 04 17:46:11 2009 +0200 @@ -78,25 +78,6 @@ else: raise ErrorResponse(HTTP_SERVER_ERROR, err.strerror) -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") - if isinstance(templatepath, str): - templatepath = [templatepath] - for path in templatepath: - for location in locations: - mapfile = os.path.join(path, location) - if os.path.isfile(mapfile): - return mapfile - raise RuntimeError("No hgweb templates found in %r" % templatepath) - def paritygen(stripecount, offset=0): """count parity of horizontal stripes for easier reading""" if stripecount and offset:
--- a/mercurial/hgweb/hgweb_mod.py Sat Apr 04 10:51:52 2009 +0200 +++ b/mercurial/hgweb/hgweb_mod.py Sat Apr 04 17:46:11 2009 +0200 @@ -9,7 +9,7 @@ import os from mercurial import ui, hg, util, hook, error, encoding from mercurial import templater, templatefilters -from common import get_mtime, style_map, ErrorResponse +from common import get_mtime, ErrorResponse from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED from request import wsgirequest @@ -37,9 +37,7 @@ self.stripecount = 1 # a repo owner may set web.templates in .hg/hgrc to get any file # readable by the user running the CGI script - self.templatepath = self.config("web", "templates", - templater.templatepath(), - untrusted=False) + self.templatepath = self.config('web', 'templates') # The CGI scripts are often run by a user different from the repo owner. # Trust the settings from the .hg/hgrc files by default. @@ -237,7 +235,7 @@ start = req.url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) - mapfile = style_map(self.templatepath, style) + mapfile = templater.stylemap(style, self.templatepath) if not self.reponame: self.reponame = (self.config("web", "name")
--- a/mercurial/hgweb/hgwebdir_mod.py Sat Apr 04 10:51:52 2009 +0200 +++ b/mercurial/hgweb/hgwebdir_mod.py Sat Apr 04 17:46:11 2009 +0200 @@ -9,7 +9,7 @@ import os from mercurial.i18n import _ from mercurial import ui, hg, util, templater, templatefilters, error, encoding -from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen,\ +from common import ErrorResponse, get_mtime, staticfile, paritygen,\ get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR from hgweb_mod import hgweb from request import wsgirequest @@ -317,7 +317,7 @@ style = req.form['style'][0] if self.stripecount is None: self.stripecount = int(config('web', 'stripes', 1)) - mapfile = style_map(templater.templatepath(), style) + mapfile = templater.stylemap(style) tmpl = templater.templater(mapfile, templatefilters.filters, defaults={"header": header, "footer": footer,
--- a/mercurial/hgweb/webcommands.py Sat Apr 04 10:51:52 2009 +0200 +++ b/mercurial/hgweb/webcommands.py Sat Apr 04 17:46:11 2009 +0200 @@ -7,7 +7,7 @@ import os, mimetypes, re, cgi, copy import webutil -from mercurial import error, archival, templatefilters +from mercurial import error, archival, templater, templatefilters from mercurial.node import short, hex from mercurial.util import binary from common import paritygen, staticfile, get_contact, ErrorResponse @@ -610,7 +610,7 @@ # readable by the user running the CGI script static = web.config("web", "static", None, untrusted=False) if not static: - tp = web.templatepath + tp = web.templatepath or templater.templatepath() if isinstance(tp, str): tp = [tp] static = [os.path.join(p, 'static') for p in tp]
--- a/mercurial/templater.py Sat Apr 04 10:51:52 2009 +0200 +++ b/mercurial/templater.py Sat Apr 04 17:46:11 2009 +0200 @@ -183,9 +183,32 @@ return normpaths +def stylemap(style, paths=None): + """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 + """ + + if paths is None: + paths = templatepath() + elif isinstance(paths, str): + paths = [templatepath] + + locations = style and [os.path.join(style, "map"), "map-" + style] or [] + locations.append("map") + for path in paths: + for location in locations: + mapfile = os.path.join(path, location) + if os.path.isfile(mapfile): + return mapfile + + raise RuntimeError("No hgweb templates found in %r" % paths) + def stringify(thing): '''turn nested template iterator into string.''' if hasattr(thing, '__iter__'): return "".join([stringify(t) for t in thing if t is not None]) return str(thing) -