Skip to content

Commit

Permalink
Merge pull request #617 from jaapio/fix/glob-menu
Browse files Browse the repository at this point in the history
Improve menu generation
  • Loading branch information
greg0ire authored Sep 26, 2024
2 parents 2ca4437 + 6908eec commit fc64ef7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
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
{
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;
}
}

0 comments on commit fc64ef7

Please sign in to comment.