Permalink
Browse files

Merge pull request #2 from chillu/ss3-fixes

FEATURE: Nested modules support. ENHANCEMENT: automatic building in LeftAndMain by attaching decorator
  • Loading branch information...
2 parents c775a36 + 75682fe commit 3a6fd07f7c046712fb03468b42332f215e794834 @wilr wilr committed May 9, 2011
Showing with 22 additions and 18 deletions.
  1. +2 −1 _config.php
  2. +20 −17 code/Compass.php
View
@@ -1,7 +1,8 @@
<?php
// This triggers compass rebuilding when a ContentController is accessed
-Object::add_extension('SiteTree', 'Compass_RebuildDecorator');
+if(class_exists('SiteTree')) Object::add_extension('SiteTree', 'Compass_RebuildDecorator');
+if(class_exists('LeftAndMain')) Object::add_extension('LeftAndMain', 'Compass_RebuildDecorator');
// Add the dev/compass tools into the URL map
Director::addRules(20, array('dev/compass' => 'Compass'));
View
@@ -179,24 +179,23 @@ protected function getAllThemes() {
/**
* Utility function that returns an array of all modules.
- * Logic taken from sapphire/dev/ModelViewer.php
+ *
+ * @return array Map of module names to their path
*/
protected function getAllModules() {
$modules = array();
if(class_exists('SS_ClassLoader')) {
// SilverStripe 3.x
- $classes = SS_ClassLoader::instance()->getManifest()->getClasses();
- $paths = array_values($classes);
+ $modules = SS_ClassLoader::instance()->getManifest()->getModules();
} else {
// SilverStripe 2.x
global $_CLASS_MANIFEST;
$paths = $_CLASS_MANIFEST;
- }
-
- foreach ($paths as $path) {
- if (preg_match('#'.preg_quote(BASE_PATH, '#').'/([^/]+)/#', $path, $matches)) {
- $modules[$matches[1]] = $matches[1];
+ foreach ($paths as $path) {
+ if (preg_match('#'.preg_quote(BASE_PATH, '#').'/([^/]+)/#', $path, $matches)) {
+ $modules[$matches[1]] = BASE_PATH . DIRECTORY_SEPARATOR . $matches[1];
+ }
}
}
@@ -214,7 +213,7 @@ protected function getAllModules() {
function rebuild($verbose = false) {
// Make sure the gems we need are available
if (($error = $this->checkGems()) !== true) return self::error($error);
-
+
$dir = null;
if (@$_GET['theme']) $dir = THEMES_PATH . DIRECTORY_SEPARATOR . $_GET['theme'];
if (@$_GET['module']) $dir = BASE_PATH . DIRECTORY_SEPARATOR . $_GET['module'];
@@ -234,14 +233,13 @@ function rebuild($verbose = false) {
}
}
- foreach ($this->getAllModules() as $module) {
+ foreach ($this->getAllModules() as $name => $path) {
// If this is in the compass module, skip
- if ($module == 'compass') continue;
- $dir = BASE_PATH . DIRECTORY_SEPARATOR . $module;
+ if ($name == 'compass') continue;
- if (file_exists($dir . DIRECTORY_SEPARATOR . 'config.rb')) {
- if ($verbose) echo "\nRebuilding module: $module\n";
- $this->rebuildDirectory($dir);
+ if (file_exists($path . DIRECTORY_SEPARATOR . 'config.rb')) {
+ if ($verbose) echo "\nRebuilding module: $name\n";
+ $this->rebuildDirectory($path);
}
}
}
@@ -305,6 +303,7 @@ protected function generate_config($dir) {
/**
* Hook in logic to potentially rebuild css from compass files when a request is received.
+ * Works both with {@link LeftAndMain} and {@link ContentController} classes.
*
* Rebuild on request happens if sapphire is in dev mode or flush is passed as a GET variable, except when
* Compass::$force_no_rebuild is true, or we're currently running a test
@@ -313,15 +312,19 @@ protected function generate_config($dir) {
*/
class Compass_RebuildDecorator extends DataObjectDecorator {
- function contentcontrollerInit($controller) {
+ function init() {
// Don't auto-rebuild if explicitly disabled
if (Compass::$force_no_rebuild) return;
// Don't auto-rebuild in test mode
$runningTest = class_exists('SapphireTest',false) && SapphireTest::is_running_test();
if ($runningTest) return;
-
+
// If we are in dev mode, or flush called, auto-rebuild
if (Director::isDev() || @$_GET['flush']) singleton('Compass')->rebuild();
}
+
+ function contentcontrollerInit() {
+ return $this->init();
+ }
}

0 comments on commit 3a6fd07

Please sign in to comment.