-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sticky sync tabs and URL param
Add a Sphinx configuration option that is named `sphinx_design_sync_tabs_storage_key` so that users can set a project-specific local storage key rather than risk clobbering the value for `sphinx-design-last-tab` across different projects. Add support for an optional URL search param of like `?tab=blah` or `?code=blah` so that I can copy and paste a URL and the receiver sees the tab content that I see. By default, no param and you get to add "Oh, and click blah" in your message. If the URL has search param `?tab=blah`, set the local storage value to `blah`. If `blah` matches a synchronization key for a tab, show the tab. When someone clicks a tab, set the local storage value to the synchronization key value and also update the URL search params with `?tab=<value>` if the project configures a URL param.
- Loading branch information
1 parent
6df4751
commit c8c0fd6
Showing
4 changed files
with
126 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Test extension configuration options.""" | ||
from pathlib import Path | ||
from typing import Callable | ||
|
||
from .conftest import SphinxBuilder | ||
|
||
|
||
def test_tabs_opts_default_values(sphinx_builder: Callable[..., SphinxBuilder]): | ||
"""Test the sphinx_design_sync_tabs_xxx options default values.""" | ||
builder = sphinx_builder() | ||
assert "sphinx_design_sync_tabs_storage_key" in builder.app.env.config | ||
assert "sphinx_design_sync_tabs_url_param" in builder.app.env.config | ||
assert ( | ||
builder.app.env.config.sphinx_design_sync_tabs_storage_key | ||
== "sphinx-design-last-tab" | ||
) | ||
assert builder.app.env.config.sphinx_design_sync_tabs_url_param is None | ||
content = "Heading\n-------\n\ncontent" | ||
builder.src_path.joinpath("index.rst").write_text(content, encoding="utf8") | ||
builder.build() | ||
design_tabs_js = Path(builder.out_path) / "_static" / "design-tabs.js" | ||
with design_tabs_js.open() as f: | ||
lines = f.read() | ||
assert "sphinx-design-last-tab" in lines | ||
|
||
|
||
def test_tabs_storage_key_set(sphinx_builder: Callable[..., SphinxBuilder]): | ||
"""Test the sphinx_design_sync_tabs_storage_key option.""" | ||
builder = sphinx_builder( | ||
conf_kwargs={ | ||
"extensions": ["myst_parser", "sphinx_design"], | ||
"myst_enable_extensions": ["colon_fence"], | ||
"sphinx_design_sync_tabs_storage_key": "spam-42", | ||
"sphinx_design_sync_tabs_url_param": "bag_of_ham", | ||
} | ||
) | ||
assert "sphinx_design_sync_tabs_storage_key" in builder.app.env.config | ||
assert builder.app.env.config.sphinx_design_sync_tabs_storage_key == "spam-42" | ||
content = "Heading\n-------\n\ncontent" | ||
builder.src_path.joinpath("index.rst").write_text(content, encoding="utf8") | ||
builder.build() | ||
design_tabs_js = Path(builder.out_path) / "_static" / "design-tabs.js" | ||
with design_tabs_js.open() as f: | ||
lines = f.read() | ||
assert "spam-42" in lines | ||
assert "bag_of_ham" in lines | ||
assert "sphinx-design-last-tab" not in lines |