Mercurial > hg
changeset 601:8865eb8ade99
Add globals to templater/fixup RSS
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Add globals to templater/fixup RSS
This removes a bunch of duplicate header() and footer() bits and makes
url and reponame available to all templates.
Fix up RSS bits to use url
Fix strftime call
manifest hash: 63e616e4c7f517a630d80429336817d64e900b68
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCyLlRywK+sNU5EO8RAj9IAJkBDzMQaOwRmF0q8tRmVRnzHCjShACfSTCj
dbfAWg1crv/mUuRZlWL6Tc4=
=Z331
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Sun, 03 Jul 2005 20:21:37 -0800 |
parents | 11c379e23ad6 |
children | 56d81b303656 |
files | mercurial/hgweb.py templates/changelogentry-rss.tmpl templates/filelogentry-rss.tmpl |
diffstat | 3 files changed, 21 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb.py Sun Jul 03 20:10:21 2005 -0800 +++ b/mercurial/hgweb.py Sun Jul 03 20:21:37 2005 -0800 @@ -84,11 +84,12 @@ return class templater: - def __init__(self, mapfile, filters = {}): + def __init__(self, mapfile, filters = {}, defaults = {}): self.cache = {} self.map = {} self.base = os.path.dirname(mapfile) self.filters = filters + self.defaults = defaults for l in file(mapfile): m = re.match(r'(\S+)\s*=\s*"(.*)"$', l) @@ -102,14 +103,16 @@ raise "unknown map entry '%s'" % l def __call__(self, t, **map): + m = self.defaults.copy() + m.update(map) try: tmpl = self.cache[t] except KeyError: tmpl = self.cache[t] = file(self.map[t]).read() - return template(tmpl, self.filters, **map) + return template(tmpl, self.filters, **m) def rfc822date(x): - return strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x)) + return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x)) class hgweb: maxchanges = 10 @@ -221,15 +224,10 @@ yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) def header(self): - port = os.environ["SERVER_PORT"] - port = port != "80" and (":" + port) or "" - self.url = "http://%s%s%s" % \ - (os.environ["SERVER_NAME"], port, os.environ["REQUEST_URI"]) - - yield self.t("header", repo = self.reponame, url = self.url) + yield self.t("header") def footer(self): - yield self.t("footer", repo = self.reponame) + yield self.t("footer") def changelog(self, pos): def changenav(): @@ -290,9 +288,6 @@ pos = end - 1 yield self.t('changelog', - header = self.header(), - footer = self.footer(), - repo = self.reponame, changenav = changenav, manifest = hex(mf), rev = pos, changesets = count, entries = changelist) @@ -348,10 +343,7 @@ mf = cl.read(cl.tip())[0] yield self.t('search', - header = self.header(), - footer = self.footer(), query = query, - repo = self.reponame, manifest = hex(mf), entries = changelist) @@ -372,9 +364,6 @@ yield self.diff(p1, n, changes[3]) yield self.t('changeset', - header = self.header(), - footer = self.footer(), - repo = self.reponame, diff = diff, rev = cl.rev(n), node = nodeid, @@ -420,9 +409,6 @@ yield l yield self.t("filelog", - header = self.header(), - footer = self.footer(), - repo = self.reponame, file = f, filenode = filenode, entries = entries) @@ -445,9 +431,6 @@ parity = l & 1) yield self.t("filerevision", file = f, - header = self.header(), - footer = self.footer(), - repo = self.reponame, filenode = node, path = up(f), text = lines(), @@ -508,9 +491,6 @@ line = l) yield self.t("fileannotate", - header = self.header(), - footer = self.footer(), - repo = self.reponame, file = f, filenode = node, annotate = annotate, @@ -568,9 +548,6 @@ parity = 1 - parity yield self.t("manifest", - header = self.header(), - footer = self.footer(), - repo = self.reponame, manifest = mnode, rev = rev, node = hex(node), @@ -595,9 +572,6 @@ parity = 1 - parity yield self.t("tags", - header = self.header(), - footer = self.footer(), - repo = self.reponame, manifest = hex(mf), entries = entries) @@ -612,9 +586,6 @@ yield self.diff(p1, n, file) yield self.t("filediff", - header = self.header(), - footer = self.footer(), - repo = self.reponame, file = file, filenode = hex(mf.get(file, nullid)), node = changeset, @@ -637,7 +608,17 @@ p = os.path.join(self.templates, b) if os.path.isfile(p): m = p - self.t = templater(m, self.filters) + port = os.environ["SERVER_PORT"] + port = port != "80" and (":" + port) or "" + url = "http://%s%s%s" % \ + (os.environ["SERVER_NAME"], port, os.environ["REQUEST_URI"]) + + self.t = templater(m, self.filters, + {"url":url, + "repo":self.reponame, + "header":self.header(), + "footer":self.footer(), + }) if not args.has_key('cmd') or args['cmd'][0] == 'changelog': c = self.repo.changelog.count() - 1
--- a/templates/changelogentry-rss.tmpl Sun Jul 03 20:10:21 2005 -0800 +++ b/templates/changelogentry-rss.tmpl Sun Jul 03 20:21:37 2005 -0800 @@ -1,6 +1,6 @@ <item> <title>#desc|firstline|escape#</title> - <link>http://127.0.0.1:8000/?cmd=changeset;node=#node#"</link> + <link>#url#?cmd=changeset;node=#node#"</link> <description>#desc|escape|addbreaks#</description> <author>#author|obfuscate#</author> <pubDate>#date|rfc822date#</pubDate>
--- a/templates/filelogentry-rss.tmpl Sun Jul 03 20:10:21 2005 -0800 +++ b/templates/filelogentry-rss.tmpl Sun Jul 03 20:21:37 2005 -0800 @@ -1,6 +1,6 @@ <item> <title>#desc|firstline|escape#</title> - <link>http://127.0.0.1:8000/?cmd=file;file=#file#;filenode=#filenode#"</link> + <link>#url#?cmd=file;file=#file#;filenode=#filenode#"</link> <description>#desc|escape|addbreaks#</description> <author>#author|obfuscate#</author> <pubDate>#date|rfc822date#</pubDate>>