Skip to content

Commit

Permalink
Rename action to template.
Browse files Browse the repository at this point in the history
`template` better fits how the property is used in practice.
  • Loading branch information
markstory committed Apr 28, 2014
1 parent a11288b commit a1fcee6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/View/Cell.php
Expand Up @@ -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.
Expand Down Expand Up @@ -137,13 +136,16 @@ public function __construct(Request $request = null, Response $response = null,
/**
* 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();
Expand All @@ -153,7 +155,7 @@ public function render($action = null) {
$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);
}

/**
Expand All @@ -175,7 +177,7 @@ public function __toString() {
public function __debugInfo() {
return [
'plugin' => $this->plugin,
'action' => $this->action,
'template' => $this->template,
'viewClass' => $this->viewClass,
'request' => $this->request,
'response' => $this->response,
Expand Down
2 changes: 1 addition & 1 deletion src/View/CellTrait.php
Expand Up @@ -71,7 +71,7 @@ public function cell($cell, $data = [], $options = []) {
}

$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);
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/View/CellTest.php
Expand Up @@ -64,6 +64,7 @@ public function testCellRender() {
$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);
Expand All @@ -88,10 +89,13 @@ public function testCellWithArguments() {
*/
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);
}

/**
Expand Down

0 comments on commit a1fcee6

Please sign in to comment.