Merge pull request #138 from drgomesp/section-grouping

Section grouping
This commit is contained in:
William DURAND 2013-03-17 16:13:56 +01:00
commit 8c9b8331d0
4 changed files with 80 additions and 19 deletions

View File

@ -56,6 +56,13 @@ class ApiDoc
*/ */
private $description = null; private $description = null;
/**
* Section to group actions together.
*
* @var string
*/
private $section = null;
/** /**
* Extended documentation. * Extended documentation.
* *
@ -139,6 +146,10 @@ class ApiDoc
if (isset($data['authentication'])) { if (isset($data['authentication'])) {
$this->setAuthentication((bool) $data['authentication']); $this->setAuthentication((bool) $data['authentication']);
} }
if (isset($data['section'])) {
$this->section = $data['section'];
}
} }
/** /**
@ -208,6 +219,22 @@ class ApiDoc
$this->description = $description; $this->description = $description;
} }
/**
* @param string $section
*/
public function setSection($section)
{
$this->section = $section;
}
/**
* @return string
*/
public function getSection()
{
return $this->section;
}
/** /**
* @param string $documentation * @param string $documentation
*/ */
@ -339,6 +366,10 @@ class ApiDoc
$data['statusCodes'] = $statusCodes; $data['statusCodes'] = $statusCodes;
} }
if($section = $this->section) {
$data['section'] = $section;
}
$data['https'] = $this->https; $data['https'] = $this->https;
$data['authentication'] = $this->authentication; $data['authentication'] = $this->authentication;

View File

@ -127,16 +127,23 @@ abstract class AbstractFormatter implements FormatterInterface
{ {
$array = array(); $array = array();
foreach ($collection as $coll) { foreach ($collection as $coll) {
$array[$coll['resource']][] = $coll['annotation']->toArray(); $array[$coll['annotation']->getSection()][$coll['resource']][] = $coll['annotation']->toArray();
} }
$processedCollection = array(); $processedCollection = array();
foreach ($array as $path => $annotations) { foreach ($array as $section => $resources) {
foreach ($annotations as $annotation) { foreach ($resources as $path => $annotations) {
$processedCollection[$path][] = $this->processAnnotation($annotation); foreach ($annotations as $annotation) {
if($section) {
$processedCollection[$section][$path][] = $this->processAnnotation($annotation);
} else {
$processedCollection['_others'][$path][] = $this->processAnnotation($annotation);
}
}
} }
} }
ksort($processedCollection);
return $processedCollection; return $processedCollection;
} }
} }

View File

@ -169,7 +169,16 @@ table tbody tr:last-child td {
font-size: 0.9em; font-size: 0.9em;
} }
#section {
border: 1px solid #ddd;
background: #f8f8f8;
padding: 5px 20px;
margin-bottom: 15px;
}
li.resource { li.resource {
width: 100%;
margin-bottom: 10px;
border-bottom: 1px solid #dddddd; border-bottom: 1px solid #dddddd;
} }
li.resource:last-child { li.resource:last-child {
@ -226,7 +235,7 @@ li.operation {
clear: both; clear: both;
overflow: hidden; overflow: hidden;
display: block; display: block;
margin: 0 0 10px 0; margin: 0 0 10px;
padding: 0 0 0 0; padding: 0 0 0 0;
} }
li.operation div.heading { li.operation div.heading {

View File

@ -1,20 +1,34 @@
{% extends "NelmioApiDocBundle::layout.html.twig" %} {% extends "NelmioApiDocBundle::layout.html.twig" %}
{% block content %} {% block content %}
{% for resource, methods in resources %} {% for section, sections in resources %}
<li class="resource"> {% if section != '_others' %}
<div class="heading"> <div id="section">
<h2>{{ resource }}</h2> <h1>{{ section }}</h1>
{% endif %}
{% for resource, methods in sections %}
<li class="resource">
<div class="heading">
{% if section == '_others' and resource != 'others' %}
<h2>{{ resource }}</h2>
{% endif %}
{% if resource != 'others' %}
<h2>{{ resource }}</h2>
{% endif %}
</div>
<ul class="endpoints">
<li class="endpoint">
<ul class="operations">
{% for data in methods %}
{% include 'NelmioApiDocBundle::method.html.twig' %}
{% endfor %}
</ul>
</li>
</ul>
</li>
{% endfor %}
{% if section != '_others' %}
</div> </div>
<ul class="endpoints"> {% endif %}
<li class="endpoint">
<ul class="operations">
{% for data in methods %}
{% include 'NelmioApiDocBundle::method.html.twig' %}
{% endfor %}
</ul>
</li>
</ul>
</li>
{% endfor %} {% endfor %}
{% endblock content %} {% endblock content %}