[Python-checkins] r64336 - in doctools/trunk/sphinx: builder.py templates/layout.html

georg.brandl python-checkins at python.org
Tue Jun 17 12:34:51 CEST 2008


Author: georg.brandl
Date: Tue Jun 17 12:34:51 2008
New Revision: 64336

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


Modified:
   doctools/trunk/sphinx/builder.py
   doctools/trunk/sphinx/templates/layout.html

Modified: doctools/trunk/sphinx/builder.py
==============================================================================
--- doctools/trunk/sphinx/builder.py	(original)
+++ doctools/trunk/sphinx/builder.py	Tue Jun 17 12:34:51 2008
@@ -358,6 +358,12 @@
 
         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,
@@ -365,12 +371,11 @@
             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,
@@ -383,21 +388,24 @@
         # 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(
@@ -427,6 +435,7 @@
             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

Modified: doctools/trunk/sphinx/templates/layout.html
==============================================================================
--- doctools/trunk/sphinx/templates/layout.html	(original)
+++ doctools/trunk/sphinx/templates/layout.html	Tue Jun 17 12:34:51 2008
@@ -8,22 +8,12 @@
     <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 %}


More information about the Python-checkins mailing list