Skip to content

Commit

Permalink
Coloring response codes
Browse files Browse the repository at this point in the history
  • Loading branch information
paveljanda committed Jul 31, 2016
1 parent 0cabc33 commit 46ad028
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ public function createTemplate($which)
return str_replace(['<', '>'], ['<span class="apiDocu-mask-param">&lt;', '&gt;</span>'], $mask);
});

$template->addFilter('apiDocuResponseCode', function($code) {
if ($code >= 200 && $code <= 202) {
return "<span class=\"apiDocu-code-success\">{$code}</span>";
} else if ($code >= 300 && $code < 500) {
return "<span class=\"apiDocu-code-warning\">{$code}</span>";
} else if ($code >= 500) {
return "<span class=\"apiDocu-code-error\">{$code}</span>";
}

return "<span class=\"apiDocu-code-other\">{$code}</span>";
});

return $template;
}

Expand Down
4 changes: 2 additions & 2 deletions src/templates/api_docu_matched.latte
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
<p class="apiDocu-description">
{foreach $route->getResponseCodes() as $code => $description}
{if is_string($description)}
{$code} <small>({$description})</small>
{$code|apiDocuResponseCode|noescape} <small>({$description})</small>
<br>
{else}
{$description}
{$code|apiDocuResponseCode|noescape}
<br>
{/if}
{/foreach}
Expand Down
4 changes: 2 additions & 2 deletions src/templates/api_docu_one.latte
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
<p class="apiDocu-description">
{foreach $route->getResponseCodes() as $code => $description}
{if is_string($description)}
{$code} <small>({$description})</small>
{$code|apiDocuResponseCode|noescape} <small>({$description})</small>
<br>
{else}
{$description}
{$code|apiDocuResponseCode|noescape}
<br>
{/if}
{/foreach}
Expand Down
12 changes: 12 additions & 0 deletions src/templates/css/api_docu.css
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,15 @@ pre.apiDocu-json {
.apiDocu-comment {
color: #939393;
}

.apiDocu-code-success {
color: #1abc9c;
}

.apiDocu-code-warning {
color: #e67e22;
}

.apiDocu-code-error {
color: #e74c3c;
}

0 comments on commit 46ad028

Please sign in to comment.