From 57afa1873ef4e7bcc83e95f8328f4c094b93ba8b Mon Sep 17 00:00:00 2001 From: Majna Date: Mon, 7 Nov 2011 01:01:56 +0100 Subject: [PATCH] Make View task use prefixed template before falling back to generic one. It is possible now to create view templates for different prefixes. --- lib/Cake/Console/Command/Task/ViewTask.php | 4 ++++ .../Test/Case/Console/Command/Task/ViewTaskTest.php | 13 +++++++++++-- .../Console/Templates/test/views/admin_edit.ctp | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 lib/Cake/Test/test_app/Console/Templates/test/views/admin_edit.ctp diff --git a/lib/Cake/Console/Command/Task/ViewTask.php b/lib/Cake/Console/Command/Task/ViewTask.php index b30d450701e..fff2572e8de 100644 --- a/lib/Cake/Console/Command/Task/ViewTask.php +++ b/lib/Cake/Console/Command/Task/ViewTask.php @@ -393,6 +393,10 @@ public function getTemplate($action) { if (!empty($this->template) && $action != $this->template) { return $this->template; } + $themePath = $this->Template->getThemePath(); + if (file_exists($themePath . 'views' . DS . $action . '.ctp')) { + return $action; + } $template = $action; $prefixes = Configure::read('Routing.prefixes'); foreach ((array)$prefixes as $prefix) { diff --git a/lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php index 1652b9267a0..57d254468a7 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php @@ -230,6 +230,7 @@ public function setUp() { $this->Task->path = TMP; $this->Task->Template->params['theme'] = 'default'; + $this->Task->Template->templatePaths = array('default' => CAKE . 'Console' . DS . 'Templates' . DS . 'default' .DS); } /** @@ -563,7 +564,7 @@ public function testExecuteWithControllerVariations($name) { } /** - * test `cake bake view $controller -admin` + * test `cake bake view $controller --admin` * Which only bakes admin methods, not non-admin methods. * * @return void @@ -701,7 +702,7 @@ public function testExecuteInteractiveWithAdmin() { } /** - * test getting templates, make sure noTemplateActions works + * test getting templates, make sure noTemplateActions works and prefixed template is used before generic one. * * @return void */ @@ -716,6 +717,14 @@ public function testGetTemplate() { $result = $this->Task->getTemplate('admin_add'); $this->assertEqual($result, 'form'); + + $this->Task->Template->templatePaths = array( + 'test' => CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Templates' . DS . 'test' .DS + ); + $this->Task->Template->params['theme'] = 'test'; + + $result = $this->Task->getTemplate('admin_edit'); + $this->assertEqual($result, 'admin_edit'); } } diff --git a/lib/Cake/Test/test_app/Console/Templates/test/views/admin_edit.ctp b/lib/Cake/Test/test_app/Console/Templates/test/views/admin_edit.ctp new file mode 100644 index 00000000000..0d7ec6739d4 --- /dev/null +++ b/lib/Cake/Test/test_app/Console/Templates/test/views/admin_edit.ctp @@ -0,0 +1 @@ +admin_edit template \ No newline at end of file