mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
created apidoc generator online template for yiiframework.com
This commit is contained in:
@ -154,7 +154,7 @@ class TypeDoc extends BaseDoc
|
||||
{
|
||||
parent::__construct($reflector, $config);
|
||||
|
||||
$this->namespace = StringHelper::basename($this->name);
|
||||
$this->namespace = StringHelper::dirname($this->name);
|
||||
|
||||
if ($reflector === null) {
|
||||
return;
|
||||
|
@ -96,7 +96,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
|
||||
$this->context = $context;
|
||||
$dir = Yii::getAlias($this->targetDir);
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir);
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
|
||||
$types = array_merge($context->classes, $context->interfaces, $context->traits);
|
||||
@ -166,7 +166,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
|
||||
$links[] = Html::a(
|
||||
$type->name,
|
||||
null,
|
||||
['href' => $this->generateFileName($type->name)]
|
||||
['href' => $this->generateLink($type->name)]
|
||||
) . $postfix;
|
||||
}
|
||||
}
|
||||
@ -191,7 +191,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
|
||||
if (($type = $this->context->getType($subject->definedBy)) === null) {
|
||||
return $subject->name;
|
||||
} else {
|
||||
$link = $this->generateFileName($type->name);
|
||||
$link = $this->generateLink($type->name);
|
||||
if ($subject instanceof MethodDoc) {
|
||||
$link .= '#' . $subject->name . '()';
|
||||
} else {
|
||||
@ -336,6 +336,11 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
|
||||
. ' )';
|
||||
}
|
||||
|
||||
protected function generateLink($typeName)
|
||||
{
|
||||
return $this->generateFileName($typeName);
|
||||
}
|
||||
|
||||
protected function generateFileName($typeName)
|
||||
{
|
||||
return strtolower(str_replace('\\', '_', $typeName)) . '.html';
|
||||
|
68
extensions/apidoc/templates/online/Renderer.php
Normal file
68
extensions/apidoc/templates/online/Renderer.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\apidoc\templates\online;
|
||||
use yii\apidoc\models\Context;
|
||||
use yii\apidoc\models\TypeDoc;
|
||||
use yii\console\Controller;
|
||||
use Yii;
|
||||
use yii\helpers\Console;
|
||||
use yii\helpers\FileHelper;
|
||||
use yii\helpers\StringHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Carsten Brandt <mail@cebe.cc>
|
||||
* @since 2.0
|
||||
*/
|
||||
class Renderer extends \yii\apidoc\templates\html\Renderer
|
||||
{
|
||||
public $layout = false;//'@yii/apidoc/templates/offline/views/offline.php';
|
||||
public $indexView = '@yii/apidoc/templates/offline/views/index.php';
|
||||
|
||||
public $pageTitle = 'Yii Framework 2.0 API Documentation';
|
||||
|
||||
/**
|
||||
* Renders a given [[Context]].
|
||||
*
|
||||
* @param Context $context the api documentation context to render.
|
||||
* @param Controller $controller the apidoc controller instance. Can be used to control output.
|
||||
*/
|
||||
public function render($context, $controller)
|
||||
{
|
||||
parent::render($context, $controller);
|
||||
$dir = Yii::getAlias($this->targetDir);
|
||||
$controller->stdout("writing packages file...");
|
||||
$packages = [];
|
||||
$notNamespaced = [];
|
||||
foreach(array_merge($context->classes, $context->interfaces, $context->traits) as $type) {
|
||||
/** @var TypeDoc $type */
|
||||
if (empty($type->namespace)) {
|
||||
$notNamespaced[] = str_replace('\\', '-', $type->name);
|
||||
} else {
|
||||
$packages[$type->namespace][] = str_replace('\\', '-', $type->name);
|
||||
}
|
||||
}
|
||||
ksort($packages);
|
||||
$packages = array_merge(['Not namespaced' => $notNamespaced], $packages);
|
||||
foreach($packages as $name => $classes) {
|
||||
sort($packages[$name]);
|
||||
}
|
||||
file_put_contents($dir . '/packages.txt', serialize($packages));
|
||||
$controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
|
||||
}
|
||||
|
||||
protected function generateLink($typeName)
|
||||
{
|
||||
return strtolower(str_replace('\\', '-', $typeName));
|
||||
}
|
||||
|
||||
protected function generateFileName($typeName)
|
||||
{
|
||||
return $this->generateLink($typeName) . '.html';
|
||||
}
|
||||
}
|
32
extensions/apidoc/templates/online/views/index.php
Normal file
32
extensions/apidoc/templates/online/views/index.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use yii\apidoc\models\ClassDoc;
|
||||
use yii\apidoc\models\InterfaceDoc;
|
||||
use yii\apidoc\models\TraitDoc;
|
||||
/**
|
||||
* @var ClassDoc[]|InterfaceDoc[]|TraitDoc[] $types
|
||||
* @var yii\web\View $this
|
||||
*/
|
||||
|
||||
?><h1>Class Reference</h1>
|
||||
|
||||
<table class="summaryTable docIndex">
|
||||
<colgroup>
|
||||
<col class="col-package" />
|
||||
<col class="col-class" />
|
||||
<col class="col-description" />
|
||||
</colgroup>
|
||||
<tr>
|
||||
<th>Class</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<?php
|
||||
ksort($types);
|
||||
foreach($types as $i=>$class):
|
||||
?>
|
||||
<tr>
|
||||
<td><?= $this->context->typeLink($class, $class->name) ?></td>
|
||||
<td><?= \yii\apidoc\helpers\Markdown::process($class->shortDescription, $class) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
Reference in New Issue
Block a user