Skip to content

Commit

Permalink
Merge pull request #3380 from phpDocumentor/fix/do-not-show-container…
Browse files Browse the repository at this point in the history
…-elements-in-toc-for-classes

Do not show container section of TOC in classes
  • Loading branch information
mvriel committed Nov 26, 2022
2 parents f806e2d + fe1b26e commit 16af967
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</dl>
{% endif %}

{% if node.interfaces is not empty or node.classes is not empty or node.traits is not empty or node.enums is not empty %}
{% if node is element container and (node.interfaces is not empty or node.classes is not empty or node.traits is not empty or node.enums is not empty) %}
<h3 id="interfaces_class_traits">
Interfaces, Classes, Traits and Enums
<a href="#interfaces_class_traits" class="headerlink"><i class="fas fa-link"></i></a>
Expand Down
41 changes: 36 additions & 5 deletions src/phpDocumentor/Transformer/Writer/Twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
use phpDocumentor\Descriptor\DescriptorAbstract;
use phpDocumentor\Descriptor\DocBlock\DescriptionDescriptor;
use phpDocumentor\Descriptor\EnumDescriptor;
use phpDocumentor\Descriptor\Interfaces\ArgumentInterface;
use phpDocumentor\Descriptor\Interfaces\ClassInterface;
use phpDocumentor\Descriptor\Interfaces\ConstantInterface;
use phpDocumentor\Descriptor\Interfaces\ContainerInterface;
use phpDocumentor\Descriptor\Interfaces\FileInterface;
use phpDocumentor\Descriptor\Interfaces\FunctionInterface;
use phpDocumentor\Descriptor\Interfaces\InterfaceInterface;
use phpDocumentor\Descriptor\Interfaces\MethodInterface;
use phpDocumentor\Descriptor\Interfaces\NamespaceInterface;
use phpDocumentor\Descriptor\Interfaces\PackageInterface;
use phpDocumentor\Descriptor\Interfaces\PropertyInterface;
use phpDocumentor\Descriptor\Interfaces\TraitInterface;
use phpDocumentor\Descriptor\Interfaces\VisibilityInterface;
use phpDocumentor\Descriptor\NamespaceDescriptor;
use phpDocumentor\Descriptor\PackageDescriptor;
Expand All @@ -39,6 +51,7 @@
use Twig\Extension\GlobalsInterface;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\TwigTest;
use Webmozart\Assert\Assert;

use function array_unshift;
Expand Down Expand Up @@ -73,11 +86,8 @@
*/
final class Extension extends AbstractExtension implements ExtensionInterface, GlobalsInterface
{
/** @var LinkRenderer */
private $routeRenderer;

/** @var ConverterInterface */
private $markdownConverter;
private LinkRenderer $routeRenderer;
private ConverterInterface $markdownConverter;

/**
* Registers the structure and transformation with this extension.
Expand Down Expand Up @@ -113,6 +123,27 @@ public function getGlobals(): array
];
}

/**
* @return list<TwigTest>
*/
public function getTests(): array
{
return [
new TwigTest('element container', static fn (Descriptor $el) => $el instanceof ContainerInterface),
new TwigTest('namespace', static fn (Descriptor $el) => $el instanceof NamespaceInterface),
new TwigTest('package', static fn (Descriptor $el) => $el instanceof PackageInterface),
new TwigTest('file', static fn (Descriptor $el) => $el instanceof FileInterface),
new TwigTest('class', static fn (Descriptor $el) => $el instanceof ClassInterface),
new TwigTest('interface', static fn (Descriptor $el) => $el instanceof InterfaceInterface),
new TwigTest('trait', static fn (Descriptor $el) => $el instanceof TraitInterface),
new TwigTest('property', static fn (Descriptor $el) => $el instanceof PropertyInterface),
new TwigTest('method', static fn (Descriptor $el) => $el instanceof MethodInterface),
new TwigTest('argument', static fn (Descriptor $el) => $el instanceof ArgumentInterface),
new TwigTest('function', static fn (Descriptor $el) => $el instanceof FunctionInterface),
new TwigTest('constant', static fn (Descriptor $el) => $el instanceof ConstantInterface),
];
}

/**
* Returns a listing of all functions that this extension adds.
*
Expand Down

0 comments on commit 16af967

Please sign in to comment.