diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php index 0d681b1..e63daf8 100644 --- a/Annotation/ApiDoc.php +++ b/Annotation/ApiDoc.php @@ -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; diff --git a/Formatter/AbstractFormatter.php b/Formatter/AbstractFormatter.php index eadc844..f2535d8 100644 --- a/Formatter/AbstractFormatter.php +++ b/Formatter/AbstractFormatter.php @@ -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; } } diff --git a/Resources/public/css/screen.css b/Resources/public/css/screen.css index fcf1848..a41eb11 100644 --- a/Resources/public/css/screen.css +++ b/Resources/public/css/screen.css @@ -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 { diff --git a/Resources/views/resources.html.twig b/Resources/views/resources.html.twig index a602100..eae4c49 100644 --- a/Resources/views/resources.html.twig +++ b/Resources/views/resources.html.twig @@ -1,20 +1,34 @@ {% extends "NelmioApiDocBundle::layout.html.twig" %} {% block content %} - {% for resource, methods in resources %} -
  • -
    -

    {{ resource }}

    + {% for section, sections in resources %} + {% if section != '_others' %} +
    +

    {{ section }}

    + {% endif %} + {% for resource, methods in sections %} +
  • +
    + {% if section == '_others' and resource != 'others' %} +

    {{ resource }}

    + {% endif %} + {% if resource != 'others' %} +

    {{ resource }}

    + {% endif %} +
    + +
  • + {% endfor %} + {% if section != '_others' %} - - + {% endif %} {% endfor %} {% endblock content %}