Просмотр исходного кода

turned bootstrap template variants into logic

El RIDO 9 лет назад
Родитель
Сommit
67f6c4eb61

+ 1 - 1
cfg/conf.ini.sample

@@ -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

+ 2 - 1
lib/View.php

@@ -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);
         }

+ 0 - 3
tpl/bootstrap-compact-page.php

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

+ 0 - 3
tpl/bootstrap-compact.php

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

+ 0 - 3
tpl/bootstrap-dark-page.php

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

+ 0 - 3
tpl/bootstrap-dark.php

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

+ 0 - 3
tpl/bootstrap-page.php

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

+ 3 - 4
tpl/bootstrap.php

@@ -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>

+ 19 - 0
tst/ViewTest.php

@@ -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()