Skip to content

Commit 0fa44f6

Browse files
committed
[TASK] Replace TocNode in automatic-menu node
1 parent ec0dad5 commit 0fa44f6

File tree

13 files changed

+463
-2
lines changed

13 files changed

+463
-2
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers;
15+
16+
use phpDocumentor\Guides\Compiler\CompilerContextInterface;
17+
use phpDocumentor\Guides\Compiler\NodeTransformer;
18+
use phpDocumentor\Guides\Nodes\Menu\MenuNode;
19+
use phpDocumentor\Guides\Nodes\Menu\NavMenuNode;
20+
use phpDocumentor\Guides\Nodes\Menu\TocNode;
21+
use phpDocumentor\Guides\Nodes\Node;
22+
use phpDocumentor\Guides\Settings\SettingsManager;
23+
use Psr\Log\LoggerInterface;
24+
25+
/** @implements NodeTransformer<MenuNode> */
26+
final class TocNodeReplacementTransformer implements NodeTransformer
27+
{
28+
public function __construct(
29+
private readonly LoggerInterface $logger,
30+
private readonly SettingsManager $settingsManager,
31+
) {
32+
}
33+
34+
public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node
35+
{
36+
return $node;
37+
}
38+
39+
public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null
40+
{
41+
if (!$node instanceof TocNode) {
42+
return $node;
43+
}
44+
45+
if (!$this->settingsManager->getProjectSettings()->isAutomaticMenu()) {
46+
return $node;
47+
}
48+
49+
if ($node->hasOption('hidden')) {
50+
$this->logger->warning('The `.. toctree::` directive with option `:hidden:` is not supported in automatic-menu mode. ', $compilerContext->getLoggerInformation());
51+
52+
return null;
53+
}
54+
55+
$this->logger->warning('The `.. toctree::` directive is not supported in automatic-menu mode. Use `.. menu::` instead. ', $compilerContext->getLoggerInformation());
56+
$menuNode = new NavMenuNode($node->getMenuEntries());
57+
$menuNode = $menuNode->withOptions($node->getOptions());
58+
$menuNode = $menuNode->withCaption($node->getCaption());
59+
60+
return $menuNode;
61+
}
62+
63+
public function supports(Node $node): bool
64+
{
65+
return $node instanceof TocNode;
66+
}
67+
68+
public function getPriority(): int
69+
{
70+
return 20000;
71+
}
72+
}

packages/guides/src/Compiler/Passes/GlobalMenuPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function run(array $documents, CompilerContextInterface $compilerContext)
5757
try {
5858
$rootDocumentEntry = $projectNode->getRootDocumentEntry();
5959
} catch (Throwable) {
60-
// Todo: Functional tests have not root document entry
60+
// Todo: Functional tests have no root document entry
6161
return $documents;
6262
}
6363

tests/Integration/tests-full/automatic_menu/automatic-default-menu/expected/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ <h1>Document Title</h1>
7676

7777
<p>Lorem Ipsum Dolor.</p>
7878

79-
8079
</div>
8180
<!-- content end -->
8281
</div>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<!DOCTYPE html>
2+
<html class="no-js" lang="en">
3+
<head>
4+
<title>Another Page - Bootstrap Theme</title>
5+
<!-- Required meta tags -->
6+
<meta charset="utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
9+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
10+
</head>
11+
<body>
12+
<header class="">
13+
14+
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
15+
<div class="container">
16+
17+
<a class="navbar-brand" href="#">Navbar</a>
18+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
19+
<span class="navbar-toggler-icon"></span>
20+
</button>
21+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
22+
23+
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
24+
<li class="nav-item">
25+
<a href="/anotherPage.html" class="nav-link current active" aria-current="page">
26+
Another Page
27+
</a>
28+
</li><li class="nav-item">
29+
<a href="/somePage.html" class="nav-link">
30+
Some Page
31+
</a>
32+
</li><li class="nav-item">
33+
<a href="/yetAnotherPage.html" class="nav-link">
34+
Yet Another Page
35+
</a>
36+
</li></ul>
37+
38+
</div>
39+
</div>
40+
</nav>
41+
</header>
42+
<main id="main-content">
43+
<div class="container">
44+
<div class="container">
45+
<div class="row">
46+
<div class="col-lg-3">
47+
<nav class="nav flex-column">
48+
<ul class="menu-level-main">
49+
<li>
50+
<a href="/anotherPage.html"
51+
class="nav-link current active" aria-current="page">Another Page</a>
52+
</li>
53+
<li>
54+
<a href="/somePage.html"
55+
class="nav-link">Some Page</a>
56+
</li>
57+
<li>
58+
<a href="/yetAnotherPage.html"
59+
class="nav-link">Yet Another Page</a>
60+
</li>
61+
</ul>
62+
</nav>
63+
64+
</div>
65+
<div class="col-lg-9">
66+
67+
<nav aria-label="breadcrumb">
68+
<ol class="breadcrumb">
69+
<li class="breadcrumb-item"><a href="/index.html">Document Title</a></li>
70+
<li class="breadcrumb-item"><a href="/anotherPage.html">Another Page</a></li>
71+
</ol>
72+
</nav>
73+
<!-- content start -->
74+
75+
<div class="section" id="another-page">
76+
<h1>Another Page</h1>
77+
78+
<p>Lorem Ipsum Dolor.</p>
79+
80+
</div>
81+
<!-- content end -->
82+
</div>
83+
</div>
84+
</div>
85+
</div>
86+
</main>
87+
<footer class="bg-primary text-light">
88+
<div class="container">
89+
90+
<p>Generated by <a href="https://www.phpdoc.org/">phpDocumentor</a>.</p>
91+
92+
</div>
93+
</footer>
94+
95+
<!-- Optional JavaScript; choose one of the two! -->
96+
97+
<!-- Option 1: Bootstrap Bundle with Popper -->
98+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
99+
100+
<!-- Option 2: Separate Popper and Bootstrap JS -->
101+
<!--
102+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
103+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
104+
-->
105+
</body>
106+
</html>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<!DOCTYPE html>
2+
<html class="no-js" lang="en">
3+
<head>
4+
<title>Document Title - Bootstrap Theme</title>
5+
<!-- Required meta tags -->
6+
<meta charset="utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
9+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
10+
</head>
11+
<body>
12+
<header class="">
13+
14+
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
15+
<div class="container">
16+
17+
<a class="navbar-brand" href="#">Navbar</a>
18+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
19+
<span class="navbar-toggler-icon"></span>
20+
</button>
21+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
22+
23+
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
24+
<li class="nav-item">
25+
<a href="/anotherPage.html" class="nav-link">
26+
Another Page
27+
</a>
28+
</li><li class="nav-item">
29+
<a href="/somePage.html" class="nav-link">
30+
Some Page
31+
</a>
32+
</li><li class="nav-item">
33+
<a href="/yetAnotherPage.html" class="nav-link">
34+
Yet Another Page
35+
</a>
36+
</li></ul>
37+
38+
</div>
39+
</div>
40+
</nav>
41+
</header>
42+
<main id="main-content">
43+
<div class="container">
44+
<div class="container">
45+
<div class="row">
46+
<div class="col-lg-3">
47+
<nav class="nav flex-column">
48+
<ul class="menu-level-main">
49+
<li>
50+
<a href="/anotherPage.html"
51+
class="nav-link">Another Page</a>
52+
</li>
53+
<li>
54+
<a href="/somePage.html"
55+
class="nav-link">Some Page</a>
56+
</li>
57+
<li>
58+
<a href="/yetAnotherPage.html"
59+
class="nav-link">Yet Another Page</a>
60+
</li>
61+
</ul>
62+
</nav>
63+
64+
</div>
65+
<div class="col-lg-9">
66+
67+
<nav aria-label="breadcrumb">
68+
<ol class="breadcrumb">
69+
<li class="breadcrumb-item"><a href="/index.html">Document Title</a></li>
70+
</ol>
71+
</nav>
72+
<!-- content start -->
73+
74+
<div class="section" id="document-title">
75+
<h1>Document Title</h1>
76+
77+
<p>Lorem Ipsum Dolor.</p>
78+
79+
<div class="toc">
80+
<li class="toc-item">
81+
<a href="/yetAnotherPage.html#yet-another-page">Yet Another Page</a>
82+
83+
84+
</li>
85+
<li class="toc-item">
86+
<a href="/somePage.html#some-page">Some Page</a>
87+
88+
89+
</li>
90+
<li class="toc-item">
91+
<a href="/anotherPage.html#another-page">Another Page</a>
92+
93+
94+
</li>
95+
</div>
96+
97+
</div>
98+
<!-- content end -->
99+
</div>
100+
</div>
101+
</div>
102+
</div>
103+
</main>
104+
<footer class="bg-primary text-light">
105+
<div class="container">
106+
107+
<p>Generated by <a href="https://www.phpdoc.org/">phpDocumentor</a>.</p>
108+
109+
</div>
110+
</footer>
111+
112+
<!-- Optional JavaScript; choose one of the two! -->
113+
114+
<!-- Option 1: Bootstrap Bundle with Popper -->
115+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
116+
117+
<!-- Option 2: Separate Popper and Bootstrap JS -->
118+
<!--
119+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
120+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
121+
-->
122+
</body>
123+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
app.WARNING: The `.. toctree::` directive is not supported in automatic-menu mode. Use `.. menu::` instead.

0 commit comments

Comments
 (0)