def templater(self): def header(**map): yield tmpl('header', encoding=util._encoding, **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): if self.motd is not None: yield self.motd else: yield config('web', 'motd', '') def config(section, name, default=None, untrusted=True): return self.parentui.config(section, name, default, untrusted) url = self._baseurl if not url.endswith('/'): url += '/' staticurl = url + 'static/' style = self.style if style is None: style = config('web', 'style', '') style = self.request.get("style", style) if self.stripecount is None: self.stripecount = int(config('web', 'stripes', 1)) mapfile = style_map(templater.templatepath(), style) tmpl = templater.templater(mapfile, templatefilters.filters, defaults={"header": header, "footer": footer, "motd": motd, "url": url, "staticurl": staticurl}) return tmpl
def templater(self, form): # determine scheme, port and server name # this is needed to create absolute urls req = self.request url = urlparse(req.url) urlbase = "http://www.example.com/" if len(url) > 1: urlbase = "%s://%s/" % (url[0], url[1]) staticurl = self.config("web", "staticurl") or urlbase + "static/" if not staticurl.endswith("/"): staticurl += "/" urlbase += req.repo_name + "/" # some functions for the templater def header(**map): yield tmpl("header", encoding="utf-8", **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): yield self.config("web", "motd", "") def sessionvars(**map): fields = [] if "style" in form: style = form.get("style", [""])[0] if style != self.config("web", "style", ""): fields.append(("style", style)) separator = req.url[-1] == "?" and ";" or "?" for name, value in fields: yield dict(name=name, value=value, separator=separator) separator = ";" # figure out which style to use style = self.style if "style" in form: style = form.get("style", [""])[0] mapfile = style_map(self.templatepath, style) if not self.reponame: self.reponame = ( self.config("web", "name") or os.environ.get("REPO_NAME") or req.url.strip("/") or self.repo.root ) # create the templater tmpl = templater.templater( mapfile, templatefilters.filters, defaults={ "url": urlbase, "staticurl": staticurl, "urlbase": urlbase, "repo": self.reponame, "header": header, "footer": footer, "motd": motd, "sessionvars": sessionvars, }, ) return tmpl