-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Lazy load thebe javascript (#41)
- Loading branch information
Showing
8 changed files
with
93 additions
and
73 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
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
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
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 |
---|---|---|
|
@@ -18,7 +18,6 @@ class SphinxBuild: | |
path_html = path_build.joinpath("html") | ||
path_pg_index = path_html.joinpath("index.html") | ||
path_pg_config = path_html.joinpath("configure.html") | ||
path_pg_chglg = path_html.joinpath("changelog.html") | ||
cmd_base = ["sphinx-build", ".", "_build/html", "-a", "-W"] | ||
|
||
def copy(self, path=None): | ||
|
@@ -70,25 +69,23 @@ def test_sphinx_thebe(file_regression, sphinx_build): | |
lb_text = "\n\n".join([ii.prettify() for ii in launch_buttons]) | ||
file_regression.check(lb_text, basename="launch_buttons", extension=".html") | ||
|
||
# Changelog has no thebe button directive, but should have the JS anyway | ||
soup_chlg = BeautifulSoup( | ||
Path(sphinx_build.path_pg_chglg).read_text(), "html.parser" | ||
) | ||
assert "https://unpkg.com/thebe" in soup_chlg.prettify() | ||
|
||
|
||
def test_always_load(file_regression, sphinx_build): | ||
def test_lazy_load(file_regression, sphinx_build): | ||
"""Test building with thebe.""" | ||
sphinx_build.copy() | ||
url = "https://unpkg.com/[email protected]/lib/index.js" # URL to search for | ||
|
||
# Basic build with defaults | ||
sphinx_build.build(cmd=["-D", "thebe_config.always_load=false"]) | ||
# Thebe JS should not be loaded by default (is loaded lazily) | ||
sphinx_build.build() | ||
soup_ix = BeautifulSoup(Path(sphinx_build.path_pg_index).read_text(), "html.parser") | ||
sources = [ii.attrs.get("src") for ii in soup_ix.select("script")] | ||
thebe_source = [ii for ii in sources if ii == url] | ||
assert len(thebe_source) == 0 | ||
|
||
# Thebe should be loaded on a page *with* the directive and not on pages w/o it | ||
# always_load=True should force this script to load on all pages | ||
sphinx_build.build(cmd=["-D", "thebe_config.always_load=true"]) | ||
soup_ix = BeautifulSoup(Path(sphinx_build.path_pg_index).read_text(), "html.parser") | ||
assert "https://unpkg.com/thebe" in soup_ix.prettify() | ||
# Changelog has no thebe button directive, so shouldn't have JS | ||
soup_chlg = BeautifulSoup( | ||
Path(sphinx_build.path_pg_chglg).read_text(), "html.parser" | ||
) | ||
assert "https://unpkg.com/thebe" not in soup_chlg.prettify() | ||
sources = [ii.attrs.get("src") for ii in soup_ix.select("script")] | ||
thebe_source = [ii for ii in sources if ii == url] | ||
assert len(thebe_source) == 1 | ||
|
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