Skip to content

Commit 8e146ac

Browse files
authored
Merge pull request #443 from linawolf/menu-2
Create a Document Tree and the Menus from it
2 parents 4cda3ed + 765fab0 commit 8e146ac

File tree

63 files changed

+831
-723
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+831
-723
lines changed

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,20 @@ test-functional: ## Runs functional tests with phpunit/phpunit
3838
test-integration: ## Runs integration tests with phpunit/phpunit
3939
$(PHP_BIN) vendor/bin/phpunit --testsuite=integration
4040

41+
.PHONY: cleanup
42+
cleanup: cleanup-tests cleanup-build cleanup-cache
43+
4144
.PHONY: cleanup-tests
4245
cleanup-tests: ## Cleans up temp directories created by test-integration
43-
$(PHP_BIN) find ./tests -type d -name 'temp' -exec rm -rf {} \;
46+
@find ./tests -type d -name 'temp' -exec sudo rm -rf {} \;
47+
48+
.PHONY: cleanup-build
49+
cleanup-build:
50+
@sudo rm -rf .build
51+
52+
.PHONY: cleanup-cache
53+
cleanup-cache:
54+
@sudo rm -rf .phpunit.cache
4455

4556
.PHONY: test-architecture
4657
test-architecture: vendor ## Runs deptrac to enfore architecural rules

packages/guides-restructured-text/src/RestructuredText/Directives/ToctreeDirective.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace phpDocumentor\Guides\RestructuredText\Directives;
66

7+
use phpDocumentor\Guides\Nodes\Menu\TocNode;
78
use phpDocumentor\Guides\Nodes\Node;
8-
use phpDocumentor\Guides\Nodes\TocNode;
99
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
1010
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1111
use phpDocumentor\Guides\RestructuredText\Toc\ToctreeBuilder;

packages/guides-restructured-text/src/RestructuredText/NodeRenderers/Html/TopicNodeRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
use InvalidArgumentException;
1717
use phpDocumentor\Guides\NodeRenderers\NodeRenderer;
18+
use phpDocumentor\Guides\Nodes\Menu\TocNode;
1819
use phpDocumentor\Guides\Nodes\Node;
19-
use phpDocumentor\Guides\Nodes\TocNode;
2020
use phpDocumentor\Guides\RenderContext;
2121
use phpDocumentor\Guides\RestructuredText\Nodes\TopicNode;
2222
use phpDocumentor\Guides\TemplateRenderer;

packages/guides-restructured-text/src/RestructuredText/Toc/ToctreeBuilder.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,12 @@
66

77
use phpDocumentor\Guides\ParserContext;
88
use phpDocumentor\Guides\RestructuredText\Parser\LinesIterator;
9-
use phpDocumentor\Guides\UrlGeneratorInterface;
109

1110
use function array_filter;
1211
use function array_map;
13-
use function in_array;
14-
use function str_contains;
1512

1613
class ToctreeBuilder
1714
{
18-
public function __construct(private readonly GlobSearcher $globSearcher, private readonly UrlGeneratorInterface $urlGenerator)
19-
{
20-
}
21-
2215
/**
2316
* @param mixed[] $options
2417
*
@@ -32,29 +25,7 @@ public function buildToctreeFiles(
3225
$toctreeFiles = [];
3326

3427
foreach ($this->parseToctreeFiles($lines) as $file) {
35-
if ($this->isGlob($options, $file)) {
36-
$globPattern = $file;
37-
38-
$globFiles = $this->globSearcher
39-
->globSearch($parserContext, $globPattern);
40-
41-
foreach ($globFiles as $globFile) {
42-
// if glob finds a file already explicitly defined
43-
// don't duplicate it in the toctree again
44-
if (in_array($globFile, $toctreeFiles, true)) {
45-
continue;
46-
}
47-
48-
$toctreeFiles[] = $globFile;
49-
}
50-
} else {
51-
$absoluteUrl = $this->urlGenerator->absoluteUrl(
52-
$parserContext->getDirName(),
53-
$file,
54-
);
55-
56-
$toctreeFiles[] = $absoluteUrl;
57-
}
28+
$toctreeFiles[] = $file;
5829
}
5930

6031
return $toctreeFiles;
@@ -68,10 +39,4 @@ private function parseToctreeFiles(LinesIterator $lines): array
6839
static fn (string $file): bool => $file !== '',
6940
);
7041
}
71-
72-
/** @param mixed[] $options */
73-
private function isGlob(array $options, string $file): bool
74-
{
75-
return isset($options['glob']) && str_contains($file, '*');
76-
}
7742
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<div class="level-x">
2-
{% for entry in node.entries -%}
2+
{% for entry in node.menuEntries -%}
3+
{% spaceless %}
34
<a href="{{ renderLink(entry.url) }}"
45
class="nav-link {% if entry.options.active %} active {% endif %}"
56
{% if entry.options.active %} aria-current="page" {% endif %} >
67
{{ renderNode(entry.value.value) }}
78
</a>
9+
{% endspaceless %}
810
{% endfor %}
911
</div>

packages/guides-theme-bootstrap/resources/template/body/menu/mainmenu/table-of-content.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
<nav class="nav flex-column">
3-
{% for entry in node.entries -%}
3+
{% for entry in node.menuEntries -%}
44
<a href="{{ renderLink(entry.url) }}"
55
class="nav-link {% if entry.options.active %} active {% endif %}"
6-
{% if entry.options.active %} aria-current="page" {% endif %} >
6+
{%- if entry.options.active %} aria-current="page" {% endif -%} >
77
{{ renderNode(entry.value.value) }}
88
</a>
99

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<ul class="level-{{ node.level }}">
2-
{% for entry in node.entries -%}
3-
2+
{% for entry in node.menuEntries -%}
3+
{% spaceless %}
44
<li class="nav-item">
55
<a href="{{ renderLink(entry.url) }}"
66
class="nav-link {% if entry.options.active %} active {% endif %}"
77
{% if entry.options.active %} aria-current="page" {% endif %} >
88
{{ renderNode(entry.value.value) }}
99
</a>
1010
</li>
11-
{% endfor %}
11+
{% endspaceless %}
12+
{%- endfor %}
1213
</ul>

packages/guides-theme-bootstrap/resources/template/body/menu/navbar/table-of-content.html.twig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11

22
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
3-
{% for entry in node.entries -%}
3+
{% for entry in node.menuEntries -%}
44
<li class="nav-item">
5-
<a href="{{ renderLink(entry.url) }}"
6-
class="nav-link {% if entry.options.active %} active {% endif %}"
7-
{% if entry.options.active %} aria-current="page" {% endif %} >
5+
<a href="{{ renderLink(entry.url) }}" class="nav-link {% if entry.options.active %} active {% endif %}"
6+
{%- if entry.options.active %} aria-current="page" {% endif %} >
87
{{ renderNode(entry.value.value) }}
98
</a>
109
</li>

packages/guides-theme-bootstrap/resources/template/body/menu/table-of-content.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% include "body/menu/navbar/table-of-content.html.twig" %}
55
{% else %}
66
<div class="toc">
7-
{% for entry in node.entries -%}
7+
{% for entry in node.menuEntries -%}
88
{{ renderNode(entry) }}
99
{% endfor %}
1010
</div>
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
<li class="toc-item"><a href="{{ url }}">{{ renderNode(node.value.value) }}</a>
2-
32
{%- if node.children|length %}
4-
{% include "body/menu/menu-level.html.twig" with {
5-
tocItems:tocItem.children
6-
} %}
3+
<ul class="menu-level-{{ node.level }}">
4+
{% for child in node.children -%}
5+
{{ renderNode(child) }}
6+
{% endfor %}
7+
</ul>
8+
{%- endif -%}
9+
{%- if node.sections|length %}
10+
<ul class="section-level-{{ node.level }}">
11+
{% for subsection in node.sections -%}
12+
{{ renderNode(subsection) }}
13+
{% endfor %}
14+
</ul>
715
{%- endif -%}
816
</li>

0 commit comments

Comments
 (0)