The `toctree callable in templates now accepts a titles_only` keyword argument.

This commit is contained in:
Georg Brandl 2010-05-30 13:16:26 +02:00
parent cbcf99f156
commit 35f0b555a4
5 changed files with 16 additions and 6 deletions

View File

@ -107,6 +107,8 @@ Features added
- Added new theme ``scrolls``, created by Armin Ronacher. - Added new theme ``scrolls``, created by Armin Ronacher.
- #193: Added a ``visitedlinkcolor`` theme option to the default - #193: Added a ``visitedlinkcolor`` theme option to the default
theme. theme.
- The ``toctree`` callable in templates now accepts a ``titles_only``
keyword argument.
* Extension API: * Extension API:

View File

@ -384,3 +384,6 @@ are in HTML form), these variables are also available:
* ``maxdepth`` (defaults to the max depth selected in the toctree directive): * ``maxdepth`` (defaults to the max depth selected in the toctree directive):
the maximum depth of the tree; set it to ``-1`` to allow unlimited depth the maximum depth of the tree; set it to ``-1`` to allow unlimited depth
* ``titles_only`` (false by default): if true, put only toplevel document
titles in the tree

View File

@ -637,9 +637,9 @@ class StandaloneHTMLBuilder(Builder):
if self.indexer is not None and title: if self.indexer is not None and title:
self.indexer.feed(pagename, title, doctree) self.indexer.feed(pagename, title, doctree)
def _get_local_toctree(self, docname, collapse=True, maxdepth=0): def _get_local_toctree(self, docname, collapse=True, **kwds):
return self.render_partial(self.env.get_toctree_for( return self.render_partial(self.env.get_toctree_for(
docname, self, collapse))['fragment'] docname, self, collapse, **kwds))['fragment']
def get_outfilename(self, pagename): def get_outfilename(self, pagename):
return path.join(self.outdir, os_path(pagename) + self.out_suffix) return path.join(self.outdir, os_path(pagename) + self.out_suffix)

View File

@ -1033,15 +1033,18 @@ class BuildEnvironment:
node['refuri'] = node['anchorname'] or '#' node['refuri'] = node['anchorname'] or '#'
return toc return toc
def get_toctree_for(self, docname, builder, collapse, maxdepth=0): def get_toctree_for(self, docname, builder, collapse, **kwds):
"""Return the global TOC nodetree.""" """Return the global TOC nodetree."""
doctree = self.get_doctree(self.config.master_doc) doctree = self.get_doctree(self.config.master_doc)
toctrees = [] toctrees = []
if 'includehidden' not in kwds:
kwds['includehidden'] = True
if 'maxdepth' not in kwds:
kwds['maxdepth'] = 0
kwds['collapse'] = collapse
for toctreenode in doctree.traverse(addnodes.toctree): for toctreenode in doctree.traverse(addnodes.toctree):
toctree = self.resolve_toctree(docname, builder, toctreenode, toctree = self.resolve_toctree(docname, builder, toctreenode,
prune=True, collapse=collapse, prune=True, **kwds)
maxdepth=maxdepth,
includehidden=True)
toctrees.append(toctree) toctrees.append(toctree)
if not toctrees: if not toctrees:
return None return None

View File

@ -1,2 +1,4 @@
{# custom sidebar template #} {# custom sidebar template #}
<h4>Custom sidebar</h4> <h4>Custom sidebar</h4>
{{ toctree(titles_only=True, maxdepth=1) }}