Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve menu generation #617

Merged
merged 1 commit into from
Sep 26, 2024
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"knplabs/github-api": "^3.9",
"monolog/monolog": "^3.7",
"php-http/guzzle7-adapter": "^1.0",
"phpdocumentor/guides": "^1.3",
"phpdocumentor/guides": "^1.4",
"phpdocumentor/guides-restructured-text": "^1.4",
"scrivo/highlight.php": "^9.18",
"symfony/cache": "^6.4",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@
<tag name="phpdoc.guides.noderenderer.html" />
</service>

<service id="Doctrine\Website\Guides\Compiler\GlobMenuFixerTransformer">
<tag name="phpdoc.guides.compiler.nodeTransformers" />
</service>

<service id="Doctrine\Website\Guides\Compiler\SidebarTransformer">
<tag name="phpdoc.guides.compiler.nodeTransformers" />
</service>
Expand Down
2 changes: 1 addition & 1 deletion lib/Docs/RST/RSTCopier.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RSTCopier
:depth: 3
:glob:

*
**
SIDEBAR;

public function __construct(
Expand Down
51 changes: 51 additions & 0 deletions lib/Guides/Compiler/GlobMenuFixerTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Doctrine\Website\Guides\Compiler;

use phpDocumentor\Guides\Compiler\CompilerContext;
use phpDocumentor\Guides\Compiler\NodeTransformer;
use phpDocumentor\Guides\Nodes\Menu\GlobMenuEntryNode;
use phpDocumentor\Guides\Nodes\Node;

/**
* This class will fix the glob menu entries.
*
* The glob menu entries are not correctly added in the docs.
* This transformer will fix the glob menu entries by replacing the '*' with '**'. This add a certain
* risk if the user had the intention to match only documents in the current directory. But this can be solved
* adding a `/` at the beginning of the glob pattern.
*
* @implements NodeTransformer<GlobMenuEntryNode>
*/
final class GlobMenuFixerTransformer implements NodeTransformer
greg0ire marked this conversation as resolved.
Show resolved Hide resolved
{
public function enterNode(Node $node, CompilerContext $compilerContext): Node
{
return $node;
}

public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null
{
if ($node->getUrl() === '*') {
return new GlobMenuEntryNode(
'**',
$node->getLevel(),
);
}

return $node;
}

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

public function getPriority(): int
{
// Before GlobMenuEntryNodeTransformer
return 4001;
}
}
Loading