Skip to content

Commit

Permalink
Getting tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
choldgraf committed Apr 17, 2021
1 parent 88305ad commit 3de44de
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 95 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
# "single_page": True,
# "extra_footer": "<a href='https://google.com'>Test</a>", # DEPRECATED KEY
# "extra_navbar": "<a href='https://google.com'>Test</a>",
# "show_navbar_depth": 2,
}

# -- ABlog config -------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions docs/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ using the following configuration in `conf.py`:
show_navbar_depth = <level>
```

The default value is 1, which is used in this documentation.
Value of 0 will collapse all the sections and sub-sections by default.
The default value is `1`, which shows only top-level sections of the documentation (and is used in this documentation).

## Customize CSS

Expand Down
8 changes: 8 additions & 0 deletions sphinx_book_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def sbt_generate_nav_html(
include_item_names=False,
with_home_page=False,
prev_section_numbers=None,
show_depth=1,
):
# Config stuff
config = app.env.config
Expand Down Expand Up @@ -125,6 +126,13 @@ def sbt_generate_nav_html(
)
toctree.insert(0, ul_home("ul")[0])

# Open the navbar to the proper depth
for ii in range(int(show_depth)):
for checkbox in toctree.select(
f"li.toctree-l{ii} > input.toctree-checkbox"
):
checkbox.attrs["checked"] = None

return toctree.prettify()

context["sbt_generate_nav_html"] = sbt_generate_nav_html
Expand Down
2 changes: 1 addition & 1 deletion sphinx_book_theme/_templates/sbt-sidebar-nav.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
{{ sbt_generate_nav_html(include_item_names=True, with_home_page=theme_home_page_in_toc) }}
{{ sbt_generate_nav_html(include_item_names=True, with_home_page=theme_home_page_in_toc, show_depth=theme_show_navbar_depth) }}
</div>
</nav>

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sphinx_book_theme/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
inherit = pydata_sphinx_theme
pygments_style = tango
sidebars = sidebar-logo.html, search-field.html, sbt-sidebar-nav.html, sbt-sidebar-footer.html
stylesheet = sphinx-book-theme.60ee9a98ef899ede750388e4f0bbf03b.css
stylesheet = sphinx-book-theme.d1eca0c74be0ba334ed3837a61090a22.css

[options]
single_page = False
Expand Down
1 change: 1 addition & 0 deletions src/scss/_leftbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ div.navbar-brand-box {
}

nav.bd-links {
margin-left: 0px; // Because the PST adds margin by default
p.caption, .toctree-l1 a {
padding-left: 0em;
}
Expand Down
8 changes: 5 additions & 3 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,17 @@ def test_show_navbar_depth(sphinx_build_factory):
"""Test with different levels of show_navbar_depth."""
sphinx_build = sphinx_build_factory(
"base",
confoverrides={"html_theme_options.show_navbar_depth": 0},
confoverrides={"html_theme_options.show_navbar_depth": 2},
).build(
assert_pass=True
) # type: SphinxBuild
sidebar = sphinx_build.html_tree("section1", "ntbk.html").find_all(
attrs={"class": "bd-sidebar"}
)[0]
collapsed_uls = sidebar.findAll("ul", {"class": "collapse-ul"})
assert len(collapsed_uls) == 3
for checkbox in sidebar.select("li.toctree-l1 > input"):
assert "checked" in checkbox.attrs
for checkbox in sidebar.select("li.toctree-l2 > input"):
assert "checked" not in checkbox.attrs


def test_topbar_download_button_off(sphinx_build_factory, file_regression):
Expand Down
176 changes: 89 additions & 87 deletions tests/test_build/test_build_book.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,93 +12,95 @@ <h1 class="site-logo" id="site-title">
<input aria-label="Search the docs ..." autocomplete="off" class="form-control" id="search-input" name="q" placeholder="Search the docs ..." type="search"/>
</form>
<nav aria-label="Main navigation" class="bd-links" id="bd-docs-nav">
<p class="caption collapsible-parent">
<span class="caption-text">
My caption
</span>
</p>
<ul class="nav sidenav_l1">
<li class="toctree-l1">
<a class="reference internal" href="page1.html">
1. Page 1
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="page2.html">
2. Page 2
</a>
</li>
<li class="toctree-l1 collapsible-parent">
<a class="reference internal" href="section1/index.html">
3. Section 1 index
</a>
<ul class="collapse-ul">
<li class="toctree-l2">
<a class="reference internal" href="section1/page1.html">
3.1. Section 1 page1
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbk.html">
3.2. A test notebook
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbkmd.html">
3.3. Section 1 page1
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbk_octave.html">
3.4. Octave
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbk_julia.html">
3.5. Julia
</a>
</li>
</ul>
<i class="fas fa-chevron-down">
</i>
</li>
<li class="toctree-l1 collapsible-parent">
<a class="reference internal" href="titles/index.html">
4. Testing titles and TOCtree
</a>
<ul class="collapse-ul">
<li class="toctree-l2">
<a class="reference internal" href="titles/page-multipletitles.html">
4.1. A page with multiple top-level titles
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="titles/page-multipletitles.html#another-top-level-title">
4.2. Another top-level title
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="titles/page-onetitle.html">
4.3. A page with one title and sub-headings
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="titles/page-onetitlenoheadings.html">
4.4. A page with a title but no sub-headings
</a>
</li>
</ul>
<i class="fas fa-chevron-down">
</i>
</li>
<li class="toctree-l1">
<a class="reference external" href="https://google.com">
https://google.com
<i class="fas fa-external-link-alt">
</i>
</a>
</li>
</ul>
<div class="bd-toc-item active">
<p class="caption">
<span class="caption-text">
My caption
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="page1.html">
1. Page 1
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="page2.html">
2. Page 2
</a>
</li>
<li class="toctree-l1 has-children">
<a class="reference internal" href="section1/index.html">
3. Section 1 index
</a>
<input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" type="checkbox">
<label for="toctree-checkbox-1">
<i class="fas fa-chevron-down">
</i>
</label>
<ul>
<li class="toctree-l2">
<a class="reference internal" href="section1/page1.html">
3.1. Section 1 page1
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbk.html">
3.2. A test notebook
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbkmd.html">
3.3. Section 1 page1
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbk_octave.html">
3.4. Octave
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbk_julia.html">
3.5. Julia
</a>
</li>
</ul>
</input>
</li>
<li class="toctree-l1 has-children">
<a class="reference internal" href="titles/index.html">
4. Testing titles and TOCtree
</a>
<input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/>
<label for="toctree-checkbox-2">
<i class="fas fa-chevron-down">
</i>
</label>
<ul>
<li class="toctree-l2">
<a class="reference internal" href="titles/page-multipletitles.html">
4.1. A page with multiple top-level titles
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="titles/page-onetitle.html">
4.3. A page with one title and sub-headings
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="titles/page-onetitlenoheadings.html">
4.4. A page with a title but no sub-headings
</a>
</li>
</ul>
</li>
<li class="toctree-l1">
<a class="reference external" href="https://google.com">
https://google.com
</a>
</li>
</ul>
</div>
</nav>
<!-- To handle the deprecated key -->
<div class="navbar_extra_footer">
Expand Down

0 comments on commit 3de44de

Please sign in to comment.