Added ability to extract inline documentation from docblock

This commit is contained in:
Samuel Gordalina 2012-07-13 13:32:53 +01:00
parent 4fdc526b42
commit 2b02733ee9
5 changed files with 55 additions and 0 deletions

View File

@ -31,6 +31,11 @@ class ApiDoc
*/
private $description = null;
/**
* @var string
*/
private $documentation = null;
/**
* @var Boolean
*/
@ -92,6 +97,22 @@ class ApiDoc
$this->description = $description;
}
/**
* @return string|null
*/
public function getDocumentation()
{
return $this->documentation;
}
/**
* @param string $documentation
*/
public function setDocumentation($documentation)
{
$this->documentation = $documentation;
}
/**
* @return Boolean
*/

View File

@ -193,6 +193,8 @@ class ApiDocExtractor
}
}
$annotation->setDocumentation($this->getDocCommentText($method));
$paramDocs = array();
foreach (explode("\n", $docblock) as $line) {
if (preg_match('{^@param (.+)}', trim($line), $matches)) {
@ -220,4 +222,19 @@ class ApiDocExtractor
return $comment;
}
protected function getDocCommentText(\Reflector $reflected)
{
$comment = $reflected->getDocComment();
// let's clean the doc block
$comment = str_replace('/**', '', $comment);
$comment = str_replace('*/', '', $comment);
$comment = preg_replace('/^\s*\* ?/m', '', $comment);
// Remove everything (and including) first annotation
$comment = preg_replace('/\n?\s*@[^\s]+.+/ms', '', $comment);
return trim($comment);
}
}

View File

@ -138,6 +138,10 @@ abstract class AbstractFormatter implements FormatterInterface
$data['description'] = $description;
}
if ($documentation = $apiDoc->getDocumentation()) {
$data['documentation'] = $documentation;
}
return $data;
}
}

View File

@ -26,6 +26,14 @@ class MarkdownFormatter extends AbstractFormatter
$markdown .= "\n\n";
if (isset($data['documentation']) && !empty($data['documentation'])) {
$markdown .= "#### Documentation ####\n\n";
foreach (explode("\n", $data['documentation']) as $line) {
$markdown .= "\t" . $line . "\n";
}
}
if (isset($data['requirements']) && !empty($data['requirements'])) {
$markdown .= "#### Requirements ####\n\n";

View File

@ -23,6 +23,11 @@
<div class="panes">
<div class="pane content selected">
{% if data.documentation is defined and data.documentation is not empty %}
<h4>Documentation</h4>
<pre>{{ data.documentation }}</pre>
{% endif %}
{% if data.requirements is defined and data.requirements is not empty %}
<h4>Requirements</h4>
<table class="fullwidth">