Fix 8c9b8331d066269d48ca374280937be264767ee6

* tests
* CS
This commit is contained in:
William DURAND 2013-03-17 16:40:31 +01:00
parent 8c9b8331d0
commit 2fd3f33ad8
5 changed files with 23 additions and 15 deletions

View File

@ -366,7 +366,7 @@ class ApiDoc
$data['statusCodes'] = $statusCodes;
}
if($section = $this->section) {
if ($section = $this->section) {
$data['section'] = $section;
}

View File

@ -134,7 +134,7 @@ abstract class AbstractFormatter implements FormatterInterface
foreach ($array as $section => $resources) {
foreach ($resources as $path => $annotations) {
foreach ($annotations as $annotation) {
if($section) {
if ($section) {
$processedCollection[$section][$path][] = $this->processAnnotation($annotation);
} else {
$processedCollection['_others'][$path][] = $this->processAnnotation($annotation);
@ -143,7 +143,8 @@ abstract class AbstractFormatter implements FormatterInterface
}
}
ksort($processedCollection);
ksort($processedCollection);
return $processedCollection;
}
}

View File

@ -111,21 +111,31 @@ class MarkdownFormatter extends AbstractFormatter
protected function render(array $collection)
{
$markdown = '';
foreach ($collection as $resource => $arrayOfData) {
$markdown .= $this->renderResourceSection($resource, $arrayOfData);
foreach ($collection as $section => $resources) {
$markdown .= $this->renderResourceSection($section, $resources);
$markdown .= "\n";
}
return trim($markdown);
}
private function renderResourceSection($resource, array $arrayOfData)
private function renderResourceSection($section, array $resources)
{
$markdown = sprintf("# %s #\n\n", $resource);
if ('_others' !== $section) {
$markdown = sprintf("# %s #\n\n", $section);
}
foreach ($arrayOfData as $data) {
$markdown .= $this->renderOne($data);
$markdown .= "\n";
foreach ($resources as $resource => $methods) {
if ('_others' === $section && 'others' !== $resource) {
$markdown = sprintf("## %s ##\n\n", $resource);
} elseif ('others' !== $resource) {
$markdown = sprintf("## %s ##\n\n", $resource);
}
foreach ($methods as $method) {
$markdown .= $this->renderOne($method);
$markdown .= "\n";
}
}
return $markdown;

View File

@ -29,6 +29,6 @@
{% endfor %}
{% if section != '_others' %}
</div>
{% endif %}
{% endif %}
{% endfor %}
{% endblock content %}

View File

@ -26,7 +26,7 @@ class MarkdownFormatterTest extends WebTestCase
$result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->format($data);
$expected = <<<MARKDOWN
# /tests #
## /tests ##
### `GET` /tests.{_format} ###
@ -126,9 +126,6 @@ c:
* required: true
# others #
### `POST` /another-post ###
_create another test_