Browse Source

finished offline template summaries

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
da1617340d
  1. 88
      extensions/yii/apidoc/components/OfflineRenderer.php
  2. 6
      extensions/yii/apidoc/models/ClassDoc.php
  3. 42
      extensions/yii/apidoc/models/Context.php
  4. 53
      extensions/yii/apidoc/models/TypeDoc.php
  5. 38
      extensions/yii/apidoc/views/class.php
  6. 73
      extensions/yii/apidoc/views/classSummary.php
  7. 34
      extensions/yii/apidoc/views/constSummary.php
  8. 34
      extensions/yii/apidoc/views/eventSummary.php
  9. 2
      extensions/yii/apidoc/views/index.php
  10. 40
      extensions/yii/apidoc/views/methodSummary.php
  11. 42
      extensions/yii/apidoc/views/propertySummary.php

88
extensions/yii/apidoc/components/OfflineRenderer.php

@ -8,6 +8,10 @@
namespace yii\apidoc\components;
use yii\apidoc\models\ConstDoc;
use yii\apidoc\models\EventDoc;
use yii\apidoc\models\MethodDoc;
use yii\apidoc\models\PropertyDoc;
use yii\base\ViewContextInterface;
use yii\console\Controller;
use yii\helpers\Console;
@ -85,17 +89,50 @@ class OfflineRenderer extends BaseRenderer implements ViewContextInterface
}
/**
* creates a link to an item
* @param ClassDoc|InterfaceDoc|TraitDoc $item
* creates a link to a type (class, interface or trait)
* @param ClassDoc|InterfaceDoc|TraitDoc $types
* @param string $title
* @return string
*/
public function link($item, $title = null)
public function typeLink($types, $title = null)
{
if (!is_array($types)) {
$types = [$types];
}
$links = [];
foreach($types as $type) {
if (!is_object($type) && ($t = $this->context->getType($type)) !== null) {
$type = $t;
}
if (!is_object($type)) {
$links[] = $type;
} else {
$links[] = Html::a(
$title !== null ? $title : $type->name,
null,
['href' => $this->generateFileName($type->name)]
);
}
}
return implode('|', $links);
}
/**
* creates a link to a subject
* @param PropertyDoc|MethodDoc|ConstDoc|EventDoc $subject
* @param string $title
* @return string
*/
public function subjectLink($subject, $title = null)
{
if ($title === null) {
$title = $item->name;
$title = $subject->name;
}
if (($type = $this->context->getType($subject->definedBy)) === null) {
return $subject->name;
} else {
return Html::a($title, null, ['href' => $this->generateFileName($type->name) . '#' . $subject->name . '-detail']);
}
return Html::a($title, null, ['href' => $this->generateFileName($item->name)]);
}
/**
@ -104,11 +141,11 @@ class OfflineRenderer extends BaseRenderer implements ViewContextInterface
*/
public function renderInheritance($class)
{
$parents[] = $this->link($class);
$parents[] = $this->typeLink($class);
while ($class->parentClass !== null) {
if(isset($this->context->classes[$class->parentClass])) {
$class = $this->context->classes[$class->parentClass];
$parents[] = $this->link($class);
$parents[] = $this->typeLink($class);
} else {
$parents[] = $class->parentClass; // TODO link to php.net
break;
@ -118,15 +155,16 @@ class OfflineRenderer extends BaseRenderer implements ViewContextInterface
}
/**
* @param ClassDoc $class
* @param array $names
* @return string
*/
public function renderImplements($class)
public function renderInterfaces($names)
{
$interfaces = [];
foreach($class->interfaces as $interface) {
sort($names, SORT_STRING);
foreach($names as $interface) {
if(isset($this->context->interfaces[$interface])) {
$interfaces[] = $this->link($this->context->interfaces[$interface]);
$interfaces[] = $this->typeLink($this->context->interfaces[$interface]);
} else {
$interfaces[] = $interface; // TODO link to php.net
}
@ -135,15 +173,16 @@ class OfflineRenderer extends BaseRenderer implements ViewContextInterface
}
/**
* @param ClassDoc|TraitDoc $class
* @param array $names
* @return string
*/
public function renderTraitUses($class)
public function renderTraits($names)
{
$traits = [];
foreach($class->traits as $trait) {
sort($names, SORT_STRING);
foreach($names as $trait) {
if(isset($this->context->traits[$trait])) {
$traits[] = $this->link($this->context->traits[$trait]);
$traits[] = $this->typeLink($this->context->traits[$trait]);
} else {
$traits[] = $trait; // TODO link to php.net
}
@ -151,17 +190,22 @@ class OfflineRenderer extends BaseRenderer implements ViewContextInterface
return implode(', ',$traits);
}
public function renderSubclasses($class)
/**
* @param array $names
* @return string
*/
public function renderClasses($names)
{
$subclasses = [];
foreach($class->subclasses as $subclass) {
if(isset($this->context->classes[$subclass])) {
$subclasses[] = $this->link($this->context->classes[$subclass]);
$classes = [];
sort($names, SORT_STRING);
foreach($names as $class) {
if(isset($this->context->classes[$class])) {
$classes[] = $this->typeLink($this->context->classes[$class]);
} else {
$subclasses[] = $subclass; // TODO link to php.net
$classes[] = $class; // TODO link to php.net
}
}
return implode(', ',$subclasses);
return implode(', ',$classes);
}

6
extensions/yii/apidoc/models/ClassDoc.php

@ -22,7 +22,13 @@ class ClassDoc extends TypeDoc
// will be set by Context::updateReferences()
public $subclasses = [];
/**
* @var EventDoc[]
*/
public $events = [];
/**
* @var ConstDoc[]
*/
public $constants = [];

42
extensions/yii/apidoc/models/Context.php

@ -32,6 +32,18 @@ class Context extends Component
public $traits = [];
public function getType($type)
{
if (isset($this->classes[$type])) {
return $this->classes[$type];
} elseif (isset($this->interfaces[$type])) {
return $this->interfaces[$type];
} elseif (isset($this->traits[$type])) {
return $this->traits[$type];
}
return null;
}
public function addFile($fileName)
{
if (isset($this->files[$fileName])) {
@ -107,7 +119,6 @@ class Context extends Component
}
// update interfaces of subclasses
foreach($this->classes as $class) {
// TODO do the same for events, constants, methods, properties
$this->updateSubclassInferfacesTraits($class);
}
// update implementedBy and usedBy for interfaces and traits
@ -119,10 +130,17 @@ class Context extends Component
}
foreach($class->traits as $trait) {
if (isset($this->traits[$trait])) {
$this->traits[$trait]->usedBy[] = $class->name;
$trait = $this->traits[$trait];
$trait->usedBy[] = $class->name;
$class->properties = array_merge($trait->properties, $class->properties); // TODO make unique
$class->methods = array_merge($trait->methods, $class->methods); // TODO make unique
}
}
}
// update properties, methods, contants and events of subclasses
foreach($this->classes as $class) {
$this->updateSubclassInheritance($class);
}
}
/**
@ -135,7 +153,27 @@ class Context extends Component
$subclass = $this->classes[$subclass];
$subclass->interfaces = array_unique(array_merge($subclass->interfaces, $class->interfaces));
$subclass->traits = array_unique(array_merge($subclass->traits, $class->traits));
$subclass->events = array_merge($class->events, $subclass->events); // TODO make unique
$subclass->constants = array_merge($class->constants, $subclass->constants); // TODO make unique
$subclass->properties = array_merge($class->properties, $subclass->properties); // TODO make unique
$subclass->methods = array_merge($class->methods, $subclass->methods); // TODO make unique
$this->updateSubclassInferfacesTraits($subclass);
}
}
/**
* Add implemented interfaces and used traits to subclasses
* @param ClassDoc $class
*/
protected function updateSubclassInheritance($class)
{
foreach($class->subclasses as $subclass) {
$subclass = $this->classes[$subclass];
$subclass->events = array_merge($class->events, $subclass->events); // TODO make unique
$subclass->constants = array_merge($class->constants, $subclass->constants); // TODO make unique
$subclass->properties = array_merge($class->properties, $subclass->properties); // TODO make unique
$subclass->methods = array_merge($class->methods, $subclass->methods); // TODO make unique
$this->updateSubclassInheritance($subclass);
}
}
}

53
extensions/yii/apidoc/models/TypeDoc.php

@ -13,9 +13,61 @@ use yii\base\Exception;
class TypeDoc extends BaseDoc
{
public $authors = [];
/**
* @var MethodDoc[]
*/
public $methods = [];
/**
* @var PropertyDoc[]
*/
public $properties = [];
public function getPublicMethods()
{
return $this->getFilteredMethods('public');
}
public function getProtectedMethods()
{
return $this->getFilteredMethods('protected');
}
private function getFilteredMethods($visibility)
{
$methods = [];
foreach($this->methods as $method) {
if ($method->visibility == $visibility) {
$methods[] = $method;
}
}
return $methods;
}
public function getPublicProperties()
{
return $this->getFilteredProperties('public');
}
public function getProtectedProperties()
{
return $this->getFilteredProperties('protected');
}
private function getFilteredProperties($visibility)
{
if ($this->properties === null) {
return [];
}
$properties = [];
foreach($this->properties as $property) {
if ($property->visibility == $visibility) {
$properties[] = $property;
}
}
return $properties;
}
/**
* @param \phpDocumentor\Reflection\InterfaceReflector $reflector
* @param array $config
@ -48,6 +100,7 @@ class TypeDoc extends BaseDoc
$method = new MethodDoc($methodReflector);
$method->definedBy = $this->name;
// TODO only set property when subclass of Object
if (!strncmp($method->name, 'set', 3)) {
$propertyName = lcfirst(substr($method->name, 3));
if (isset($this->properties[$propertyName])) {

38
extensions/yii/apidoc/views/class.php

@ -26,30 +26,36 @@ use yii\apidoc\models\TraitDoc;
echo $item->name;
?></h1>
<div id="nav">
<a href="index.html">All Classes</a>
<?php if(!($item instanceof InterfaceDoc) && !empty($item->properties)): ?>
| <a href="#properties">Properties</a>
<?php endif; ?>
<?php if(!empty($item->methods)): ?>
| <a href="#methods">Methods</a>
<?php endif; ?>
<?php if($item instanceof ClassDoc && !empty($item->events)): ?>
| <a href="#events">Events</a>
<?php endif; ?>
<a href="index.html">All Classes</a>
<?php if(!($item instanceof InterfaceDoc) && !empty($item->properties)): ?>
| <a href="#properties">Properties</a>
<?php endif; ?>
<?php if(!empty($item->methods)): ?>
| <a href="#methods">Methods</a>
<?php endif; ?>
<?php if($item instanceof ClassDoc && !empty($item->events)): ?>
| <a href="#events">Events</a>
<?php endif; ?>
<?php if($item instanceof ClassDoc && !empty($item->constants)): ?>
| <a href="#constants">Constants</a>
<?php endif; ?>
</div>
<?= $this->render('classSummary', ['item' => $item]); ?>
<?= $this->render('classSummary', ['item' => $item]) ?>
<a name="properties"></a>
<?php //$this->renderPartial('propertySummary',array('class'=>$item,'protected'=>false)); ?>
<?php //$this->renderPartial('propertySummary',array('class'=>$item,'protected'=>true)); ?>
<?= $this->render('propertySummary', ['item' => $item,'protected' => false]) ?>
<?= $this->render('propertySummary', ['item' => $item,'protected' => true]) ?>
<a name="methods"></a>
<?php //$this->renderPartial('methodSummary',array('class'=>$item,'protected'=>false)); ?>
<?php //$this->renderPartial('methodSummary',array('class'=>$item,'protected'=>true)); ?>
<?= $this->render('methodSummary', ['item' => $item, 'protected' => false]) ?>
<?= $this->render('methodSummary', ['item' => $item, 'protected' => true]) ?>
<a name="events"></a>
<?php //$this->renderPartial('eventSummary',array('class'=>$item)); ?>
<?= $this->render('eventSummary', ['item' => $item]) ?>
<a name="constants"></a>
<?= $this->render('constSummary', ['item' => $item]) ?>
<?php //$this->renderPartial('propertyDetails',array('class'=>$item)); ?>
<?php //$this->renderPartial('methodDetails',array('class'=>$item)); ?>

73
extensions/yii/apidoc/views/classSummary.php

@ -1,60 +1,49 @@
<?php
use yii\apidoc\components\OfflineRenderer;
use yii\apidoc\models\ClassDoc;
use yii\apidoc\models\InterfaceDoc;
use yii\apidoc\models\TraitDoc;
/**
* @var ClassDoc|InterfaceDoc|TraitDoc $item
* @var yii\web\View $this
* @var OfflineRenderer $renderer
*/
$renderer = $this->context;
?><table class="summaryTable docClass">
<colgroup>
<colgroup>
<col class="col-name" />
<col class="col-value" />
</colgroup>
<?php if ($item instanceof ClassDoc): ?>
<tr>
<th>Inheritance</th>
<td><?php echo $this->context->renderInheritance($item); ?></td>
</tr>
<?php endif; ?>
<?php if(!empty($item->interfaces)): ?>
<tr>
<th>Implements</th>
<td><?php echo $this->context->renderImplements($item); ?></td>
</tr>
<?php endif; ?>
<?php if(!($item instanceof InterfaceDoc) && !empty($item->traits)): ?>
<tr>
<th>Uses Traits</th>
<td><?php echo $this->context->renderTraitUses($item); ?></td>
</tr>
<?php endif; ?>
<?php if($item instanceof ClassDoc && !empty($item->subclasses)): ?>
<tr>
<th>Subclasses</th>
<td><?php echo $this->context->renderSubclasses($item); ?></td>
</tr>
<?php endif; ?>
<?php if(!empty($item->since)): ?>
<tr>
<th>Since</th>
<td><?php echo $item->since; ?></td>
</tr>
<?php endif; ?>
<?php if(!empty($item->version)): ?>
<tr>
<th>Version</th>
<td><?php echo $item->version; ?></td>
</tr>
<?php endif; ?>
<tr>
</colgroup>
<?php if ($item instanceof ClassDoc): ?>
<tr><th>Inheritance</th><td><?= $renderer->renderInheritance($item) ?></td></tr>
<?php endif; ?>
<?php if ($item instanceof ClassDoc && !empty($item->interfaces)): ?>
<tr><th>Implements</th><td><?= $renderer->renderInterfaces($item->interfaces) ?></td></tr>
<?php endif; ?>
<?php if(!($item instanceof InterfaceDoc) && !empty($item->traits)): ?>
<tr><th>Uses Traits</th><td><?= $renderer->renderTraits($item->traits) ?></td></tr>
<?php endif; ?>
<?php if($item instanceof ClassDoc && !empty($item->subclasses)): ?>
<tr><th>Subclasses</th><td><?= $renderer->renderClasses($item->subclasses) ?></td></tr>
<?php endif; ?>
<?php if ($item instanceof InterfaceDoc && !empty($item->implementedBy)): ?>
<tr><th>Implemented by</th><td><?= $renderer->renderClasses($item->implementedBy) ?></td></tr>
<?php endif; ?>
<?php if ($item instanceof TraitDoc && !empty($item->usedBy)): ?>
<tr><th>Implemented by</th><td><?= $renderer->renderClasses($item->usedBy) ?></td></tr>
<?php endif; ?>
<?php if(!empty($item->since)): ?>
<tr><th>Available since version</th><td><?= $item->since ?></td></tr>
<?php endif; ?>
<tr>
<th>Source Code</th>
<!-- <td>--><?php //echo $this->renderSourceLink($item->sourcePath); ?><!--</td>-->
</tr>
<td><?php // TODO echo $this->renderSourceLink($item->sourcePath) ?></td>
</tr>
</table>
<div id="classDescription">
<?php echo $item->description; ?>
<strong><?= $item->shortDescription ?></strong>
<p><?= nl2br($item->description) ?></p>
</div>

34
extensions/yii/apidoc/views/constSummary.php

@ -0,0 +1,34 @@
<?php
use yii\apidoc\models\ClassDoc;
/**
* @var ClassDoc $item
* @var yii\web\View $this
*/
if (empty($item->constants)) {
return;
} ?>
<div class="summary docConst">
<h2>Constants</h2>
<p><a href="#" class="toggle">Hide inherited constants</a></p>
<table class="summaryTable">
<colgroup>
<col class="col-const" />
<col class="col-description" />
<col class="col-defined" />
</colgroup>
<tr>
<th>Constant</th><th>Description</th><th>Defined By</th>
</tr>
<?php foreach($item->constants as $constant): ?>
<tr<?= $constant->definedBy != $item->name ? ' class="inherited"' : '' ?> id="<?= $constant->name ?>">
<td><?= $this->context->subjectLink($constant) ?></td>
<td><?= $constant->shortDescription ?></td>
<td><?= $this->context->typeLink($constant->definedBy) ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>

34
extensions/yii/apidoc/views/eventSummary.php

@ -0,0 +1,34 @@
<?php
use yii\apidoc\models\ClassDoc;
/**
* @var ClassDoc $item
* @var yii\web\View $this
*/
if (empty($item->events)) {
return;
} ?>
<div class="summary docEvent">
<h2>Events</h2>
<p><a href="#" class="toggle">Hide inherited events</a></p>
<table class="summaryTable">
<colgroup>
<col class="col-event" />
<col class="col-description" />
<col class="col-defined" />
</colgroup>
<tr>
<th>Event</th><th>Description</th><th>Defined By</th>
</tr>
<?php foreach($item->events as $event): ?>
<tr<?= $event->definedBy != $item->name ? ' class="inherited"' : '' ?> id="<?= $event->name ?>">
<td><?= $this->context->subjectLink($event) ?></td>
<td><?= $event->shortDescription ?></td>
<td><?= $this->context->typeLink($event->definedBy) ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>

2
extensions/yii/apidoc/views/index.php

@ -23,7 +23,7 @@ use yii\apidoc\models\TraitDoc;
ksort($items);
foreach($items as $i=>$class): ?>
<tr>
<td><?php echo $this->context->link($class, $class->name); ?></td>
<td><?php echo $this->context->typeLink($class, $class->name); ?></td>
<td><?php echo $class->shortDescription; ?></td>
</tr>
<?php endforeach; ?>

40
extensions/yii/apidoc/views/methodSummary.php

@ -0,0 +1,40 @@
<?php
use yii\apidoc\models\ClassDoc;
use yii\apidoc\models\InterfaceDoc;
use yii\apidoc\models\TraitDoc;
/**
* @var ClassDoc|InterfaceDoc|TraitDoc $item
* @var boolean $protected
* @var yii\web\View $this
*/
if ($protected && count($item->getProtectedMethods()) == 0 || !$protected && count($item->getPublicMethods()) == 0) {
return;
} ?>
<div class="summary docMethod">
<h2><?= $protected ? 'Protected Methods' : 'Public Methods' ?></h2>
<p><a href="#" class="toggle">Hide inherited methods</a></p>
<table class="summaryTable">
<colgroup>
<col class="col-method" />
<col class="col-description" />
<col class="col-defined" />
</colgroup>
<tr>
<th>Method</th><th>Description</th><th>Defined By</th>
</tr>
<?php foreach($item->methods as $method): ?>
<?php if($protected && $method->visibility == 'protected' || !$protected && $method->visibility != 'protected'): ?>
<tr<?= $method->definedBy != $item->name ? ' class="inherited"' : '' ?> id="<?= $method->name ?>">
<td><?= $this->context->subjectLink($method, $method->name.'()') ?></td>
<td><?= $method->shortDescription ?></td>
<td><?= $this->context->typeLink($method->definedBy) ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</table>
</div>

42
extensions/yii/apidoc/views/propertySummary.php

@ -0,0 +1,42 @@
<?php
use yii\apidoc\models\ClassDoc;
use yii\apidoc\models\InterfaceDoc;
use yii\apidoc\models\TraitDoc;
/**
* @var ClassDoc|InterfaceDoc|TraitDoc $item
* @var boolean $protected
* @var yii\web\View $this
*/
if ($protected && count($item->getProtectedProperties()) == 0 || !$protected && count($item->getPublicProperties()) == 0) {
return;
} ?>
<div class="summary docProperty">
<h2><?= $protected ? 'Protected Properties' : 'Public Properties' ?></h2>
<p><a href="#" class="toggle">Hide inherited properties</a></p>
<table class="summaryTable">
<colgroup>
<col class="col-property" />
<col class="col-type" />
<col class="col-description" />
<col class="col-defined" />
</colgroup>
<tr>
<th>Property</th><th>Type</th><th>Description</th><th>Defined By</th>
</tr>
<?php foreach($item->properties as $property): ?>
<?php if($protected && $property->visibility == 'protected' || !$protected && $property->visibility != 'protected'): ?>
<tr<?= $property->definedBy != $item->name ? ' class="inherited"' : '' ?> id="<?= $property->name ?>">
<td><?php echo $this->context->subjectLink($property); ?></td>
<td><?php echo $this->context->typeLink($property->types); ?></td>
<td><?php echo $property->shortDescription; ?></td>
<td><?php echo $this->context->typeLink($property->definedBy); ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</table>
</div>
Loading…
Cancel
Save