[PATCH] Added array support to hgweb

Jeff Sipek jeffpc at optonline.net
Wed Aug 10 19:09:09 CDT 2005


The following patch adds array support to hgweb templates.

For instance, one can pass the template class a dictionary (it works
with tuples and lists as well) containing elements:

test = {1: 'foo', 'a': 'bar'}

and then, anywhere in the template, he can access either location by
writing:

#test[1]# or #test['a']#

of course you can still use all the filters you are used to:

#test['a']|age# works just as expected.

Jeff Sipek


# HG changeset patch
# User Josef "Jeff" Sipek <jeffpc at optonline.net>
# Node ID 8c00b1316b9f46fab2f7cc8ba35abb2c816e9278
# Parent  6390c377a9e617e01061d33f3729948d72b6f54f
Added array support to template system

diff -r 6390c377a9e6 -r 8c00b1316b9f mercurial/hgweb.py
--- a/mercurial/hgweb.py	Tue Aug  9 17:36:34 2005
+++ b/mercurial/hgweb.py	Thu Aug 11 00:00:55 2005
@@ -66,13 +66,21 @@
 
 def template(tmpl, filters = {}, **map):
     while tmpl:
-        m = re.search(r"#([a-zA-Z0-9]+)((\|[a-zA-Z0-9]+)*)#", tmpl)
+        m = re.search(r"#([a-zA-Z0-9]+)(\[(['a-zA-Z0-9]+)\]){0,1}((\|[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)
+            s = m.group(3)
+            if (s):
+                if (s[0]=="'" and s[-1]=="'"):
+                    s = s[1:-1]
+                else:
+                    s = int(s)
+                v = callable(v) and v(**map)[s] or v[s]
+            else:
+                v = callable(v) and v(**map) or v
+
+            fl = m.group(4)
             if fl:
                 for f in fl.split("|")[1:]:
                     v = filters[f](v)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.selenic.com/pipermail/mercurial/attachments/20050810/e92cd97f/attachment.pgp


More information about the Mercurial mailing list