diff --git a/CHANGELOG.md b/CHANGELOG.md index 6994f9e9..8551f837 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/models/BaseDoc.php b/models/BaseDoc.php index ab8fbd4b..324064ba 100644 --- a/models/BaseDoc.php +++ b/models/BaseDoc.php @@ -50,7 +50,7 @@ class BaseDoc extends BaseObject /** * @param Type|null $aggregatedType - * @return string[]|array + * @return string[] */ protected function splitTypes($aggregatedType) { diff --git a/models/MethodDoc.php b/models/MethodDoc.php index 226cbd03..1006459b 100644 --- a/models/MethodDoc.php +++ b/models/MethodDoc.php @@ -24,6 +24,10 @@ class MethodDoc extends FunctionDoc public $visibility; // will be set by creating class public $definedBy; + /** + * @var string + */ + public $sourceCode = ''; /** @@ -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); + } } } diff --git a/templates/html/ApiRenderer.php b/templates/html/ApiRenderer.php index 3fdc35d4..34b617fb 100644 --- a/templates/html/ApiRenderer.php +++ b/templates/html/ApiRenderer.php @@ -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; @@ -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); diff --git a/templates/html/views/methodDetails.php b/templates/html/views/methodDetails.php index ae6392d6..72500f7b 100644 --- a/templates/html/views/methodDetails.php +++ b/templates/html/views/methodDetails.php @@ -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; @@ -90,6 +91,25 @@ + sourceCode; + $collapseId = 'collapse' . ucfirst($method->name); + ?> + +

+ +

+
+
+
+                highlight('php', $sourceCode)->value ?>
+            
+
+
+ render('@yii/apidoc/templates/html/views/todos', ['doc' => $method]) ?> diff --git a/templates/html/views/type.php b/templates/html/views/type.php index 148f37e1..30ad64ef 100644 --- a/templates/html/views/type.php +++ b/templates/html/views/type.php @@ -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; ?> @@ -105,7 +106,7 @@ render('@yii/apidoc/templates/html/views/constSummary', ['type' => $type]) ?> render('@yii/apidoc/templates/html/views/propertyDetails', ['type' => $type]) ?> -render('@yii/apidoc/templates/html/views/methodDetails', ['type' => $type]) ?> +render('@yii/apidoc/templates/html/views/methodDetails', ['type' => $type, 'highlighter' => $highlighter]) ?> render('@yii/apidoc/templates/html/views/eventDetails', ['type' => $type]) ?> diff --git a/tests/data/api/animal/Cat.php b/tests/data/api/animal/Cat.php index 466ade70..20fe38ab 100644 --- a/tests/data/api/animal/Cat.php +++ b/tests/data/api/animal/Cat.php @@ -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'; } -} \ No newline at end of file +} diff --git a/tests/data/api/animal/Dog.php b/tests/data/api/animal/Dog.php index 5960fd57..de2ad0a2 100644 --- a/tests/data/api/animal/Dog.php +++ b/tests/data/api/animal/Dog.php @@ -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'; } -} \ No newline at end of file +}