Output each accesskey only once, regardless of the number of relbars.

This commit is contained in:
Georg Brandl 2009-02-24 23:38:12 +01:00
parent d31f68be58
commit af102a2579
2 changed files with 12 additions and 2 deletions

View File

@ -26,6 +26,15 @@ def _tobool(val):
return val.lower() in ('true', '1', 'yes', 'on') return val.lower() in ('true', '1', 'yes', 'on')
return bool(val) return bool(val)
def accesskey(context, key):
"""Helper to output each access key only once."""
if '_accesskeys' not in context:
context.vars['_accesskeys'] = {}
if key not in context.vars['_accesskeys']:
context.vars['_accesskeys'][key] = 1
return 'accesskey="%s"' % key
return ''
class BuiltinTemplateLoader(TemplateBridge, BaseLoader): class BuiltinTemplateLoader(TemplateBridge, BaseLoader):
""" """
@ -64,6 +73,7 @@ class BuiltinTemplateLoader(TemplateBridge, BaseLoader):
extensions=extensions) extensions=extensions)
self.environment.filters['tobool'] = _tobool self.environment.filters['tobool'] = _tobool
self.environment.globals['debug'] = contextfunction(pformat) self.environment.globals['debug'] = contextfunction(pformat)
self.environment.globals['accesskey'] = contextfunction(accesskey)
if use_i18n: if use_i18n:
self.environment.install_gettext_translations(builder.translator) self.environment.install_gettext_translations(builder.translator)

View File

@ -12,14 +12,14 @@
{%- for rellink in rellinks %} {%- for rellink in rellinks %}
<li class="right" {% if loop.first %}style="margin-right: 10px"{% endif %}> <li class="right" {% if loop.first %}style="margin-right: 10px"{% endif %}>
<a href="{{ pathto(rellink[0]) }}" title="{{ rellink[1]|striptags }}" <a href="{{ pathto(rellink[0]) }}" title="{{ rellink[1]|striptags }}"
accesskey="{{ rellink[2] }}">{{ rellink[3] }}</a> {{ accesskey(rellink[2]) }}>{{ rellink[3] }}</a>
{%- if not loop.first %}{{ reldelim2 }}{% endif %}</li> {%- if not loop.first %}{{ reldelim2 }}{% endif %}</li>
{%- endfor %} {%- endfor %}
{%- block rootrellink %} {%- block rootrellink %}
<li><a href="{{ pathto(master_doc) }}">{{ shorttitle|e }}</a>{{ reldelim1 }}</li> <li><a href="{{ pathto(master_doc) }}">{{ shorttitle|e }}</a>{{ reldelim1 }}</li>
{%- endblock %} {%- endblock %}
{%- for parent in parents %} {%- for parent in parents %}
<li><a href="{{ parent.link|e }}" accesskey="U">{{ parent.title }}</a>{{ reldelim1 }}</li> <li><a href="{{ parent.link|e }}" {% if loop.last %}{{ accesskey("U") }}{% endif %}>{{ parent.title }}</a>{{ reldelim1 }}</li>
{%- endfor %} {%- endfor %}
{%- block relbaritems %} {% endblock %} {%- block relbaritems %} {% endblock %}
</ul> </ul>