Skip to content

Commit 49a40ee

Browse files
committed
[FEATURE] Add back to list / back to top buttons to confvals
1 parent f454947 commit 49a40ee

File tree

16 files changed

+317
-131
lines changed

16 files changed

+317
-131
lines changed

Documentation-rendertest/Confval/ConfvalTrees.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Properties of CASE
88
==================
99

1010
.. confval-menu::
11+
:name: typoscript-case-properties
12+
:caption: TypoScript Case Properties
1113
:display: table
1214
:type:
1315

packages/typo3-docs-theme/resources/template/body/directive/confval-menu.html.twig

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,35 @@
113113
{% endfor %}
114114
{% endmacro %}
115115

116+
{% macro renderCaption(node) %}
117+
{% if node.caption -%}
118+
<div class="caption">{{ node.caption }}</div>
119+
{%- endif %}
120+
{% endmacro %}
121+
116122
{% import _self as macros %}
117123
{% if node.display=='list' %}
118-
<div class="mb-4">
124+
<div class="mb-4" id="{{ node.anchor }}">
125+
{{ macros.renderCaption(node) }}
119126
<ul>
120127
{% for entry in node.confvals %}
121128
{{ macros.renderConfvalListItem(entry, node) }}
122129
{% endfor %}
123130
</ul>
124131
</div>
125132
{% elseif node.display=='tree' %}
126-
<div class="directory-tree mb-4">
133+
<div class="directory-tree mb-4" id="{{ node.anchor }}">
134+
{{ macros.renderCaption(node) }}
127135
<ul>
128136
{% for entry in node.confvals %}
129137
{{ macros.renderConfvalItem(entry, node) }}
130138
{% endfor %}
131139
</ul>
132140
</div>
133141
{% else %}
134-
<div class="table-responsive confval-table">
135-
<table class="table table-hover">
142+
<div class="table-responsive confval-table" id="{{ node.anchor }}">
143+
<table class="table table-hover caption-top">
144+
{%- if node.caption %}<caption>{{ node.caption }}</caption>{% endif %}
136145
<thead>
137146
<tr>
138147
<th scope="col">Name</th>
@@ -154,4 +163,6 @@
154163
</table>
155164
</div>
156165
{% endif %}
157-
{{ renderNode(node.children) }}
166+
{% for child in node.children %}
167+
{% include "body/directive/confval.html.twig" with {'node': child, 'backAnchor': node.anchor } %}
168+
{% endfor %}

packages/typo3-docs-theme/resources/template/body/directive/confval.html.twig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<dl class="confval">
2-
<dt{% if not node.noindex %} id="{{ node.anchor }}"{% endif -%}>
2+
<dt{% if not node.noindex %} id="{{ node.anchor }}"{% endif %} class="d-flex justify-content-between">
3+
<div class="confval-header">
34
<code class="sig-name descname"><span class="pre">{{ node.plainContent }}</span></code>
45
{% if not node.noindex %}
56
<a class="headerlink" href="#{{ node.anchor }}" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" data-id="{{ node.anchor }}" data-rstCode="{{ getRstCodeForLink(node) }}" title="Reference this configuration value">¶</a>
67
{% else %}
78
<span class="headerNoindex" title="This configuration value cannot be linked directly. Consider to link to the section above."><i class="fa-solid fa-link-slash"></i></span>
89
{% endif -%}
10+
</div>
11+
<div class="confval-back-to-top">
12+
{%- if backAnchor %}
13+
<a href="#{{ backAnchor }}" class="backToList" title="Back to list"><i class="fa-solid fa-angles-up fa-xs"></i></a>
14+
{% else %}
15+
<a href="#" class="backToTop" title="Back to top"><i class="fa-solid fa-arrow-up fa-xs"></i></a>
16+
{%- endif %}
17+
</div>
918
</dt>
1019
<dd>
1120
{% if node.type or node.required or node.default or node.additionalOptions %}

packages/typo3-docs-theme/src/Directives/ConfvalMenuDirective.php

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,72 +22,79 @@
2222
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
2323
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
2424
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Rule;
25+
use phpDocumentor\Guides\RestructuredText\TextRoles\GenericLinkProvider;
2526
use Psr\Log\LoggerInterface;
2627
use T3Docs\Typo3DocsTheme\Nodes\ConfvalMenuNode;
2728

2829
class ConfvalMenuDirective extends SubDirective
2930
{
31+
public const NAME = 'confval-menu';
3032
public function __construct(
3133
Rule $startingRule,
34+
GenericLinkProvider $genericLinkProvider,
3235
private readonly LoggerInterface $logger,
3336
private readonly AnchorNormalizer $anchorReducer,
3437
) {
3538
parent::__construct($startingRule);
39+
$genericLinkProvider->addGenericLink(self::NAME, ConfvalMenuNode::LINK_TYPE, ConfvalMenuNode::LINK_PREFIX);
3640
}
3741
protected function processSub(
3842
BlockContext $blockContext,
3943
CollectionNode $collectionNode,
4044
Directive $directive,
4145
): Node|null {
4246
$originalChildren = $collectionNode->getChildren();
43-
$chilConfvals = [];
47+
$childConfvals = [];
4448
foreach ($originalChildren as $child) {
4549
if ($child instanceof ConfvalNode) {
46-
$chilConfvals[] = $child;
50+
$childConfvals[] = $child;
4751
} else {
4852
$this->logger->warning('A confval-menu may only contain confvals. ', $blockContext->getLoggerInformation());
4953
}
5054
}
5155
$fields = [];
52-
$display = 'list';
53-
$excludeNoindex = false;
54-
$excludeString = '';
56+
$reservedParameterNames = [
57+
'name',
58+
'class',
59+
'caption',
60+
'exclude-noindex',
61+
'exclude',
62+
];
5563
foreach ($directive->getOptions() as $option) {
56-
if ($option->getName() == 'name' || $option->getName() == 'class') {
57-
continue;
58-
}
59-
if ($option->getName() == 'display') {
60-
$display = (string) $option->getValue();
61-
continue;
62-
}
63-
if ($option->getName() == 'exclude-noindex') {
64-
$excludeNoindex = (bool) $option->getValue();
65-
continue;
66-
}
67-
if ($option->getName() == 'exclude') {
68-
$excludeString = (string) $option->getValue();
64+
if (in_array($option->getName(), $reservedParameterNames, true)) {
6965
continue;
7066
}
7167
$fields[] = $option->getName();
7268
}
73-
$exclude = explode(',', $excludeString);
69+
$exclude = explode(',', $directive->getOptionString('exclude'));
7470
$anchorReducer = $this->anchorReducer;
7571
$exclude = array_map(function ($element) use ($anchorReducer) {
7672
return $anchorReducer->reduceAnchor($element);
7773
}, $exclude);
74+
$id = $directive->getOptionString(
75+
'name',
76+
$directive->getOptionString(
77+
'caption',
78+
$blockContext->getDocumentParserContext()->getDocument()->getFilePath()
79+
)
80+
);
81+
$id = $this->anchorReducer->reduceAnchor($id);
7882
return new ConfvalMenuNode(
83+
$id,
7984
$directive->getData(),
8085
$directive->getDataNode() ?? new InlineCompoundNode(),
81-
$chilConfvals,
82-
$chilConfvals,
86+
$childConfvals,
87+
$directive->getOptionString('caption'),
88+
$childConfvals,
8389
$fields,
84-
$display,
85-
$excludeNoindex,
90+
$directive->getOptionString('display', 'list'),
91+
$directive->getOptionBool('exclude-noindex'),
8692
$exclude,
93+
$directive->getOptionBool('noindex'),
8794
);
8895
}
8996
public function getName(): string
9097
{
91-
return 'confval-menu';
98+
return self::NAME;
9299
}
93100
}

packages/typo3-docs-theme/src/Nodes/ConfvalMenuNode.php

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
namespace T3Docs\Typo3DocsTheme\Nodes;
44

55
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
6+
use phpDocumentor\Guides\Nodes\LinkTargetNode;
67
use phpDocumentor\Guides\Nodes\Node;
8+
use phpDocumentor\Guides\Nodes\OptionalLinkTargetsNode;
9+
use phpDocumentor\Guides\Nodes\PrefixedLinkTargetNode;
710
use phpDocumentor\Guides\RestructuredText\Nodes\ConfvalNode;
811
use phpDocumentor\Guides\RestructuredText\Nodes\GeneralDirectiveNode;
912

10-
final class ConfvalMenuNode extends GeneralDirectiveNode
13+
final class ConfvalMenuNode extends GeneralDirectiveNode implements LinkTargetNode, OptionalLinkTargetsNode, PrefixedLinkTargetNode
1114
{
15+
public const LINK_TYPE = 'std:confval-menu';
16+
public const LINK_PREFIX = 'confval-menu-';
1217
/**
1318
* @param list<Node> $value
1419
* @param Node[] $value
@@ -17,18 +22,31 @@ final class ConfvalMenuNode extends GeneralDirectiveNode
1722
* @param string[] $exclude
1823
*/
1924
public function __construct(
25+
private readonly string $id,
2026
protected readonly string $plainContent,
2127
protected readonly InlineCompoundNode $content,
2228
array $value = [],
29+
private readonly string $caption = '',
2330
private array $confvals = [],
2431
private readonly array $fields = [],
2532
private readonly string $display = 'tree',
2633
private readonly bool $excludeNoindex = false,
27-
private readonly array $exclude = []
34+
private readonly array $exclude = [],
35+
private readonly bool $noindex = false,
2836
) {
2937
parent::__construct('confval-menu', $plainContent, $content, $value);
3038
}
3139

40+
public function getId(): string
41+
{
42+
return $this->id;
43+
}
44+
45+
public function getCaption(): string
46+
{
47+
return $this->caption;
48+
}
49+
3250
/**
3351
* @return ConfvalNode[]
3452
*/
@@ -70,4 +88,28 @@ public function getExclude(): array
7088
{
7189
return $this->exclude;
7290
}
91+
92+
public function getLinkType(): string
93+
{
94+
return self::LINK_TYPE;
95+
}
96+
97+
public function getLinkText(): string
98+
{
99+
return $this->caption;
100+
}
101+
102+
public function getPrefix(): string
103+
{
104+
return self::LINK_PREFIX;
105+
}
106+
public function getAnchor(): string
107+
{
108+
return $this->getPrefix() . $this->getId();
109+
}
110+
111+
public function isNoindex(): bool
112+
{
113+
return $this->noindex;
114+
}
73115
}

tests/Integration/tests/confval/confval-basic/expected/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<section class="section" id="confval">
33
<h1>Confval<a class="headerlink" href="#confval" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" title="Reference this headline"></a></h1>
44
<dl class="confval">
5-
<dt id="confval-demo">
5+
<dt id="confval-demo" class="d-flex justify-content-between">
6+
<div class="confval-header">
67
<code class="sig-name descname"><span class="pre">demo</span></code>
78
<a class="headerlink" href="#confval-demo" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" data-id="confval-demo" data-rstCode=":confval:`demo &lt;somemanual:demo&gt;`" title="Reference this configuration value"></a>
8-
</dt>
9+
</div>
10+
<div class="confval-back-to-top"> <a href="#" class="backToTop" title="Back to top"><i class="fa-solid fa-arrow-up fa-xs"></i></a> </div>
11+
</dt>
912
<dd>
1013
<dl class="field-list simple">
1114
<dt class="field-even">Type</dt>

tests/Integration/tests/confval/confval-duplicate-with-name/expected/anotherDomain.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<section class="section" id="confval-in-another-domain">
33
<h1>Confval in another domain<a class="headerlink" href="#confval-in-another-domain" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" title="Reference this headline"></a></h1>
44
<dl class="confval">
5-
<dt id="confval-another-demo">
5+
<dt id="confval-another-demo" class="d-flex justify-content-between">
6+
<div class="confval-header">
67
<code class="sig-name descname"><span class="pre">demo</span></code>
78
<a class="headerlink" href="#confval-another-demo" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" data-id="confval-another-demo" data-rstCode=":confval:`demo &lt;somemanual:another-demo&gt;`" title="Reference this configuration value"></a>
8-
</dt>
9+
</div>
10+
<div class="confval-back-to-top"> <a href="#" class="backToTop" title="Back to top"><i class="fa-solid fa-arrow-up fa-xs"></i></a> </div>
11+
</dt>
912
<dd>
1013
<dl class="field-list simple">
1114
<dt class="field-even">Type</dt>

tests/Integration/tests/confval/confval-duplicate-with-name/expected/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<section class="section" id="confval">
33
<h1>Confval<a class="headerlink" href="#confval" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" title="Reference this headline"></a></h1>
44
<dl class="confval">
5-
<dt id="confval-demo">
5+
<dt id="confval-demo" class="d-flex justify-content-between">
6+
<div class="confval-header">
67
<code class="sig-name descname"><span class="pre">demo</span></code>
78
<a class="headerlink" href="#confval-demo" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" data-id="confval-demo" data-rstCode=":confval:`demo &lt;somemanual:demo&gt;`" title="Reference this configuration value"></a>
8-
</dt>
9+
</div>
10+
<div class="confval-back-to-top"> <a href="#" class="backToTop" title="Back to top"><i class="fa-solid fa-arrow-up fa-xs"></i></a> </div>
11+
</dt>
912
<dd>
1013
<dl class="field-list simple">
1114
<dt class="field-even">Type</dt>

tests/Integration/tests/confval/confval-duplicate/expected/anotherDomain.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<section class="section" id="confval-in-another-domain">
33
<h1>Confval in another domain<a class="headerlink" href="#confval-in-another-domain" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" title="Reference this headline"></a></h1>
44
<dl class="confval">
5-
<dt id="confval-demo">
5+
<dt id="confval-demo" class="d-flex justify-content-between">
6+
<div class="confval-header">
67
<code class="sig-name descname"><span class="pre">demo</span></code>
78
<a class="headerlink" href="#confval-demo" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" data-id="confval-demo" data-rstCode=":confval:`demo &lt;somemanual:demo&gt;`" title="Reference this configuration value"></a>
8-
</dt>
9+
</div>
10+
<div class="confval-back-to-top"> <a href="#" class="backToTop" title="Back to top"><i class="fa-solid fa-arrow-up fa-xs"></i></a> </div>
11+
</dt>
912
<dd>
1013
<dl class="field-list simple">
1114
<dt class="field-even">Type</dt>

tests/Integration/tests/confval/confval-duplicate/expected/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<section class="section" id="confval">
33
<h1>Confval<a class="headerlink" href="#confval" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" title="Reference this headline"></a></h1>
44
<dl class="confval">
5-
<dt id="confval-demo">
5+
<dt id="confval-demo" class="d-flex justify-content-between">
6+
<div class="confval-header">
67
<code class="sig-name descname"><span class="pre">demo</span></code>
78
<a class="headerlink" href="#confval-demo" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" data-id="confval-demo" data-rstCode=":confval:`demo &lt;somemanual:demo&gt;`" title="Reference this configuration value"></a>
8-
</dt>
9+
</div>
10+
<div class="confval-back-to-top"> <a href="#" class="backToTop" title="Back to top"><i class="fa-solid fa-arrow-up fa-xs"></i></a> </div>
11+
</dt>
912
<dd>
1013
<dl class="field-list simple">
1114
<dt class="field-even">Type</dt>

0 commit comments

Comments
 (0)