Skip to content

Commit

Permalink
Adding App::themePath(). Will be used to reduce code duplication in a…
Browse files Browse the repository at this point in the history
… variety of places.
  • Loading branch information
markstory committed Jul 1, 2010
1 parent e023350 commit 91f8e22
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cake/libs/configure.php
Expand Up @@ -702,7 +702,7 @@ function build($paths = array(), $reset = false) {
/**
* Get the path that a plugin is on. Searches through the defined plugin paths.
*
* @param string $plugin CamelCased plugin name to find the path of.
* @param string $plugin CamelCased/lower_cased plugin name to find the path of.
* @return string full path to the plugin.
*/
function pluginPath($plugin) {
Expand All @@ -716,6 +716,23 @@ function pluginPath($plugin) {
return $_this->plugins[0] . $pluginDir . DS;
}

/**
* Find the path that a theme is on. Search through the defined theme paths.
*
* @param string $theme lower_cased theme name to find the path of.
* @return string full path to the theme.
*/
function themePath($theme) {
$_this =& App::getInstance();
$themeDir = 'themed' . DS . Inflector::underscore($theme);
for ($i = 0, $length = count($_this->views); $i < $length; $i++) {
if (is_dir($_this->views[$i] . $themeDir)) {
return $_this->views[$i] . $themeDir . DS ;
}
}
return $_this->views[0] . $themeDir . DS;
}

/**
* Returns a key/value list of all paths where core libs are found.
* Passing $type only returns the values for a given value of $key.
Expand Down
20 changes: 20 additions & 0 deletions cake/tests/cases/libs/configure.test.php
Expand Up @@ -460,6 +460,26 @@ function testPluginPath() {
App::build();
}

/**
* test that pluginPath can find paths for plugins.
*
* @return void
*/
function testThemePath() {
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS)
));
$path = App::themePath('test_theme');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
$this->assertEqual($path, $expected);

$path = App::themePath('TestTheme');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
$this->assertEqual($path, $expected);

App::build();
}

/**
* testClassLoading method
*
Expand Down

0 comments on commit 91f8e22

Please sign in to comment.