# HG changeset patch # User Vadim Gelfer # Date 1141068789 28800 # Node ID a7e416bf3c1de62ff0ac5b5e8f30b4d1c2d4c67e # Parent e4abeafd6eb107b9120f221d88fbe4eadd574466 improve templating. allow {foo} as well as #foo#. add new functions for changeset authors. diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -67,9 +67,9 @@ class templater(object): tmpl = self.cache[t] = file(self.map[t]).read() return self.template(tmpl, self.filters, **m) - template_re = re.compile(r"#([a-zA-Z_][a-zA-Z0-9_]*)" + template_re = re.compile(r"[#{]([a-zA-Z_][a-zA-Z0-9_]*)" r"((%[a-zA-Z_][a-zA-Z0-9_]*)*)" - r"((\|[a-zA-Z_][a-zA-Z0-9_]*)*)#") + r"((\|[a-zA-Z_][a-zA-Z0-9_]*)*)[#}]") def template(self, tmpl, filters={}, **map): lm = map.copy() @@ -136,18 +136,34 @@ def nl2br(text): def obfuscate(text): return ''.join(['&#%d;' % ord(c) for c in text]) +def domain(author): + f = author.find('@') + if f == -1: return '' + author = author[f+1:] + f = author.find('>') + if f >= 0: author = author[:f] + return author + +def person(author): + f = author.find('<') + if f == -1: return util.shortuser(author) + return author[:f].rstrip() + common_filters = { - "escape": lambda x: cgi.escape(x, True), - "urlescape": urllib.quote, - "strip": lambda x: x.strip(), + "addbreaks": nl2br, "age": age, "date": lambda x: util.datestr(x), - "addbreaks": nl2br, + "escape": lambda x: cgi.escape(x, True), + "firstline": (lambda x: x.splitlines(1)[0]), + "domain": domain, "obfuscate": obfuscate, + "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"), + "person": person, + "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"), "short": (lambda x: x[:12]), - "firstline": (lambda x: x.splitlines(1)[0]), - "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"), - "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"), + "strip": lambda x: x.strip(), + "urlescape": urllib.quote, + "user": util.shortuser, } def templatepath(name=None):