Commit 31a1eca5 by Carsten Brandt

add source code links to api docs

parent 6df4802e
......@@ -95,7 +95,6 @@ class BaseDoc extends Object
}
}
// TODO
public function loadSource($reflection)
{
......@@ -104,14 +103,6 @@ class BaseDoc extends Object
$this->endLine = $reflection->getEndLine();
}
public function getSourceUrl($baseUrl, $line=null)
{
if($line === null)
return $baseUrl . $this->sourcePath;
else
return $baseUrl . $this->sourcePath . '#' . $line;
}
public function getSourceCode()
{
$lines = file(YII_PATH . $this->sourcePath);
......
......@@ -161,7 +161,7 @@ class TypeDoc extends BaseDoc
{
parent::__construct($reflector, $context, $config);
$this->namespace = StringHelper::dirname($this->name);
$this->namespace = trim(StringHelper::dirname($this->name), '\\');
if ($reflector === null) {
return;
......
......@@ -88,4 +88,29 @@ class ApiRenderer extends \yii\apidoc\templates\html\ApiRenderer
$this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
}
}
public function getSourceUrl($type, $line = null)
{
if (is_string($type)) {
$type = $this->apiContext->getType($type);
}
$baseUrl = 'https://github.com/yiisoft/yii2/blob/master';
switch ($this->getTypeCategory($type))
{
case 'yii':
$url = '/framework/' . str_replace('\\', '/', substr($type->name, 4)) . '.php';
break;
case 'app':
return null;
default:
$url = '/extensions/' . str_replace('\\', '/', substr($type->name, 4)) . '.php';
break;
}
if($line === null)
return $baseUrl . $url;
else
return $baseUrl . $url . '#L' . $line;
}
}
\ No newline at end of file
......@@ -33,6 +33,11 @@ trait RendererTrait
if ($type === null) {
return $types;
}
return $this->filterTypes($types, $this->getTypeCategory($type));
}
protected function getTypeCategory($type)
{
$extensions = $this->extensions;
$navClasses = 'app';
if (isset($type)) {
......@@ -49,7 +54,7 @@ trait RendererTrait
}
}
}
return $this->filterTypes($types, $navClasses);
return $navClasses;
}
protected function filterTypes($types, $navClasses)
......
......@@ -279,4 +279,9 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface
{
return Html::a($text, null, ['href' => $href]);
}
public function getSourceUrl($type)
{
return null;
}
}
......@@ -61,6 +61,11 @@ ArrayHelper::multisort($methods, 'name');
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php if(($sourceUrl = $renderer->getSourceUrl($method->definedBy, $method->startLine)) !== null): ?>
<tr>
<td colspan="3">Source Code: <a href="<?= $sourceUrl ?>"><?= $sourceUrl ?></a></td>
</tr>
<?php endif; ?>
</table>
<!-- --><?php //$this->renderPartial('sourceCode',array('object'=>$method)); ?>
......
......@@ -70,10 +70,12 @@ $renderer = $this->context;
<?php if(!empty($type->since)): ?>
<tr><th>Available since version</th><td><?= $type->since ?></td></tr>
<?php endif; ?>
<?php if(($sourceUrl = $renderer->getSourceUrl($type)) !== null): ?>
<tr>
<th>Source Code</th>
<td><?php // TODO echo $this->renderSourceLink($type->sourcePath) ?></td>
<td><a href="<?= $sourceUrl ?>"><?= $sourceUrl ?></a></td>
</tr>
<?php endif; ?>
</table>
<div id="classDescription">
......
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