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

View File

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

View File

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

View File

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