Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/src/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ This page renders theme-native directives and commonly used Sphinx content with

### Steps

The `steps` directive turns its child headings into a numbered walkthrough.
The `fuma-steps` directive turns its child headings into a numbered walkthrough.
If your project uses Sphinx Design 0.8 or later, rename existing heading-based `steps` blocks to `fuma-steps`. Fuma still accepts `steps` when no other extension registers that name.

::::\{steps}
```{fuma-steps}

### Install the package

Expand All @@ -23,10 +24,10 @@ Set `html_theme = "fuma"` in `conf.py`.
### Build the site

Run the normal Sphinx HTML builder.
::::
```

````markdown
```{steps}
```{fuma-steps}
### Install the package

Add sphinx-fuma to the documentation environment.
Expand Down
17 changes: 12 additions & 5 deletions sphinx_fuma/_steps.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""The ``steps`` directive.
"""The ``fuma-steps`` directive.

fumadocs renders numbered walkthroughs as a rail of circled step numbers. There
is no Sphinx equivalent, so a thin container directive marks the region and the
stylesheet draws the rail from the headings inside it.
The stylesheet draws a rail of circled step numbers from the headings inside
the container.
"""

from docutils import nodes
from docutils.parsers.rst import Directive
from sphinx.util.docutils import is_directive_registered

__all__ = ("setup_steps",)

Expand All @@ -24,5 +24,12 @@ def run(self):
return [container]


def _register_steps_alias(app) -> None:
if not is_directive_registered("steps"):
app.add_directive("steps", StepsDirective)


def setup_steps(app) -> None:
app.add_directive("steps", StepsDirective)
app.add_directive("fuma-steps", StepsDirective)
# Wait for all extensions and the HTML theme to register their directives.
app.connect("builder-inited", _register_steps_alias)
47 changes: 47 additions & 0 deletions sphinx_fuma/tests/test_theme.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
import subprocess
import sys
from pathlib import Path

import pytest
Expand Down Expand Up @@ -353,6 +355,51 @@ def test_step_bodies_are_preserved(self, built):
steps = html.split('class="fd-steps', 1)[1].split("</div>", 1)[0]
assert "Pull it down" in steps

@pytest.mark.parametrize(
"extensions",
[
["sphinx_design", "sphinx_fuma"],
["sphinx_fuma", "sphinx_design"],
["sphinx_design"],
],
)
def test_fuma_steps_and_sphinx_design_steps_render_together(self, tmp_path, extensions):
pytest.importorskip("sphinx_design.steps")
(tmp_path / "conf.py").write_text(f"extensions = {extensions!r}\nhtml_theme = 'fuma'\n")
(tmp_path / "index.rst").write_text(
"""Steps
=====

.. fuma-steps::

.. rubric:: Install Fuma

Install the theme.

.. steps::
:start: 3

.. step:: Install Sphinx Design

Install the extension.
"""
)
out = tmp_path / "_build"
result = subprocess.run(
[sys.executable, "-m", "sphinx", "-W", "-b", "html", str(tmp_path), str(out)],
check=False,
capture_output=True,
text=True,
)
assert result.returncode == 0, result.stderr
html = (out / "index.html").read_text()
assert 'class="fd-steps' in html
design_steps = re.search(r"<ol\b[^>]*\bsd-steps\b[^>]*>", html)
assert design_steps is not None
assert 'start="3"' in design_steps[0]
assert "Install the theme." in html
assert "Install the extension." in html


class TestFiles:
def test_directive_builds_a_tree(self, built):
Expand Down