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; $data['statusCodes'] = $statusCodes;
} }
if($section = $this->section) { if ($section = $this->section) {
$data['section'] = $section; $data['section'] = $section;
} }

View File

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

View File

@ -111,21 +111,31 @@ class MarkdownFormatter extends AbstractFormatter
protected function render(array $collection) protected function render(array $collection)
{ {
$markdown = ''; $markdown = '';
foreach ($collection as $resource => $arrayOfData) { foreach ($collection as $section => $resources) {
$markdown .= $this->renderResourceSection($resource, $arrayOfData); $markdown .= $this->renderResourceSection($section, $resources);
$markdown .= "\n"; $markdown .= "\n";
} }
return trim($markdown); 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) { foreach ($resources as $resource => $methods) {
$markdown .= $this->renderOne($data); if ('_others' === $section && 'others' !== $resource) {
$markdown .= "\n"; $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; return $markdown;

View File

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

View File

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