turned bootstrap template variants into logic

This commit is contained in:
El RIDO 2017-01-08 10:02:07 +01:00
parent 87fad1fb77
commit 67f6c4eb61
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
9 changed files with 25 additions and 21 deletions

View file

@ -31,7 +31,7 @@ defaultformatter = "plaintext"
; size limit per paste or comment in bytes, defaults to 2 Mebibytes
sizelimit = 2097152
; template to include, default is "bootstrap" (tpl/bootstrap.html)
; template to include, default is "bootstrap" (tpl/bootstrap.php)
template = "bootstrap"
; (optional) notice to display

View file

@ -52,7 +52,8 @@ class View
*/
public function draw($template)
{
$path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $template . '.php';
$file = substr($template, 0, 9) === 'bootstrap' ? 'bootstrap' : $template;
$path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php';
if (!file_exists($path)) {
throw new Exception('Template ' . $template . ' not found!', 80);
}

View file

@ -1,3 +0,0 @@
<?php
$tpl = 'bootstrap-compact-page';
include 'bootstrap.php';

View file

@ -1,3 +0,0 @@
<?php
$tpl = 'bootstrap-compact';
include 'bootstrap.php';

View file

@ -1,3 +0,0 @@
<?php
$tpl = 'bootstrap-dark-page';
include 'bootstrap.php';

View file

@ -1,3 +0,0 @@
<?php
$tpl = 'bootstrap-dark';
include 'bootstrap.php';

View file

@ -1,3 +0,0 @@
<?php
$tpl = 'bootstrap-page';
include 'bootstrap.php';

View file

@ -1,9 +1,8 @@
<?php
use PrivateBin\I18n;
if (!isset($tpl)) $tpl = 'bootstrap';
$isCpct = substr($tpl, 9, 8) === '-compact';
$isDark = substr($tpl, 9, 5) === '-dark';
$isPage = substr($tpl, -5) === '-page';
$isCpct = substr($template, 9, 8) === '-compact';
$isDark = substr($template, 9, 5) === '-dark';
$isPage = substr($template, -5) === '-page';
?><!DOCTYPE html>
<html lang="en">
<head>

View file

@ -67,6 +67,25 @@ class ViewTest extends PHPUnit_Framework_TestCase
ob_end_clean();
}
}
// check bootstrap variants
$template = 'bootstrap-page';
ob_start();
$page->draw($template);
$this->_content[$template] = ob_get_contents();
ob_end_clean();
foreach (array('-dark', '-compact') as $suffix) {
$template = 'bootstrap' . $suffix;
ob_start();
$page->draw($template);
$this->_content[$template] = ob_get_contents();
ob_end_clean();
$template .= '-page';
ob_start();
$page->draw($template);
$this->_content[$template] = ob_get_contents();
ob_end_clean();
}
}
public function tearDown()