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

@ -144,6 +144,7 @@ abstract class AbstractFormatter implements FormatterInterface
}
ksort($processedCollection);
return $processedCollection;
}
}

View File

@ -111,22 +111,32 @@ 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);
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

@ -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_