Browse Source

Rename action to template.

`template` better fits how the property is used in practice.
mark_story 12 years ago
parent
commit
a1fcee6b81
3 changed files with 17 additions and 11 deletions
  1. 12 10
      src/View/Cell.php
  2. 1 1
      src/View/CellTrait.php
  3. 4 0
      tests/TestCase/View/CellTest.php

+ 12 - 10
src/View/Cell.php

@@ -40,13 +40,12 @@ abstract class Cell {
 	public $View;
 
 /**
- * Name of the action that was invoked.
- *
- * Action name will be inflected to get the template name when rendering.
+ * Name of the template that will be rendered.
+ * This property is inflected from the action name that was invoked.
  *
  * @var string
  */
-	public $action;
+	public $template;
 
 /**
  * Automatically set to the name of a plugin.
@@ -137,13 +136,16 @@ abstract class Cell {
 /**
  * Render the cell.
  *
- * @param string $action Custom template name to render. If not provided (null), the last
+ * @param string $template Custom template name to render. If not provided (null), the last
  * value will be used. This value is automatically set by `CellTrait::cell()`.
  * @return void
  */
-	public function render($action = null) {
-		if ($action !== null) {
-			$this->action = $action;
+	public function render($template = null) {
+		if ($template !== null) {
+			$template = Inflector::underscore($template);
+		}
+		if (empty($template)) {
+			$template = $this->template;
 		}
 
 		$this->View = $this->createView();
@@ -153,7 +155,7 @@ abstract class Cell {
 		$className = array_pop($className);
 		$this->View->subDir = 'Cell' . DS . substr($className, 0, strpos($className, 'Cell'));
 
-		return $this->View->render(Inflector::underscore($this->action));
+		return $this->View->render($template);
 	}
 
 /**
@@ -175,7 +177,7 @@ abstract class Cell {
 	public function __debugInfo() {
 		return [
 			'plugin' => $this->plugin,
-			'action' => $this->action,
+			'template' => $this->template,
 			'viewClass' => $this->viewClass,
 			'request' => $this->request,
 			'response' => $this->response,

+ 1 - 1
src/View/CellTrait.php

@@ -71,7 +71,7 @@ trait CellTrait {
 		}
 
 		$cellInstance = new $className($this->request, $this->response, $this->getEventManager(), $options);
-		$cellInstance->action = Inflector::underscore($action);
+		$cellInstance->template = Inflector::underscore($action);
 		$cellInstance->plugin = !empty($plugin) ? $plugin : null;
 		$cellInstance->theme = !empty($this->theme) ? $this->theme : null;
 		$length = count($data);

+ 4 - 0
tests/TestCase/View/CellTest.php

@@ -64,6 +64,7 @@ class CellTest extends TestCase {
 		$cell = $this->View->cell('Articles::teaserList');
 		$render = "{$cell}";
 
+		$this->assertEquals('teaser_list', $cell->template);
 		$this->assertContains('<h2>Lorem ipsum</h2>', $render);
 		$this->assertContains('<h2>Usectetur adipiscing eli</h2>', $render);
 		$this->assertContains('<h2>Topis semper blandit eu non</h2>', $render);
@@ -88,10 +89,13 @@ class CellTest extends TestCase {
  */
 	public function testDefaultCellAction() {
 		$appCell = $this->View->cell('Articles');
+
+		$this->assertEquals('display', $appCell->template);
 		$this->assertContains('dummy', "{$appCell}");
 
 		$pluginCell = $this->View->cell('TestPlugin.Dummy');
 		$this->assertContains('dummy', "{$pluginCell}");
+		$this->assertEquals('display', $pluginCell->template);
 	}
 
 /**