Skip to content

Commit

Permalink
[BUGFIX] Warn when a directive has not title
Browse files Browse the repository at this point in the history
resolves #983

(cherry picked from commit 08a9c91)
  • Loading branch information
linawolf committed Apr 18, 2024
1 parent 31b0b98 commit f880b29
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
use phpDocumentor\Guides\RestructuredText\Parser\InlineParser;
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Rule;
use phpDocumentor\Guides\RestructuredText\TextRoles\GenericLinkProvider;
use Psr\Log\LoggerInterface;

use function boolval;
use function in_array;
use function trim;

/**
* The confval directive configuration values.
Expand All @@ -41,6 +43,7 @@ public function __construct(
GenericLinkProvider $genericLinkProvider,
private readonly AnchorNormalizer $anchorReducer,
private readonly InlineParser $inlineParser,
private readonly LoggerInterface|null $logger = null,
) {
parent::__construct($startingRule);

Expand Down Expand Up @@ -71,6 +74,12 @@ protected function processSub(
$required = false;
$default = null;
$additionalOptions = [];
if (trim($directive->getData()) === '') {
if ($this->logger !== null) {
$this->logger->warning('A directive must have a title: .. confval:: [some_title]', $blockContext->getLoggerInformation());
}
}

if ($directive->hasOption('type')) {
$type = $this->inlineParser->parse($directive->getOption('type')->toString(), $blockContext);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- content start -->
<div class="section" id="confval-directive">
<h1>Confval directive</h1>
<dl class="confval">
<dt id="confval-">
<code class="sig-name descname"><span class="pre"></span></code></dt>
<dd>
<div class="line-block">
<div class="line"><strong>Type:</strong> <code>&quot;Hello World&quot;</code></div>
<div class="line"><strong>Required:</strong> true</div>
<div class="line"><strong>Custom Info:</strong> <strong>custom</strong></div>

</div>
<div class="confval-description">

<p>This is the confval <code>demo</code> content!</p>

<p>Another paragraph.</p>

</div>
</dd>
</dl>
</div>
<!-- content end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app.WARNING: A directive must have a title
12 changes: 12 additions & 0 deletions tests/Integration/tests/confval/confval-no-title/input/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Confval directive
=================

.. confval::
:type: :php:`string`
:default: ``"Hello World"``
:required: true
:Custom Info: **custom**

This is the confval ``demo`` content!

Another paragraph.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!-- content start -->
<div class="section" id="uml-directive">
<h1>Uml Directive</h1>
<figure
class="uml-diagram"
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
<figure
class="uml-diagram"
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
</div>
<div class="section" id="uml-directive">
<h1>Uml Directive</h1>
<figure
class="uml-diagram"
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
<figure
class="uml-diagram"
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
</div>
<!-- content end -->

0 comments on commit f880b29

Please sign in to comment.