Skip to content

Commit

Permalink
[TASK] Replace TocNode in automatic-menu node
Browse files Browse the repository at this point in the history
  • Loading branch information
linawolf committed Oct 4, 2024
1 parent ec0dad5 commit a7d9feb
Show file tree
Hide file tree
Showing 13 changed files with 463 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link https://phpdoc.org
*/

namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers;

use phpDocumentor\Guides\Compiler\CompilerContextInterface;
use phpDocumentor\Guides\Compiler\NodeTransformer;
use phpDocumentor\Guides\Nodes\Menu\MenuNode;
use phpDocumentor\Guides\Nodes\Menu\NavMenuNode;
use phpDocumentor\Guides\Nodes\Menu\TocNode;
use phpDocumentor\Guides\Nodes\Node;
use phpDocumentor\Guides\Settings\SettingsManager;
use Psr\Log\LoggerInterface;

/** @implements NodeTransformer<MenuNode> */
final class TocNodeReplacementTransformer implements NodeTransformer
{
public function __construct(
private readonly LoggerInterface $logger,
private readonly SettingsManager $settingsManager,
) {
}

public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node
{
return $node;
}

public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null
{
if (!$node instanceof TocNode) {
return $node;
}

if (!$this->settingsManager->getProjectSettings()->isAutomaticMenu()) {
return $node;
}

if ($node->hasOption('hidden')) {
$this->logger->warning('The `.. toctree::` directive with option `:hidden:` is not supported in automatic-menu mode. ', $compilerContext->getLoggerInformation());

return null;
}

$this->logger->warning('The `.. toctree::` directive is not supported in automatic-menu mode. Use `.. menu::` instead. ', $compilerContext->getLoggerInformation());
$menuNode = new NavMenuNode($node->getMenuEntries());
$menuNode = $menuNode->withOptions($node->getOptions());
$menuNode = $menuNode->withCaption($node->getCaption());

return $menuNode;
}

public function supports(Node $node): bool
{
return $node instanceof TocNode;
}

public function getPriority(): int
{
return 20_000;
}
}
2 changes: 1 addition & 1 deletion packages/guides/src/Compiler/Passes/GlobalMenuPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function run(array $documents, CompilerContextInterface $compilerContext)
try {
$rootDocumentEntry = $projectNode->getRootDocumentEntry();
} catch (Throwable) {
// Todo: Functional tests have not root document entry
// Todo: Functional tests have no root document entry
return $documents;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ <h1>Document Title</h1>

<p>Lorem Ipsum Dolor.</p>


</div>
<!-- content end -->
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<title>Another Page - Bootstrap Theme</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<header class="">

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">

<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">

<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a href="/anotherPage.html" class="nav-link current active" aria-current="page">
Another Page
</a>
</li><li class="nav-item">
<a href="/somePage.html" class="nav-link">
Some Page
</a>
</li><li class="nav-item">
<a href="/yetAnotherPage.html" class="nav-link">
Yet Another Page
</a>
</li></ul>

</div>
</div>
</nav>
</header>
<main id="main-content">
<div class="container">
<div class="container">
<div class="row">
<div class="col-lg-3">
<nav class="nav flex-column">
<ul class="menu-level-main">
<li>
<a href="/anotherPage.html"
class="nav-link current active" aria-current="page">Another Page</a>
</li>
<li>
<a href="/somePage.html"
class="nav-link">Some Page</a>
</li>
<li>
<a href="/yetAnotherPage.html"
class="nav-link">Yet Another Page</a>
</li>
</ul>
</nav>

</div>
<div class="col-lg-9">

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/index.html">Document Title</a></li>
<li class="breadcrumb-item"><a href="/anotherPage.html">Another Page</a></li>
</ol>
</nav>
<!-- content start -->

<div class="section" id="another-page">
<h1>Another Page</h1>

<p>Lorem Ipsum Dolor.</p>

</div>
<!-- content end -->
</div>
</div>
</div>
</div>
</main>
<footer class="bg-primary text-light">
<div class="container">

<p>Generated by <a href="https://www.phpdoc.org/">phpDocumentor</a>.</p>

</div>
</footer>

<!-- Optional JavaScript; choose one of the two! -->

<!-- Option 1: Bootstrap Bundle with Popper -->
<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>

<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<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>
-->
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<title>Document Title - Bootstrap Theme</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<header class="">

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">

<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">

<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a href="/anotherPage.html" class="nav-link">
Another Page
</a>
</li><li class="nav-item">
<a href="/somePage.html" class="nav-link">
Some Page
</a>
</li><li class="nav-item">
<a href="/yetAnotherPage.html" class="nav-link">
Yet Another Page
</a>
</li></ul>

</div>
</div>
</nav>
</header>
<main id="main-content">
<div class="container">
<div class="container">
<div class="row">
<div class="col-lg-3">
<nav class="nav flex-column">
<ul class="menu-level-main">
<li>
<a href="/anotherPage.html"
class="nav-link">Another Page</a>
</li>
<li>
<a href="/somePage.html"
class="nav-link">Some Page</a>
</li>
<li>
<a href="/yetAnotherPage.html"
class="nav-link">Yet Another Page</a>
</li>
</ul>
</nav>

</div>
<div class="col-lg-9">

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/index.html">Document Title</a></li>
</ol>
</nav>
<!-- content start -->

<div class="section" id="document-title">
<h1>Document Title</h1>

<p>Lorem Ipsum Dolor.</p>

<div class="toc">
<li class="toc-item">
<a href="/yetAnotherPage.html#yet-another-page">Yet Another Page</a>


</li>
<li class="toc-item">
<a href="/somePage.html#some-page">Some Page</a>


</li>
<li class="toc-item">
<a href="/anotherPage.html#another-page">Another Page</a>


</li>
</div>

</div>
<!-- content end -->
</div>
</div>
</div>
</div>
</main>
<footer class="bg-primary text-light">
<div class="container">

<p>Generated by <a href="https://www.phpdoc.org/">phpDocumentor</a>.</p>

</div>
</footer>

<!-- Optional JavaScript; choose one of the two! -->

<!-- Option 1: Bootstrap Bundle with Popper -->
<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>

<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<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>
-->
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app.WARNING: The `.. toctree::` directive is not supported in automatic-menu mode. Use `.. menu::` instead.
Loading

0 comments on commit a7d9feb

Please sign in to comment.