From d5ea00899c8c202a209b4fa0acee31b559a47957 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 16 Feb 2009 00:08:08 +0100 Subject: [PATCH] Change html_collapse_toctree setting to an argument of the toctree() callable. --- CHANGES | 7 +++---- doc/config.rst | 8 -------- doc/templating.rst | 3 ++- sphinx/builders/html.py | 10 +++++----- sphinx/config.py | 1 - 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index 2d4342bcb..80a27910b 100644 --- a/CHANGES +++ b/CHANGES @@ -55,7 +55,9 @@ New features added and ``staticmethod``. - Added a ``toctree`` callable to the templates, and the ability - to include external links in toctrees. + to include external links in toctrees. The 'collapse' keyword argument + indicates whether or not to only display subitems of the current page. + (Defaults to True.) * Configuration: @@ -70,9 +72,6 @@ New features added - The new ``html_show_sourcelink`` config value can be used to switch off the links to the reST sources in the sidebar. - - The new ``html_collapse_toctree`` config value can be used to - "collapse" the generated toctree given to the templates. - - The default value for ``htmlhelp_basename`` is now the project title, cleaned up as a filename. diff --git a/doc/config.rst b/doc/config.rst index efa1fa852..2c9e09d0c 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -515,14 +515,6 @@ that use Sphinx' HTMLWriter class. .. versionadded:: 0.4 -.. confval:: html_collapse_toctree - - If true, the toctree given to the templates as ``toctree`` will be collapsed, - i.e. only the subitems that contain the current page are visible. Default is - ``False``. - - .. versionadded:: 0.6 - .. confval:: htmlhelp_basename Output file base name for HTML help builder. Default is ``'pydoc'``. diff --git a/doc/templating.rst b/doc/templating.rst index 2ee449aa0..bccdd689c 100644 --- a/doc/templating.rst +++ b/doc/templating.rst @@ -364,4 +364,5 @@ are in HTML form), these variables are also available: .. data:: toctree A callable yielding the global TOC tree containing the current page, rendered - as HTML bullet lists. + as HTML bullet lists. If the optional keyword argument ``collapse`` is true, + all TOC entries that are not ancestors of the current page are collapsed. diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 3332aa144..1bbf359f7 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -184,10 +184,6 @@ class StandaloneHTMLBuilder(Builder): self.theme.get_options(self.config.html_theme_options).iteritems()) self.globalcontext.update(self.config.html_context) - def _get_local_toctree(self, docname): - return self.render_partial(self.env.get_toctree_for( - docname, self, self.config.html_collapse_toctree))['fragment'] - def get_doc_context(self, docname, body, metatags): """Collect items for the template context of a page.""" # find out relations @@ -535,6 +531,10 @@ class StandaloneHTMLBuilder(Builder): if self.indexer is not None and title: self.indexer.feed(pagename, title, doctree) + def _get_local_toctree(self, docname, collapse=True): + return self.render_partial(self.env.get_toctree_for( + docname, self, collapse))['fragment'] + # --------- these are overwritten by the serialization builder def get_target_uri(self, docname, typ=None): @@ -554,7 +554,7 @@ class StandaloneHTMLBuilder(Builder): ctx['pathto'] = pathto ctx['hasdoc'] = lambda name: name in self.env.all_docs ctx['customsidebar'] = self.config.html_sidebars.get(pagename) - ctx['toctree'] = lambda: self._get_local_toctree(pagename) + ctx['toctree'] = lambda **kw: self._get_local_toctree(pagename, **kw) ctx.update(addctx) self.app.emit('html-page-context', pagename, templatename, diff --git a/sphinx/config.py b/sphinx/config.py index 474ddc236..d5bb64716 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -72,7 +72,6 @@ class Config(object): html_use_smartypants = (True, False), html_translator_class = (None, False), html_sidebars = ({}, False), - html_collapse_toctree = (False, False), html_additional_pages = ({}, False), html_use_modindex = (True, False), html_add_permalinks = (True, False),