Skip to content

Commit

Permalink
Making themes also CamelCased
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 15, 2011
1 parent 1930452 commit 6713bb1
Show file tree
Hide file tree
Showing 20 changed files with 25 additions and 30 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Core/App.php
Expand Up @@ -387,11 +387,11 @@ public static function pluginPath($plugin) {
*
* `App::themePath('MyTheme'); will return the full path to the 'MyTheme' theme`
*
* @param string $theme lower_cased theme name to find the path of.
* @param string $theme theme name to find the path of.
* @return string full path to the theme.
*/
public static function themePath($theme) {
$themeDir = 'themed' . DS . Inflector::underscore($theme);
$themeDir = 'Themed' . DS . Inflector::camelize($theme);
foreach (self::$__packages['View'] as $path) {
if (is_dir($path . $themeDir)) {
return $path . $themeDir . DS ;
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Core/AppTest.php
Expand Up @@ -393,11 +393,11 @@ function testThemePath() {
'View' => array(LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS)
));
$path = App::themePath('test_theme');
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS;
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS;
$this->assertEqual($path, $expected);

$path = App::themePath('TestTheme');
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS;
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS;
$this->assertEqual($path, $expected);

App::build();
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Test/Case/Routing/DispatcherTest.php
Expand Up @@ -1227,21 +1227,21 @@ public function testAssets() {
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/flash/theme_test.swf'));
$result = ob_get_clean();

$file = file_get_contents(LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'flash' . DS . 'theme_test.swf');
$file = file_get_contents(LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'flash' . DS . 'theme_test.swf');
$this->assertEqual($file, $result);
$this->assertEqual('this is just a test to load swf file from the theme.', $result);

ob_start();
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs/theme_test.pdf'));
$result = ob_get_clean();
$file = file_get_contents(LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'pdfs' . DS . 'theme_test.pdf');
$file = file_get_contents(LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'pdfs' . DS . 'theme_test.pdf');
$this->assertEqual($file, $result);
$this->assertEqual('this is just a test to load pdf file from the theme.', $result);

ob_start();
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/img/test.jpg'));
$result = ob_get_clean();
$file = file_get_contents(LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg');
$file = file_get_contents(LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg');
$this->assertEqual($file, $result);

ob_start();
Expand Down
16 changes: 8 additions & 8 deletions lib/Cake/Test/Case/View/ThemeViewTest.php
Expand Up @@ -149,18 +149,18 @@ function testPluginThemedGetTemplate() {
$this->Controller->name = 'TestPlugin';
$this->Controller->viewPath = 'Tests';
$this->Controller->action = 'index';
$this->Controller->theme = 'test_theme';
$this->Controller->theme = 'TestTheme';

$ThemeView = new TestThemeView($this->Controller);
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS . 'Plugins' . DS . 'TestPlugin' . DS . 'Tests' . DS .'index.ctp';
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Plugins' . DS . 'TestPlugin' . DS . 'Tests' . DS .'index.ctp';
$result = $ThemeView->getViewFileName('index');
$this->assertEqual($result, $expected);

$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS . 'Plugins' . DS . 'TestPlugin' . DS . 'Layouts' . DS .'plugin_default.ctp';
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Plugins' . DS . 'TestPlugin' . DS . 'Layouts' . DS .'plugin_default.ctp';
$result = $ThemeView->getLayoutFileName('plugin_default');
$this->assertEqual($result, $expected);

$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS . 'Layouts' . DS .'default.ctp';
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS .'default.ctp';
$result = $ThemeView->getLayoutFileName('default');
$this->assertEqual($result, $expected);
}
Expand All @@ -179,16 +179,16 @@ function testGetTemplate() {
$this->Controller->params['pass'] = array('home');

$ThemeView = new TestThemeView($this->Controller);
$ThemeView->theme = 'test_theme';
$ThemeView->theme = 'TestTheme';
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Pages' . DS .'home.ctp';
$result = $ThemeView->getViewFileName('home');
$this->assertEqual($result, $expected);

$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS . 'Posts' . DS .'index.ctp';
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Posts' . DS .'index.ctp';
$result = $ThemeView->getViewFileName('/Posts/index');
$this->assertEqual($result, $expected);

$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'test_theme' . DS . 'Layouts' . DS .'default.ctp';
$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS .'default.ctp';
$result = $ThemeView->getLayoutFileName();
$this->assertEqual($result, $expected);

Expand Down Expand Up @@ -259,7 +259,7 @@ function testMemoryLeakInPaths() {
$this->Controller->name = 'Posts';
$this->Controller->viewPath = 'posts';
$this->Controller->layout = 'whatever';
$this->Controller->theme = 'test_theme';
$this->Controller->theme = 'TestTheme';

$View = new ThemeView($this->Controller);
$View->element('test_element');
Expand Down
12 changes: 6 additions & 6 deletions lib/Cake/Test/Case/View/ViewTest.php
Expand Up @@ -753,14 +753,14 @@ function testViewFileName() {
$result = $View->getViewFileName('index');
$this->assertPattern('/posts(\/|\\\)index.ctp/', $result);

$result = $View->getViewFileName('/pages/home');
$this->assertPattern('/pages(\/|\\\)home.ctp/', $result);
$result = $View->getViewFileName('/Pages/home');
$this->assertPattern('/Pages(\/|\\\)home.ctp/', $result);

$result = $View->getViewFileName('../elements/test_element');
$this->assertPattern('/elements(\/|\\\)test_element.ctp/', $result);
$result = $View->getViewFileName('../Elements/test_element');
$this->assertPattern('/Elements(\/|\\\)test_element.ctp/', $result);

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

$expected = LIBS . 'Test' . DS . 'test_app' . DS . 'View' . DS .'Posts' . DS .'index.ctp';
$result = $View->getViewFileName('../Posts/index');
Expand Down
13 changes: 4 additions & 9 deletions lib/Cake/View/Helper.php
Expand Up @@ -211,15 +211,10 @@ public function webroot($file) {
if (file_exists(Configure::read('App.www_root') . 'theme' . DS . $this->theme . DS . $file)) {
$webPath = "{$this->request->webroot}theme/" . $theme . $asset[0];
} else {
$viewPaths = App::path('views');

foreach ($viewPaths as $viewPath) {
$path = $viewPath . 'themed'. DS . $this->theme . DS . 'webroot' . DS . $file;

if (file_exists($path)) {
$webPath = "{$this->request->webroot}theme/" . $theme . $asset[0];
break;
}
$themePath = App::themePath($this->theme);
$path = $themePath . 'webroot' . DS . $file;
if (file_exists($path)) {
$webPath = "{$this->request->webroot}theme/" . $theme . $asset[0];
}
}
}
Expand Down

0 comments on commit 6713bb1

Please sign in to comment.