Commit 7fa619fe by Carsten Brandt

added extensions to API docs

parent 3519c14e
...@@ -128,7 +128,7 @@ class RenderController extends Controller ...@@ -128,7 +128,7 @@ class RenderController extends Controller
return new $rendererClass(); return new $rendererClass();
} }
protected function findFiles($path, $except = ['/vendor/', '/tests/']) protected function findFiles($path, $except = ['vendor/', 'tests/'])
{ {
$path = FileHelper::normalizePath($path); $path = FileHelper::normalizePath($path);
$options = [ $options = [
......
...@@ -28,6 +28,103 @@ class Renderer extends \yii\apidoc\templates\html\Renderer ...@@ -28,6 +28,103 @@ class Renderer extends \yii\apidoc\templates\html\Renderer
public $guideUrl; public $guideUrl;
public $extensions = [
'apidoc',
'authclient',
'bootstrap',
'codeception',
'composer',
'debug',
'elasticsearch',
'faker',
'gii',
'imagine',
'jui',
'mongodb',
'redis',
'smarty',
'sphinx',
'swiftmailer',
'twig',
];
/**
* 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 renderApi($context, $controller)
{
parent::renderApi($context, $controller);
$dir = Yii::getAlias($this->targetDir);
$types = array_merge($context->classes, $context->interfaces, $context->traits);
$controller->stdout('generating extension index files...');
foreach($this->extensions as $ext) {
$readme = @file_get_contents("https://raw.github.com/yiisoft/yii2-$ext/master/README.md");
$indexFileContent = $this->renderWithLayout($this->indexView, [
'docContext' => $context,
'types' => $this->filterTypes($types, $ext),
'readme' => $readme ?: null,
]);
file_put_contents($dir . "/ext_{$ext}_index.html", $indexFileContent);
}
$controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
}
public function getNavTypes($type, $types)
{
if ($type === null) {
return $types;
}
$extensions = $this->extensions;
$navClasses = 'app';
if (isset($type)) {
if ($type->name == 'Yii') {
$navClasses = 'yii';
} elseif (strncmp($type->name, 'yii\\', 4) == 0) {
$subName = substr($type->name, 4);
if (($pos = strpos($subName, '\\')) !== false) {
$subNamespace = substr($subName, 0, $pos);
if (in_array($subNamespace, $extensions)) {
$navClasses = $subNamespace;
} else {
$navClasses = 'yii';
}
}
}
}
return $this->filterTypes($types, $navClasses);
}
protected function filterTypes($types, $navClasses)
{
switch ($navClasses)
{
case 'app':
$types = array_filter($types, function($val) {
return strncmp($val->name, 'yii\\', 4) !== 0;
});
break;
case 'yii':
$self = $this;
$types = array_filter($types, function($val) use ($self) {
if (strlen($val->name) < 5) {
return false;
}
$subName = substr($val->name, 4, strpos($val->name, '\\', 5) - 4);
return strncmp($val->name, 'yii\\', 4) === 0 && !in_array($subName, $self->extensions);
});
break;
default:
$types = array_filter($types, function($val) use ($navClasses) {
return strncmp($val->name, "yii\\$navClasses\\", strlen("yii\\$navClasses\\")) === 0;
});
}
return $types;
}
/** /**
* Renders a given [[Context]]. * Renders a given [[Context]].
* *
......
...@@ -11,6 +11,7 @@ $this->beginContent('@yii/apidoc/templates/bootstrap/layouts/main.php'); ?> ...@@ -11,6 +11,7 @@ $this->beginContent('@yii/apidoc/templates/bootstrap/layouts/main.php'); ?>
<div class="row"> <div class="row">
<div class="col-md-2"> <div class="col-md-2">
<?php <?php
$types = $this->context->getNavTypes(isset($type) ? $type : null, $types);
ksort($types); ksort($types);
$nav = []; $nav = [];
foreach($types as $i=>$class) { foreach($types as $i=>$class) {
......
...@@ -37,9 +37,17 @@ $this->beginPage(); ...@@ -37,9 +37,17 @@ $this->beginPage();
'padded' => false, 'padded' => false,
'view' => $this, 'view' => $this,
]); ]);
$extItems = [];
foreach($this->context->extensions as $ext) {
$extItems[] = [
'label' => $ext,
'url' => "./ext_{$ext}_index.html",
];
}
$nav = [ $nav = [
['label' => 'Class reference', 'url' => './index.html'], ['label' => 'Class reference', 'url' => './index.html'],
// ['label' => 'Application API', 'url' => '/site/about'], // ['label' => 'Application API', 'url' => '/site/about'],
['label' => 'Extensions', 'items' => $extItems],
]; ];
if ($this->context->guideUrl !== null) { if ($this->context->guideUrl !== null) {
$nav[] = ['label' => 'Guide', 'url' => $this->context->guideUrl . 'guide_index.html']; $nav[] = ['label' => 'Guide', 'url' => $this->context->guideUrl . 'guide_index.html'];
......
...@@ -8,6 +8,10 @@ use yii\apidoc\models\TraitDoc; ...@@ -8,6 +8,10 @@ use yii\apidoc\models\TraitDoc;
* @var yii\web\View $this * @var yii\web\View $this
*/ */
if (isset($readme)) {
echo \yii\apidoc\helpers\Markdown::process($readme);
}
?><h1>Class Reference</h1> ?><h1>Class Reference</h1>
<table class="summaryTable docIndex table table-bordered table-striped table-hover"> <table class="summaryTable docIndex table table-bordered table-striped table-hover">
......
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