# HG changeset patch # User Josef "Jeff" Sipek # Date 1124331260 18000 # Node ID aedb47764f2902b54eeef6ee2d83dd0cf8795807 # Parent 54b2a42e501e9c2462ec4bb152c13ef8625f40c4 Added support for #foo%bar# syntax This required moving template() into the templater class diff -r 54b2a42e501e -r aedb47764f29 mercurial/hgweb.py --- a/mercurial/hgweb.py Wed Aug 17 17:57:37 2005 -0800 +++ b/mercurial/hgweb.py Wed Aug 17 21:14:20 2005 -0500 @@ -64,25 +64,6 @@ else: sys.stdout.write(str(thing)) -def template(tmpl, filters = {}, **map): - while tmpl: - m = re.search(r"#([a-zA-Z0-9]+)((\|[a-zA-Z0-9]+)*)#", tmpl) - if m: - yield tmpl[:m.start(0)] - v = map.get(m.group(1), "") - v = callable(v) and v(**map) or v - - fl = m.group(2) - if fl: - for f in fl.split("|")[1:]: - v = filters[f](v) - - yield v - tmpl = tmpl[m.end(0):] - else: - yield tmpl - return - class templater: def __init__(self, mapfile, filters = {}, defaults = {}): self.cache = {} @@ -109,7 +90,37 @@ tmpl = self.cache[t] except KeyError: tmpl = self.cache[t] = file(self.map[t]).read() - return template(tmpl, self.filters, **m) + return self.template(tmpl, self.filters, **m) + + def template(self, tmpl, filters = {}, **map): + while tmpl: + m = re.search(r"#([a-zA-Z0-9]+)((%[a-zA-Z0-9]+)*)((\|[a-zA-Z0-9]+)*)#", tmpl) + if m: + yield tmpl[:m.start(0)] + v = map.get(m.group(1), "") + v = callable(v) and v(**map) or v + + format = m.group(2) + fl = m.group(4) + + if format: + q = v.__iter__ + for i in q(): + lm = map.copy() + lm.update(i) + yield self(format[1:], **lm) + + v = "" + + elif fl: + for f in fl.split("|")[1:]: + v = filters[f](v) + + yield v + tmpl = tmpl[m.end(0):] + else: + yield tmpl + return def rfc822date(x): return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x)) @@ -560,10 +571,9 @@ def entries(**map): parity = 0 for k,n in i: - yield self.t("tagentry", - parity = parity, - tag = k, - node = hex(n)) + yield {"parity": parity, + "tag": k, + "node": hex(n)} parity = 1 - parity yield self.t("tags", diff -r 54b2a42e501e -r aedb47764f29 templates/tags.tmpl --- a/templates/tags.tmpl Wed Aug 17 17:57:37 2005 -0800 +++ b/templates/tags.tmpl Wed Aug 17 21:14:20 2005 -0500 @@ -11,7 +11,7 @@

tags:

#footer#