ソースを参照

ul/li indentation only for debug mode

euromark 13 年 前
コミット
f0b2c1a935
2 ファイル変更19 行追加6 行削除
  1. 10 0
      Test/Case/View/Helper/TreeHelperTest.php
  2. 9 6
      View/Helper/TreeHelper.php

+ 10 - 0
Test/Case/View/Helper/TreeHelperTest.php

@@ -230,4 +230,14 @@ TEXT;
 		$this->assertTextEquals($expected, $output);
 	}
 
+	public function testGenerateProductive() {
+		$tree = $this->Model->find('threaded');
+
+		$expected = '<ul><li>One<ul><li>One-SubA</li></ul></li><li>Two<ul><li>Two-SubA<ul><li>Two-SubA-1<ul><li>Two-SubA-1-1</li></ul></li></ul></li></ul></li><li>Three</li><li>Four<ul><li>Four-SubA</li></ul></li></ul>';
+
+		$output = $this->Tree->generate($tree, array('indent' => false));
+
+		$this->assertTextEquals($expected, $output);
+	}
+
 }

+ 9 - 6
View/Helper/TreeHelper.php

@@ -113,7 +113,7 @@ class TreeHelper extends AppHelper {
 			'indent' => null,
 			'splitDepth' => false,
 			'splitCount' => null,
-			'totalNodes' => false
+			'totalNodes' => null
 		), (array)$settings);
 		if ($this->_settings['autoPath'] && !isset($this->_settings['autoPath'][2])) {
 			$this->_settings['autoPath'][2] = 'active';
@@ -134,9 +134,6 @@ class TreeHelper extends AppHelper {
 				}
 			}
 		}
-		if (!$model) {
-			$model = '_NULL_';
-		}
 		$this->_settings['model'] = $model;
 
 		$this->_itemAttributes = $this->_typeAttributes = $this->_typeAttributesNext = array();
@@ -264,7 +261,10 @@ class TreeHelper extends AppHelper {
 					$return .= $this->_suffix();
 					$return .= $this->generate($result['children'], $settings);
 					if ($itemType) {
-						$return .= $whiteSpace . "\t" . '</' . $itemType . '>';
+						if ($indent) {
+							$return .= $whiteSpace . "\t";
+						}
+						$return .= '</' . $itemType . '>';
 					}
 				} elseif ($numberOfTotalChildren) {
 					$_addType = true;
@@ -296,7 +296,10 @@ class TreeHelper extends AppHelper {
 			$return .= "\r\n";
 		}
 		if ($return && $type) {
-			$return .= $whiteSpace . '</' . $type . '>';
+			if ($indent) {
+				$return .= $whiteSpace;
+			}
+			$return .= '</' . $type . '>';
 			if ($indent) {
 				$return .= "\r\n";
 			}