Skip to content

Commit

Permalink
Themes are now plugins, this unifies the intallation experience and
Browse files Browse the repository at this point in the history
loading syntax
  • Loading branch information
lorenzo committed May 20, 2014
1 parent 2f8a72b commit 5f60225
Show file tree
Hide file tree
Showing 20 changed files with 15 additions and 17 deletions.
21 changes: 11 additions & 10 deletions src/View/View.php
Expand Up @@ -1096,31 +1096,32 @@ protected function _paths($plugin = null, $cached = true) {
if (!empty($plugin)) {
$count = count($viewPaths);
for ($i = 0; $i < $count; $i++) {
if (!in_array($viewPaths[$i], $corePaths)) {
$paths[] = $viewPaths[$i] . 'Plugin' . DS . $plugin . DS;
}
$paths[] = $viewPaths[$i] . 'Plugin' . DS . $plugin . DS;
}
$paths = array_merge($paths, App::path('Template', $plugin));
}

$paths = array_unique(array_merge($paths, $viewPaths));
if (!empty($this->theme)) {
$theme = Inflector::camelize($this->theme);
$themePaths = array();
foreach ($paths as $path) {
if (strpos($path, DS . 'Plugin' . DS) === false) {
if ($plugin) {
$themePaths[] = $path . 'Themed' . DS . $theme . DS . 'Plugin' . DS . $plugin . DS;
}
$themePaths[] = $path . 'Themed' . DS . $theme . DS;
$themePaths = App::path('Template', $theme);

if ($plugin) {
$count = count($viewPaths);
for ($i = 0; $i < $count; $i++) {
$themePaths[] = $themePaths[$i] . 'Plugin' . DS . $plugin . DS;
}
}

$paths = array_merge($themePaths, $paths);
}

$paths = array_merge($paths, $corePaths);

if ($plugin !== null) {
return $this->_pathsForPlugin[$plugin] = $paths;
}

return $this->_paths = $paths;
}

Expand Down
11 changes: 4 additions & 7 deletions tests/TestCase/View/ViewTest.php
Expand Up @@ -272,7 +272,7 @@ public function setUp() {

App::objects('Plugin', null, false);

Plugin::load(array('TestPlugin', 'TestPlugin', 'PluginJs'));
Plugin::load(array('TestPlugin', 'TestPlugin', 'PluginJs', 'TestTheme'));
Configure::write('debug', true);
}

Expand Down Expand Up @@ -314,11 +314,11 @@ public function testGetTemplate() {
$result = $ThemeView->getViewFileName('home');
$this->assertPathEquals($expected, $result);

$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Posts' . DS . 'index.ctp';
$expected = Plugin::path('TestTheme') . 'Template' . DS . 'Posts' . DS . 'index.ctp';
$result = $ThemeView->getViewFileName('/Posts/index');
$this->assertPathEquals($expected, $result);

$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layout' . DS . 'default.ctp';
$expected = Plugin::path('TestTheme') . 'Template' . DS . 'Layout' . DS . 'default.ctp';
$result = $ThemeView->getLayoutFileName();
$this->assertPathEquals($expected, $result);

Expand Down Expand Up @@ -370,7 +370,7 @@ public function testPluginThemedGetTemplate() {
];

$ThemeView = new TestThemeView(null, null, null, $viewOptions);
$themePath = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Themed' . DS . 'TestTheme' . DS;
$themePath = Plugin::path('TestTheme') . 'Template' . DS;

$expected = $themePath . 'Plugin' . DS . 'TestPlugin' . DS . 'Tests' . DS . 'index.ctp';
$result = $ThemeView->getViewFileName('index');
Expand Down Expand Up @@ -1052,9 +1052,6 @@ public function testViewFileName() {
$result = $View->getViewFileName('../Element/test_element');
$this->assertRegExp('/Element(\/|\\\)test_element.ctp/', $result);

$result = $View->getViewFileName('../Themed/TestTheme/Posts/index');
$this->assertRegExp('/Themed(\/|\\\)TestTheme(\/|\\\)Posts(\/|\\\)index.ctp/', $result);

$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Posts' . DS . 'index.ctp';
$result = $View->getViewFileName('../Posts/index');
$this->assertPathEquals($expected, $result);
Expand Down

0 comments on commit 5f60225

Please sign in to comment.