Commit 79a14e7a by Carsten Brandt

created apidoc generator online template for yiiframework.com

parent 35cd2bff
......@@ -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';
......
<?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';
}
}
\ No newline at end of file
<?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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment