Commit 8be17013 authored by Laurent Bachelier's avatar Laurent Bachelier

Add breadcrumbs in the HTML views

The title() def now has a "html" argument, so it can be different when
in the body or in the title tag where no tags are allowed.
Also, the 'path' template variable is now always identical to the 'path'
Context variable.

closes #603
parent c2910454
......@@ -113,7 +113,7 @@ class Context(object):
def _init_template_vars(self):
self.template_vars = {
'ass2m_version': VERSION,
'path': self.path or "/",
'path': self.path,
'url': self.url,
'root_url': self.root_url,
'global': dict(),
......
......@@ -68,6 +68,19 @@ header nav menu li.selected a {
color: black;
}
header nav.breadcrumbs {
display: inline;
}
header nav.breadcrumbs a.last {
color: black;
}
header h1 {
font-weight: normal;
}
footer {
font-size: medium;
font-family: monospace;
......
......@@ -2,4 +2,4 @@
${next.body()}
<%def name="title()">Internal error</%def>
<%def name="title(html=False)">Internal error</%def>
......@@ -73,7 +73,13 @@ event_classes = {
</section>
</article>
<%def name="title()">Event ${path | h}</%def>
<%def name="title(html=False)">
% if html:
Event ${partials.breadcrumbs(path, isdir=False)}
% else:
Event ${path}
% endif
</%def>
<%def name="header()">
${parent.header()}
......
......@@ -7,7 +7,7 @@
% if available_views:
${altrels()}
% endif
<title>${self.title()}</title>
<title>${capture(self.title, html=False).replace('\n', ' ') | trim}</title>
% for stylesheet in stylesheets:
<link rel="stylesheet" type="text/css" href="${root_url.setvar(action='asset', file=stylesheet).href}" />
% endfor
......@@ -36,7 +36,7 @@
</%def>
<%def name="header()">
<h1>${self.title()}</h1>
<h1>${self.title(html=True) | trim}</h1>
</%def>
<%def name="footer()">
......
......@@ -18,7 +18,7 @@
<tr><th>Name</th></tr>
</thead>
<tbody>
% if path != '/':
% if path:
<tr class="parent">
<td class="filename"><a href="../">Parent directory</a></td>
</tr>
......@@ -33,7 +33,13 @@
</section>
</article>
<%def name="title()">Gallery of ${path | h}</%def>
<%def name="title(html=False)">
% if html:
Gallery of ${partials.breadcrumbs(path)}
% else:
Gallery of ${path}/
% endif
</%def>
<%def name="header()">
${parent.header()}
......
......@@ -11,7 +11,7 @@
</tr>
</thead>
<tbody>
% if path != '/':
% if path:
<tr class="parent">
<td class="filename"><a href="../">Parent directory</a></td>
</tr>
......@@ -37,7 +37,13 @@
</table>
</article>
<%def name="title()">Index of ${path | h}</%def>
<%def name="title(html=False)">
% if html:
Index of ${partials.breadcrumbs(path)}
% else:
Index of ${path}/
% endif
</%def>
<%def name="header()">
${parent.header()}
......
......@@ -19,4 +19,4 @@
</section>
</article>
<%def name="title()">Login</%def>
<%def name="title(html=False)">Login</%def>
......@@ -31,3 +31,38 @@ view_links = [(available_view.verbose_name, url.setvar(view=available_view.name)
</%def>
<%def name="display_user(u)"><abbr title="${u.realname | h}">${u.name | h}</abbr></%def>
<%def name="breadcrumbs(path, isdir=True)">
<%
if path == '/':
paths = ['[root]']
else:
paths = path.split('/')
paths[0] = '[root]'
%>
<nav class="breadcrumbs">
% for index, pathpart in enumerate(paths, 1):
<%
classes = []
parturl = '../' * (len(paths)-index)
chr = '/'
%>\
% if index == len(paths):
<%
classes.append('last')
parturl = url.href
if not isdir:
chr = ''
%>\
% endif
% if index == 1:
<%
classes.append('root')
parturl = root_url.href
chr = ':/'
%>\
% endif
<a class="${' '.join(classes)}" href="${parturl}">${pathpart | h}</a>${chr}\
% endfor
</nav>
</%def>
......@@ -23,7 +23,7 @@ class BaseWebTest(TestCase):
def test_listAndDownload(self):
res = self.app.get("/")
assert "<h1>Index of /</h1>" in res.body
assert "<title>Index of /</title>" in res.body
with open(os.path.join(self.root, "penguins_are_cute"), 'w') as f:
f.write("HELLO")
......@@ -96,7 +96,7 @@ class BaseWebTest(TestCase):
res = self.app.get("/penguins/", status=200)
assert "Parent directory" in res.body
res = res.click("Parent directory")
assert "<h1>Index of /</h1>" in res.body
assert "<title>Index of /</title>" in res.body
def test_actionsInRoot(self):
os.mkdir(os.path.join(self.root, 'penguins'))
......
......@@ -41,7 +41,7 @@ class GalleryTest(TestCase):
def test_listAndDefaultView(self):
res = self.app.get('/images/')
assert '<h1>Index of /images</h1>' in res.body
assert '<title>Index of /images/</title>' in res.body
assert '<img' not in res.body
assert 'nothing' in res.body
......@@ -53,7 +53,7 @@ class GalleryTest(TestCase):
res2 = self.app.get('/images/')
for res in (res1, res2):
assert '<h1>Gallery of /images</h1>' in res.body
assert '<title>Gallery of /images/</title>' in res.body
assert '<img' in res.body
assert 'nothing' in res.body
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment