Skip to content

Commit

Permalink
Improve menu generation
Browse files Browse the repository at this point in the history
So the origin of the menu's not working is in the way the menu's are defined. The doctrine parser did use * as a deep search wildcard which is not according to the behavior sphinx does it. As the toctree is a directive defined by sphinx we try to follow that one closely. The correct way of writing a toctree is

```
.. toctree::
   :glob:

   **
```

This will include all documents and sections in a project. starting at the level of the current page.
  • Loading branch information
jaapio committed Sep 25, 2024
1 parent 2ca4437 commit 6908eec
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 6908eec

Please sign in to comment.