diff mercurial/hgweb/webutil.py @ 10254:8d5de52431f2

hgweb: changenav: separate pages before and after the current position This should allow styles to customize more precisely navigation bar, for example inserting a cursor to show where we are in the navigation bar.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Sat, 16 Jan 2010 02:33:06 +0100
parents 5d49fdef6fd0
children d6512b3e9ac0
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py	Fri Jan 15 21:32:53 2010 +0100
+++ b/mercurial/hgweb/webutil.py	Sat Jan 16 02:33:06 2010 +0100
@@ -32,31 +32,34 @@
         for f in seq(factor * 10):
             yield f
 
-    def nav(**map):
-        l = []
-        last = 0
-        for f in seq(1, pagelen):
-            if f < pagelen or f <= last:
-                continue
-            if f > limit:
-                break
-            last = f
-            if pos + f < limit:
-                l.append(("+%d" % f, hex(nodefunc(pos + f).node())))
-            if pos - f >= 0:
-                l.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
+    navbefore = []
+    navafter = []
 
-        try:
-            yield {"label": "(0)", "node": hex(nodefunc('0').node())}
+    last = 0
+    for f in seq(1, pagelen):
+        if f < pagelen or f <= last:
+            continue
+        if f > limit:
+            break
+        last = f
+        if pos + f < limit:
+            navafter.append(("+%d" % f, hex(nodefunc(pos + f).node())))
+        if pos - f >= 0:
+            navbefore.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
 
+    navafter.append(("tip", "tip"))
+    try:
+        navbefore.insert(0, ("(0)", hex(nodefunc('0').node())))
+    except error.RepoError:
+        pass
+
+    def gen(l):
+        def f(**map):
             for label, node in l:
                 yield {"label": label, "node": node}
+        return f
 
-            yield {"label": "tip", "node": "tip"}
-        except error.RepoError:
-            pass
-
-    return nav
+    return (dict(before=gen(navbefore), after=gen(navafter)), )
 
 def _siblings(siblings=[], hiderev=None):
     siblings = [s for s in siblings if s.node() != nullid]