Commits

Anonymous committed b832c2d

Compile the right-aligned rellinks into a list that is iterated
over at template rendering time.

Comments (0)

Files changed (2)

sphinx/builder.py

 
         self.relations = self.env.collect_relations()
 
+        rellinks = []
+        if self.config.html_use_index:
+            rellinks.append(('genindex', 'General Index', 'I', 'index'))
+        if self.config.html_use_modindex:
+            rellinks.append(('modindex', 'Global Module Index', 'M', 'modules'))
+
         self.globalcontext = dict(
             project = self.config.project,
             release = self.config.release,
             last_updated = self.last_updated,
             copyright = self.config.copyright,
             style = self.config.html_style,
-            use_modindex = self.config.html_use_modindex,
-            use_index = self.config.html_use_index,
             use_opensearch = self.config.html_use_opensearch,
             docstitle = self.config.html_title,
             shorttitle = self.config.html_short_title,
             show_sphinx = self.config.html_show_sphinx,
+            rellinks = rellinks,
             builder = self.name,
             parents = [],
             logo = logo,
         # find out relations
         prev = next = None
         parents = []
+        rellinks = self.globalcontext['rellinks'][:]
         related = self.relations.get(docname)
         titles = self.env.titles
+        if related and related[2]:
+            try:
+                next = {'link': self.get_relative_uri(docname, related[2]),
+                        'title': self.render_partial(titles[related[2]])['title']}
+                rellinks.append((related[2], next['title'], 'N', 'next'))
+            except KeyError:
+                next = None
         if related and related[1]:
             try:
                 prev = {'link': self.get_relative_uri(docname, related[1]),
                         'title': self.render_partial(titles[related[1]])['title']}
+                rellinks.append((related[1], prev['title'], 'P', 'previous'))
             except KeyError:
                 # the relation is (somehow) not in the TOC tree, handle that gracefully
                 prev = None
-        if related and related[2]:
-            try:
-                next = {'link': self.get_relative_uri(docname, related[2]),
-                        'title': self.render_partial(titles[related[2]])['title']}
-            except KeyError:
-                next = None
         while related and related[0]:
             try:
                 parents.append(
             title = title,
             meta = meta,
             body = body,
+            rellinks = rellinks,
             sourcename = sourcename,
             toc = self.render_partial(self.env.get_toc_for(docname))['fragment'],
             # only display a TOC if there's more than one item to show

sphinx/templates/layout.html

     <div class="related">
       <h3>Navigation</h3>
       <ul>
-        {%- if use_index %}
-        <li class="right" style="margin-right: 10px"><a href="{{ pathto('genindex') }}" title="General Index" accesskey="I">index</a></li>
-        {%- endif %}
-        {%- if use_modindex %}
-        <li class="right"><a href="{{ pathto('modindex') }}" title="Global Module Index" accesskey="M">modules</a>{{ reldelim2 }}</li>
-        {%- endif %}
-        {%- if next %}
-          <li class="right"><a href="{{ next.link|e }}" title="{{ next.title|striptags }}" accesskey="N">next</a>{{ reldelim2 }}</li>
-        {%- endif %}
-        {%- if prev %}
-          <li class="right"><a href="{{ prev.link|e }}" title="{{ prev.title|striptags }}" accesskey="P">previous</a>{{ reldelim2 }}</li>
-        {%- endif %}
-        {%- if builder == 'web' %}
-          <li class="right"><a href="{{ pathto('settings') }}"
-                               title="Customize your viewing settings" accesskey="S">settings</a> |</li>
-        {%- endif %}
+        {%- for rellink in rellinks %}
+        <li class="right" {% if loop.first %}style="margin-right: 10px"{% endif %}>
+          <a href="{{ pathto(rellink[0]) }}" title="{{ rellink[1]|striptags }}"
+             accesskey="{{ rellink[2] }}">{{ rellink[3] }}</a>
+          {%- if not loop.first %}{{ reldelim2 }}{% endif %}</li>
+        {%- endfor %}
         {%- block rootrellink %}
         <li><a href="{{ pathto('index') }}">{{ shorttitle }}</a>{{ reldelim1 }}</li>
         {%- endblock %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.