fix(ui): section tabs above the breadcrumb, so the Ansible tab strip holds still (#5214)
The tabs were drawn in each page's content block, which base.html renders after the breadcrumb, so on every nested Ansible page the strip moved down a line. base.html now has a section_tabs block above the breadcrumb, and every Ansible page fills it. A guard in test_breadcrumbs.py fails any page that calls a tabs macro outside that block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,3 +53,32 @@ def test_every_nested_page_has_a_trail():
|
||||
missing = sorted(name for name, p in pages.items()
|
||||
if name not in TOP_LEVEL and needs_crumbs_and_lacks_them(p.read_text()))
|
||||
assert not missing, f"add {{% block breadcrumb %}}{{{{ crumbs([...]) }}}} (rule 134): {missing}"
|
||||
|
||||
|
||||
# A section's tabs go in base.html's section_tabs block, above the trail, so the
|
||||
# strip holds still whether or not the page has a breadcrumb (#5214). Drawn in
|
||||
# the content block instead, they sit under the trail and jump down a line on
|
||||
# every nested page.
|
||||
_TABS_BLOCK = re.compile(r"\{%-?\s*block\s+section_tabs\s*-?%\}(.*?)\{%-?\s*endblock", re.S)
|
||||
_TABS_CALL = re.compile(r"\{\{-?\s*\w*_tabs\(")
|
||||
|
||||
|
||||
def tabs_outside_their_block(text: str) -> bool:
|
||||
calls = len(_TABS_CALL.findall(text))
|
||||
inside = sum(len(_TABS_CALL.findall(b)) for b in _TABS_BLOCK.findall(text))
|
||||
return calls > inside
|
||||
|
||||
|
||||
def test_the_tabs_guard_can_fail():
|
||||
assert tabs_outside_their_block('{% block content %}{{ ansible_tabs("runs") }}{% endblock %}')
|
||||
assert not tabs_outside_their_block('{% block section_tabs %}{{ ansible_tabs("runs") }}{% endblock %}')
|
||||
|
||||
|
||||
def test_section_tabs_sit_above_the_trail():
|
||||
base = (REPO / "steward/templates/base.html").read_text()
|
||||
assert base.index("{% block section_tabs %}") < base.index("{% block breadcrumb %}")
|
||||
pages = [p for p in template_files() if _EXTENDS_BASE.search(p.read_text())]
|
||||
tabbed = [p for p in pages if _TABS_CALL.search(p.read_text())]
|
||||
assert len(tabbed) >= 10, [str(p) for p in tabbed] # the ten Ansible pages, at least
|
||||
wrong = sorted(str(p.relative_to(REPO)) for p in tabbed if tabs_outside_their_block(p.read_text()))
|
||||
assert not wrong, f"move the tabs into {{% block section_tabs %}}: {wrong}"
|
||||
|
||||
Reference in New Issue
Block a user