diff mercurial/hgweb/common.py @ 4461:12e4d9524951

hgweb: use generator to count parity of horizontal stripes for easier reading. - use web.stripes in all places and consistently - start with parity0 for lists generated in reverse (e.g. changelog)
author Thomas Arendsen Hein <thomas@intevation.de>
date Tue, 29 May 2007 16:42:05 +0200
parents 5ae460b1f6f0
children
line wrap: on
line diff
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -60,3 +60,19 @@ def style_map(templatepath, style):
             return mapfile
     raise RuntimeError("No hgweb templates found in %r" % templatepath)
 
+def paritygen(stripecount, offset=0):
+    """count parity of horizontal stripes for easier reading"""
+    if stripecount and offset:
+        # account for offset, e.g. due to building the list in reverse
+        count = (stripecount + offset) % stripecount
+        parity = (stripecount + offset) / stripecount & 1
+    else:
+        count = 0
+        parity = 0
+    while True:
+        yield parity
+        count += 1
+        if stripecount and count >= stripecount:
+            parity = 1 - parity
+            count = 0
+