From c629d2c820c7c93877cdaa55a98f8750b3a9870b Mon Sep 17 00:00:00 2001 From: AD7six Date: Tue, 28 Jul 2009 09:02:29 +0200 Subject: [PATCH] allow overriding the default templates Allow templates to be distributed as plugins Prevent any folder named skel or something_skel, or not containing any of the folders that bake is expecting, from being considered a theme. --- cake/console/libs/tasks/template.php | 29 ++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/cake/console/libs/tasks/template.php b/cake/console/libs/tasks/template.php index 1b7ea0b97..3f94fbdca 100644 --- a/cake/console/libs/tasks/template.php +++ b/cake/console/libs/tasks/template.php @@ -53,18 +53,39 @@ class TemplateTask extends Shell { **/ function _findThemes() { $paths = App::path('shells'); - array_unshift($paths, CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS); + $core = array_pop($paths); + $core = str_replace('libs' . DS, '', $core); + $paths[] = $core; + $Folder =& new Folder($core . 'templates' . DS . 'default'); + $contents = $Folder->read(); + $themeFolders = $contents[0]; + + $pluginPaths = App::path('plugins'); + foreach($pluginPaths as $path) { + $paths[] = $path . 'vendors' . DS . 'shells' . DS; + } + + // TEMPORARY TODO remove when all paths are DS terminated + foreach($paths as &$path) { + $path = rtrim($path, DS) . DS; + } + $themes = array(); foreach ($paths as $path) { $Folder =& new Folder($path . 'templates', false); $contents = $Folder->read(); $subDirs = $contents[0]; foreach ($subDirs as $dir) { - if (empty($dir) || $dir == 'skel') { + if (empty($dir) || preg_match('@^skel$|_skel$@', $dir)) { continue; } - $templateDir = $path . 'templates' . DS . $dir . DS; - $themes[$dir] = $templateDir; + $Folder =& new Folder($path . 'templates' . DS . $dir); + $contents = $Folder->read(); + $subDirs = $contents[0]; + if (array_intersect($contents[0], $themeFolders)) { + $templateDir = $path . 'templates' . DS . $dir . DS; + $themes[$dir] = $templateDir; + } } } return $themes;