-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
137 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from functools import partial | ||
|
||
from docutils import nodes | ||
from sphinx import addnodes | ||
from sphinx.builders.html import StandaloneHTMLBuilder | ||
|
||
|
||
MAXDEPTH_DEFAULT = 2 | ||
|
||
|
||
def patch_builder(app): | ||
if isinstance(app.builder, StandaloneHTMLBuilder): | ||
app.builder._get_local_toctree = partial(get_local_toctree, app.builder) | ||
|
||
|
||
def get_local_toctree(self, docname, collapse=True, **kwds): | ||
""" | ||
A patched version of `StandaloneHTMLBuilder._get_local_toctree` | ||
that calls the modified `get_toctree_for` function. | ||
""" | ||
kwds.setdefault('includehidden', False) | ||
toctree = get_toctree_for(self.env, docname, self, collapse, **kwds) | ||
return self.render_partial(toctree)['fragment'] | ||
|
||
|
||
def get_toctree_for(env, docname, builder, collapse, **kwds): | ||
""" | ||
A wrapper for `environment.get_toctree_for` that shifts the resultant toctree up one level. | ||
""" | ||
toctree = env.get_toctree_for(docname, builder, False, **kwds) | ||
newtree = addnodes.compact_paragraph() | ||
newtree['toctree'] = True | ||
|
||
maxdepth = env.config.nav_maxdepth | ||
try: | ||
maxdepth.setdefault('default', MAXDEPTH_DEFAULT) | ||
except AttributeError: | ||
maxdepth = {'default': maxdepth} | ||
|
||
for top_level_list in toctree: | ||
assert isinstance(top_level_list, nodes.bullet_list) | ||
for top_level_item in top_level_list.children: | ||
assert len(top_level_item) == 2 | ||
title_node = top_level_item[0][0][0] # compact_paragraph -> reference -> Text | ||
list_node = top_level_item[1] | ||
env._toctree_prune(node = list_node, | ||
depth = 2, | ||
maxdepth = maxdepth.get(title_node.astext(), maxdepth['default']), | ||
collapse = collapse) | ||
newtree += nodes.caption(title_node.astext(), '', title_node) | ||
newtree += list_node | ||
toctree_update_classes(newtree) | ||
return newtree | ||
|
||
|
||
def toctree_update_classes(toctree, depth=1): | ||
"""Update 'toctree-l%d' classes to match new structure.""" | ||
for node in toctree.children: | ||
if isinstance(node, (addnodes.compact_paragraph, nodes.list_item)): | ||
for idx, class_ in enumerate(node['classes']): | ||
if class_.startswith('toctree-l'): | ||
node['classes'][idx] = 'toctree-l%d' % (depth - 1) | ||
toctree_update_classes(node, depth) | ||
elif isinstance(node, nodes.bullet_list): | ||
toctree_update_classes(node, depth + 1) | ||
|
||
|
||
def setup(app): | ||
app.connect('builder-inited', patch_builder) | ||
app.add_config_value('nav_maxdepth', {}, '') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
============= | ||
API Reference | ||
============= | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
schematics.models <models> | ||
schematics.validation <validation> | ||
schematics.transforms <transforms> | ||
schematics.types <types> | ||
schematics.contrib <contrib> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
====== | ||
Basics | ||
====== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
Overview <../index> | ||
install | ||
quickstart | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
=========== | ||
Development | ||
=========== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
development | ||
community | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
======== | ||
Contents | ||
======== | ||
|
||
.. toctree:: | ||
|
||
basics/index | ||
usage/index | ||
api/index | ||
development/index | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
============ | ||
User's Guide | ||
============ | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
types | ||
models | ||
exporting | ||
importing | ||
validation |