Use template for HTML

master
Gilles Crettenand 11 years ago committed by Gilles Crettenand
parent 34161ba282
commit 2a802ee5e1

@ -18,12 +18,14 @@ class Html extends Formatter {
$first = reset($data);
$single = ! is_array($first);
$content = '<table><thead>';
$content = '<table class="table table-striped table-hover"><thead>';
if($single) {
$content .= "<tr><th>Field</th><th>Value</th></tr>";
} else {
$columns = array_keys($first);
$content .= '<tr>';
foreach(array_keys($first) as $k) {
foreach($columns as $k) {
$content .= "<th>$k</th>";
}
$content .= '</tr>';
@ -36,8 +38,14 @@ class Html extends Formatter {
} else {
foreach($data as $row) {
$content .= '<tr>';
foreach($row as $col) {
$content .= '<td>'.print_r($col, true).'</td>';
foreach($columns as $c) {
$v = print_r(isset($row[$c]) ? $row[$c] : '', true);
$limit = 50;
if(strlen($v) > $limit) {
$v = substr($v, 0, $limit).' [...]';
}
$content .= "<td>$v</td>";
}
$content .= '</tr>';
}
@ -75,6 +83,17 @@ class Html extends Formatter {
$content = '<h1>Unable to render this</h1>';
}
echo $content;
$html = file_get_contents('template.html');
$context = array(
'title' => 'BSR - WebService',
'content' => $content
);
foreach($context as $k => $v) {
$html = str_replace("{{ $k }}", $v, $html);
}
echo $html;
}
}

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>BSR WebService - {{ title }}</title>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
{{ content }}
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
</body>
</html>
Loading…
Cancel
Save