Skip to content
Merged
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ Yii Framework 2 apidoc extension Change Log
- Bug #179: Fixed incorrect output when string type hint is used in method parameters (arogachev)
- Bug #199: Fixed processing of nullable return types (arogachev)
- Bug #148: Fixed processing of code containing uniform variable syntax (arogachev)
- Enh #143: Do not include methods and properties marked as internal (arogachev)
- Bug #197: Adapted fixing of Markdown links for multiple links (arogachev)
- Bug #128: Fixed extracting of first sentence from the text containing backticks (arogachev)
- Enh #209: Added support for todos in properties and methods (arogachev)
- Enh #18: Added pretty print for arrays (arogachev)
- Enh #209: Added support for todos in properties and methods (arogachev)
- Bug #128: Fixed extracting of first sentence from the text containing backticks (arogachev)
- Bug #197: Adapted fixing of Markdown links for multiple links (arogachev)
- Enh #143: Do not include methods and properties marked as internal (arogachev)
- Enh #147: Added feature of viewing method source code without external links (arogachev)


2.1.6 May 05, 2021
Expand Down
2 changes: 1 addition & 1 deletion models/BaseDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BaseDoc extends BaseObject

/**
* @param Type|null $aggregatedType
* @return string[]|array
* @return string[]
*/
protected function splitTypes($aggregatedType)
{
Expand Down
9 changes: 9 additions & 0 deletions models/MethodDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class MethodDoc extends FunctionDoc
public $visibility;
// will be set by creating class
public $definedBy;
/**
* @var string
*/
public $sourceCode = '';


/**
Expand All @@ -44,5 +48,10 @@ public function __construct($reflector = null, $context = null, $config = [])
$this->isStatic = $reflector->isStatic();

$this->visibility = $reflector->getVisibility();

$lines = file($this->sourceFile);
for ($i = $this->startLine - 1; $i <= $this->endLine - 1; $i++) {
$this->sourceCode .= substr($lines[$i], 4);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 can be calculated dynamically. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "4" exactly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Number of spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's the number of spaces we need to remove from the beginning of each line. I thought of existence of cases with different amount of spaces used for indentation, tabs instead of spaces and so on. But we discussed it with @samdark and decided to leave it as is now.

}
}
}
5 changes: 5 additions & 0 deletions templates/html/ApiRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace yii\apidoc\templates\html;

use Highlight\Highlighter;
use yii\apidoc\helpers\ApiMarkdown;
use yii\apidoc\models\MethodDoc;
use yii\apidoc\models\PropertyDoc;
Expand Down Expand Up @@ -102,12 +103,16 @@ public function render($context, $targetDir)
if ($this->controller !== null) {
Console::startProgress(0, $typeCount, 'Rendering files: ', false);
}

$done = 0;
$higlighter = new Highlighter;

foreach ($types as $type) {
$fileContent = $this->renderWithLayout($this->typeView, [
'type' => $type,
'apiContext' => $context,
'types' => $types,
'highlighter' => $higlighter,
]);
file_put_contents($targetDir . '/' . $this->generateFileName($type->name), $fileContent);

Expand Down
20 changes: 20 additions & 0 deletions templates/html/views/methodDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/* @var $type ClassDoc|TraitDoc */
/* @var $this yii\web\View */
/* @var $renderer \yii\apidoc\templates\html\ApiRenderer */
/* @var $highlighter \Highlight\Highlighter */

$renderer = $this->context;

Expand Down Expand Up @@ -90,6 +91,25 @@
<?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/todos', ['doc' => $method]) ?>

<?php endforeach; ?>
Expand Down
3 changes: 2 additions & 1 deletion templates/html/views/type.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/* @var $type ClassDoc|InterfaceDoc|TraitDoc */
/* @var $this yii\web\View */
/* @var $renderer \yii\apidoc\templates\html\ApiRenderer */
/* @var $highlighter \Highlight\Highlighter */

$renderer = $this->context;
?>
Expand Down Expand Up @@ -105,7 +106,7 @@
<?= $this->render('@yii/apidoc/templates/html/views/constSummary', ['type' => $type]) ?>

<?= $this->render('@yii/apidoc/templates/html/views/propertyDetails', ['type' => $type]) ?>
<?= $this->render('@yii/apidoc/templates/html/views/methodDetails', ['type' => $type]) ?>
<?= $this->render('@yii/apidoc/templates/html/views/methodDetails', ['type' => $type, 'highlighter' => $highlighter]) ?>
<?php if ($type instanceof ClassDoc): ?>
<?= $this->render('@yii/apidoc/templates/html/views/eventDetails', ['type' => $type]) ?>
<?php endif; ?>
4 changes: 2 additions & 2 deletions tests/data/api/animal/Cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Cat extends Animal
*/
public function render()
{
// this method has `@inheritdoc` tag in brackets
// this method has `inheritdoc` tag in brackets
return 'This is a cat';
}
}
}
4 changes: 2 additions & 2 deletions tests/data/api/animal/Dog.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Dog extends Animal
*/
public function render()
{
// this method has `@inheritdoc` tag without brackets
// this method has `inheritdoc` tag without brackets
return 'This is a dog';
}
}
}