diff mercurial/hgweb/hgwebdir_mod.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 ca639faa38a2
children 53eca35c3aeb
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -10,7 +10,7 @@ from mercurial import demandimport; dema
 import os, mimetools, cStringIO
 from mercurial.i18n import gettext as _
 from mercurial import ui, hg, util, templater
-from common import get_mtime, staticfile, style_map
+from common import get_mtime, staticfile, style_map, paritygen
 from hgweb_mod import hgweb
 
 # This is a stopgap
@@ -22,6 +22,7 @@ class hgwebdir(object):
         self.parentui = parentui
         self.motd = None
         self.style = None
+        self.stripecount = None
         self.repos_sorted = ('name', False)
         if isinstance(config, (list, tuple)):
             self.repos = cleannames(config)
@@ -41,6 +42,8 @@ class hgwebdir(object):
                     self.motd = cp.get('web', 'motd')
                 if cp.has_option('web', 'style'):
                     self.style = cp.get('web', 'style')
+                if cp.has_option('web', 'stripes'):
+                    self.stripecount = int(cp.get('web', 'stripes'))
             if cp.has_section('paths'):
                 self.repos.extend(cleannames(cp.items('paths')))
             if cp.has_section('collections'):
@@ -97,6 +100,8 @@ class hgwebdir(object):
             style = config('web', 'style', '')
         if req.form.has_key('style'):
             style = req.form['style'][0]
+        if self.stripecount is None:
+            self.stripecount = int(config('web', 'stripes', 1))
         mapfile = style_map(templater.templatepath(), style)
         tmpl = templater.templater(mapfile, templater.common_filters,
                                    defaults={"header": header,
@@ -127,7 +132,7 @@ class hgwebdir(object):
                     separator = ';'
 
             rows = []
-            parity = 0
+            parity = paritygen(self.stripecount)
             for name, path in self.repos:
                 u = ui.ui(parentui=parentui)
                 try:
@@ -165,8 +170,7 @@ class hgwebdir(object):
                 if (not sortcolumn
                     or (sortcolumn, descending) == self.repos_sorted):
                     # fast path for unsorted output
-                    row['parity'] = parity
-                    parity = 1 - parity
+                    row['parity'] = parity.next()
                     yield row
                 else:
                     rows.append((row["%s_sort" % sortcolumn], row))
@@ -175,8 +179,7 @@ class hgwebdir(object):
                 if descending:
                     rows.reverse()
                 for key, row in rows:
-                    row['parity'] = parity
-                    parity = 1 - parity
+                    row['parity'] = parity.next()
                     yield row
 
         try: