Skip to content

Commit

Permalink
Fix #140: Added support for multiple "since" tags
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev authored Dec 8, 2021
1 parent d7acf3e commit 43add9d
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Yii Framework 2 apidoc extension Change Log
- Enh #196: Added support for PHPDoc inline links (arogachev)
- Enh #147: Added feature of viewing method source code without external links (arogachev)
- Bug #168: Fixed handling of inheritance (arogachev)
- Enh #140: Added support for multiple "since" tags (arogachev)
- Bug #240: Fixed a bug when a "virtual" / "magic" property's full description was displayed instead of preview in
properties list (arogachev)
- Bug #239: Do not show a "virtual" / "magic" methods's full description if it matches short description (arogachev)
Expand Down
19 changes: 17 additions & 2 deletions models/BaseDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ class BaseDoc extends BaseObject
public $endLine;
public $shortDescription;
public $description;
/**
* @var string|null Available since this version.
*/
public $since;
/**
* @var array A mapping where keys are versions and values are descriptions.
*/
public $sinceMap = [];
public $deprecatedSince;
public $deprecatedReason;
/**
Expand Down Expand Up @@ -183,11 +190,19 @@ public function __construct($reflector = null, $context = null, $config = [])
$this->tags = $docBlock->getTags();
foreach ($this->tags as $i => $tag) {
if ($tag instanceof Since) {
$this->since = $tag->getVersion();
$description = (string) $tag->getDescription();
if (!$this->since && !$this->sinceMap && !$description) {
$this->since = $tag->getVersion();
}

if ($description) {
$this->sinceMap[$tag->getVersion()] = $description;
}

unset($this->tags[$i]);
} elseif ($tag instanceof Deprecated) {
$this->deprecatedSince = $tag->getVersion();
$this->deprecatedReason = $tag->getDescription();
$this->deprecatedReason = (string) $tag->getDescription();
unset($this->tags[$i]);
} elseif ($tag->getName() === 'todo') {
$this->todos[] = $tag;
Expand Down
6 changes: 6 additions & 0 deletions templates/bootstrap/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ tr.deprecated th {
background: lightpink;
}

/* Changelog */

.changelog {
border: 1px solid #ddd !important;
}

/* Todos */

.todo {
Expand Down
25 changes: 25 additions & 0 deletions templates/html/views/changelog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use yii\apidoc\models\BaseDoc;

/* @var $doc BaseDoc */
?>

<?php if ($doc->sinceMap) { ?>
<table class="changelog table table-bordered">
<thead>
<tr>
<th scope="col">Version</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<?php foreach ($doc->sinceMap as $version => $description) { ?>
<tr>
<th><?= $version ?></th>
<td><?= $description ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
2 changes: 2 additions & 0 deletions templates/html/views/eventDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
<?= $this->render('seeAlso', ['object' => $event]) ?>
</div>

<?= $this->render('@yii/apidoc/templates/html/views/changelog', ['doc' => $event]) ?>

<?php endforeach; ?>
</div>
24 changes: 5 additions & 19 deletions templates/html/views/methodDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,11 @@
<?php endif; ?>
</table>

<?php
$sourceCode = $method->sourceCode;
$collapseId = 'collapse' . ucfirst($method->name);
?>

<p>
<a class="btn btn-link" data-toggle="collapse" href="#<?= $collapseId ?>" role="button" aria-expanded="false"
aria-controls="<?= $collapseId ?>">
Source code
</a>
</p>
<div class="collapse" id="<?= $collapseId ?>">
<div class="card card-body">
<pre>
<code class="hljs php language-php"><?= $highlighter->highlight('php', $sourceCode)->value ?></code>
</pre>
</div>
</div>

<?= $this->render('@yii/apidoc/templates/html/views/changelog', ['doc' => $method]) ?>
<?= $this->render(
'@yii/apidoc/templates/html/views/methodSourceCode',
['method' => $method, 'highlighter' => $highlighter]
) ?>
<?= $this->render('@yii/apidoc/templates/html/views/todos', ['doc' => $method]) ?>

<?php endforeach; ?>
Expand Down
24 changes: 24 additions & 0 deletions templates/html/views/methodSourceCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use yii\apidoc\models\MethodDoc;

/* @var $method MethodDoc */
/* @var $highlighter \Highlight\Highlighter */

$sourceCode = $method->sourceCode;
$collapseId = 'collapse' . ucfirst($method->name);
?>

<p>
<a class="btn btn-link" data-toggle="collapse" href="#<?= $collapseId ?>" role="button" aria-expanded="false"
aria-controls="<?= $collapseId ?>">
Source code
</a>
</p>
<div class="collapse" id="<?= $collapseId ?>">
<div class="card card-body">
<pre>
<code class="hljs php language-php"><?= $highlighter->highlight('php', $sourceCode)->value ?></code>
</pre>
</div>
</div>
1 change: 1 addition & 0 deletions templates/html/views/propertyDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

<div class="signature"><?php echo $renderer->renderPropertySignature($property, $type); ?></div>

<?= $this->render('@yii/apidoc/templates/html/views/changelog', ['doc' => $property]) ?>
<?= $this->render('@yii/apidoc/templates/html/views/todos', ['doc' => $property]) ?>

<?php endforeach; ?>
Expand Down
2 changes: 2 additions & 0 deletions templates/html/views/type.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
<?= $this->render('seeAlso', ['object' => $type]) ?>
</div>

<?= $this->render('@yii/apidoc/templates/html/views/changelog', ['doc' => $type]) ?>

<a id="properties"></a>
<?= $this->render('@yii/apidoc/templates/html/views/propertySummary', ['type' => $type, 'protected' => false]) ?>
<?= $this->render('@yii/apidoc/templates/html/views/propertySummary', ['type' => $type, 'protected' => true]) ?>
Expand Down

0 comments on commit 43add9d

Please sign in to comment.