[PATCH 2 of 2] hgwebdir: add a "URL breadcrumb" to the index pages
Angel Ezquerra
angel.ezquerra at gmail.com
Mon Aug 6 19:20:29 UTC 2012
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1343247675 -7200
# Branch stable
# Node ID 92442515d8bc5b7628a2c8f97f35c0b15a20c84f
# Parent 06d3090c691a0607ed1d08d0dfd7c3e850d1d383
hgwebdir: add a "URL breadcrumb" to the index pages
A "URL breadcrumb" is a path where each of the path items can be clicked to go
to the corresponding path page.
This lets you go up the folder hierarchy very quickly. For example, when showing
the list of repositories in http://myserver/myteams/myprojects, the following
"breadcrumb" will be shown:
/myteams/myprojects
Clicking on "myprojects" reloads the page. Clicking on "myteams/" goes up one
folder. Clicking on the leftmost "/" goes to the server root.
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -389,7 +389,34 @@
self.refresh()
self.updatereqenv(req.env)
- return tmpl("index", entries=entries, subdir=subdir,
+ def makebreadcrumb(url, relpath):
+ '''Return a 'URL breadcrumb' list
+
+ A 'URL breadcrumb' is a list of URL-name pairs,
+ corresponding to each of the path items on a URL.
+ This can be used to create path navigation entries.
+ '''
+ breadcrumb = []
+ if not relpath:
+ return breadcrumb
+ pathitems = ['/'] + relpath.split('/')
+ urlel = url
+ for pathel in reversed(pathitems):
+ if breadcrumb and pathel != '/':
+ pathel += '/'
+ breadcrumb.append({'url': urlel, 'name': pathel})
+ urlel = os.path.dirname(urlel)
+ if not urlel:
+ break
+ return reversed(breadcrumb)
+
+ relpath = subdir
+ if relpath and relpath[-1] == '/':
+ relpath = relpath[:-1]
+ url = '/' + relpath
+
+ return tmpl("index", relpath=relpath, entries=entries, subdir=subdir,
+ pathdef=makebreadcrumb(url, relpath),
sortcolumn=sortcolumn, descending=descending,
**dict(sort))
diff --git a/mercurial/templates/coal/map b/mercurial/templates/coal/map
--- a/mercurial/templates/coal/map
+++ b/mercurial/templates/coal/map
@@ -223,3 +223,4 @@
error = ../paper/error.tmpl
urlparameter = '{separator}{name}={value|urlescape}'
hiddenformentry = '<input type="hidden" name="{name}" value="{value|escape}" />'
+breadcrumb = '<a href="{url}">{name}</a>'
diff --git a/mercurial/templates/gitweb/index.tmpl b/mercurial/templates/gitweb/index.tmpl
--- a/mercurial/templates/gitweb/index.tmpl
+++ b/mercurial/templates/gitweb/index.tmpl
@@ -5,7 +5,7 @@
<div class="page_header">
<a href="{logourl}" title="Mercurial" style="float: right;">Mercurial</a>
- Repositories list
+ Repositories list : {pathdef%breadcrumb}
</div>
<table cellspacing="0">
diff --git a/mercurial/templates/gitweb/map b/mercurial/templates/gitweb/map
--- a/mercurial/templates/gitweb/map
+++ b/mercurial/templates/gitweb/map
@@ -300,3 +300,4 @@
index = index.tmpl
urlparameter = '{separator}{name}={value|urlescape}'
hiddenformentry = '<input type="hidden" name="{name}" value="{value|escape}" />'
+breadcrumb = '<a href="{url}">{name}</a>'
diff --git a/mercurial/templates/monoblue/index.tmpl b/mercurial/templates/monoblue/index.tmpl
--- a/mercurial/templates/monoblue/index.tmpl
+++ b/mercurial/templates/monoblue/index.tmpl
@@ -5,7 +5,7 @@
<body>
<div id="container">
<div class="page-header">
- <h1>Mercurial Repositories</h1>
+ <h1>Mercurial Repositories : {pathdef%breadcrumb}</h1>
<ul class="page-nav">
</ul>
</div>
diff --git a/mercurial/templates/monoblue/map b/mercurial/templates/monoblue/map
--- a/mercurial/templates/monoblue/map
+++ b/mercurial/templates/monoblue/map
@@ -258,3 +258,4 @@
urlparameter = '{separator}{name}={value|urlescape}'
hiddenformentry = '<input type="hidden" name="{name}" value="{value|escape}" />'
graph = graph.tmpl
+breadcrumb = '<a href="{url}">{name}</a>'
diff --git a/mercurial/templates/paper/index.tmpl b/mercurial/templates/paper/index.tmpl
--- a/mercurial/templates/paper/index.tmpl
+++ b/mercurial/templates/paper/index.tmpl
@@ -9,7 +9,7 @@
<img src="{staticurl}{logoimg}" width=75 height=90 border=0 alt="mercurial" /></a>
</div>
<div class="main">
-<h2>Mercurial Repositories</h2>
+<h2>Mercurial Repositories : {pathdef%breadcrumb}</h2>
<table class="bigtable">
<tr>
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
--- a/mercurial/templates/paper/map
+++ b/mercurial/templates/paper/map
@@ -222,3 +222,4 @@
error = error.tmpl
urlparameter = '{separator}{name}={value|urlescape}'
hiddenformentry = '<input type="hidden" name="{name}" value="{value|escape}" />'
+breadcrumb = '<a href="{url}">{name}</a>'
diff --git a/mercurial/templates/spartan/index.tmpl b/mercurial/templates/spartan/index.tmpl
--- a/mercurial/templates/spartan/index.tmpl
+++ b/mercurial/templates/spartan/index.tmpl
@@ -3,7 +3,7 @@
</head>
<body>
-<h2>Mercurial Repositories</h2>
+<h2>Mercurial Repositories : {pathdef%breadcrumb}</h2>
<table>
<tr>
diff --git a/mercurial/templates/spartan/map b/mercurial/templates/spartan/map
--- a/mercurial/templates/spartan/map
+++ b/mercurial/templates/spartan/map
@@ -181,3 +181,4 @@
error = error.tmpl
urlparameter = '{separator}{name}={value|urlescape}'
hiddenformentry = '<input type="hidden" name="{name}" value="{value|escape}" />'
+breadcrumb = '<a href="{url}">{name}</a>'
More information about the Mercurial-devel
mailing list