1
0
فهرست منبع

Tidy up template output after running

Nathaniel van Diepen 7 سال پیش
والد
کامیت
889b768fae
1فایلهای تغییر یافته به همراه30 افزوده شده و 0 حذف شده
  1. 30 0
      Data/template.class.php

+ 30 - 0
Data/template.class.php

@@ -10,6 +10,25 @@
 		private static $templates = [];
 		public static $cachedir;
 		public static $basedir = __DIR__;
+		private static $tidy;
+		private static $tidyConfig = [
+			'indent'=>true,
+			'tab-size'=>4,
+			'wrap'=>0,
+			'wrap-asp'=>false,
+			'wrap-attributes'=>false,
+			'wrap-jste'=>false,
+			'wrap-php'=>false,
+			'wrap-script-literals'=>false,
+			'wrap-sections'=>false,
+			'char-encoding'=>'utf8',
+			'newline'=>'LF',
+			'tidy-mark'=>true,
+			'merge-divs'=>false,
+			'merge-spans'=>false,
+			'logical-emphasis'=>false,
+			'literal-attributes'=>true
+		];
 		private static $regex = [
 			'match'=>'/\{([^#\/?_][^}\n]*?)\}/i',
 			'parentmatch'=>'/\{\.\.\/([^#\/?_][^}\n]*?)\}/i',
@@ -233,6 +252,17 @@
 				file_put_contents($this->path, static::compile($this->template));
 				$output = static::execute($this->path, $data);
 			}
+			if(class_exists('tidy')){
+				if(is_null(static::$tidy)){
+					static::$tidy = new \tidy();
+				}
+				$tidy = static::$tidy;
+				$tidy->parseString($output, static::$tidyConfig);
+				if(!$tidy->cleanRepair()){
+					throw new \Exception($tidy->errorBuffer);
+				}
+				$output = "{$tidy}";
+			}
 			if($this->fire('after', $output) === false){
 				throw new Exception("Render on template {$this->name} cancelled. After");
 			}