Author: rande
Date: 2010-05-18 13:59:58 +0200 (Tue, 18 May 2010)
New Revision: 29499

Modified:
   plugins/swCombinePlugin/trunk/README
   plugins/swCombinePlugin/trunk/lib/combine/swCombineStylesheet.class.php
   plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php
   plugins/swCombinePlugin/trunk/lib/task/swOptimizeCreateFilesTask.class.php
Log:
[swCombinePlugin] fix bugs

Modified: plugins/swCombinePlugin/trunk/README
===================================================================
--- plugins/swCombinePlugin/trunk/README        2010-05-18 10:00:05 UTC (rev 
29498)
+++ plugins/swCombinePlugin/trunk/README        2010-05-18 11:59:58 UTC (rev 
29499)
@@ -19,7 +19,7 @@
 ## Available optimizers
 
   - Global
-    - swPassDriver : do nothing, use this if you want to combine your files 
with no optizations
+    - swPassDriver : do nothing, use this if you want to combine your files 
with no optimizations
   
   - Javascript 
     - swDriverGoogleClosureCompilerApi : use google closure algorithm
@@ -131,6 +131,7 @@
 
 The asset version format is : ASSET_FILE?_sw=ASSET_VERSION
 
+
 ### What does it mean ?
 
 You can configure a long time expired value on your server by using simple 
regular expression.
@@ -148,7 +149,6 @@
           swCombine:
             version: 42
 
-
  * clear your cache
 
          ./symfony cc
@@ -156,4 +156,13 @@
  * regenerate the combined css and js files with 
 
          ./symfony sw:combine frontend
-         ./symfony sw:combine backend
\ No newline at end of file
+         ./symfony sw:combine backend
+         
+         
+## Troubleshooting
+
+### css @import not loaded 
+
+   the import syntax must be : @import url('yourfile.css') or @import 
url("yourfile.css").
+   
+   this is not valid : @import url(yourfile.css)
\ No newline at end of file

Modified: 
plugins/swCombinePlugin/trunk/lib/combine/swCombineStylesheet.class.php
===================================================================
--- plugins/swCombinePlugin/trunk/lib/combine/swCombineStylesheet.class.php     
2010-05-18 10:00:05 UTC (rev 29498)
+++ plugins/swCombinePlugin/trunk/lib/combine/swCombineStylesheet.class.php     
2010-05-18 11:59:58 UTC (rev 29499)
@@ -29,18 +29,8 @@
     $this->path_pos = -1;
     $this->paths    = array();
     
-    $include = @file_get_contents($asset);
-    
-    if(!$include)
-    {
-      throw new Exception('unable to read the asset : '.$asset);
-    }
-    
-    // remove BOM
-    $contents = $this->removeBom($contents);
-    
     // import css from external declarations
-    $contents = $this->fixImportStatement($path, $include);
+    $contents = $this->fixImportStatement($asset);
     
     // get the version so each time the cache is cleared then the image are 
reload 
     // from the webserver
@@ -61,29 +51,45 @@
     return $contents;
   }
   
-  public function fixImportStatement($path, $include)
+  public function fixImportStatement($asset)
   {
+    $contents = @file_get_contents($asset);
     
+    if(!$contents)
+    {
+      throw new Exception('unable to read the asset : '.$asset);
+    }
+    
+    // remove BOM
+    $contents = $this->removeBom($contents);
+    
+    $asset = realpath($asset);
+    $info = pathinfo($asset);
+    
     $this->path_pos++;
 
     // store the current path in the recursion
-    $this->paths[$this->path_pos] = $path;
+    $this->paths[$this->path_pos] = $info['dirname'];
     
     // fix image path
-    $content = preg_replace_callback('/url\(("|\'|)(.*)("|\'|)\)/smU', 
array($this, 'fixImportImageCallback'), $include);
+    $fix = preg_replace_callback('/url\(("|\'|)(.*)("|\'|)\)/smU', 
array($this, 'fixImportImageCallback'), $contents);
     
-    // fetch the contents of any include file
-    $content = preg_replace_callback('/@import url\([ ]*[\'|"](.*)[\'|"][ 
]*\);/smU', array($this, 'fixImportStatementCallback'), $content);
+    if($fix)
+    {
+      $contents = $fix;
+    }
     
-    $this->path_pos--;
-    
-    if(!$content)
+    // fetch the contents of any include files
+    $fix = preg_replace_callback('/@import url\([ ]*[\'|"](.*)[\'|"][ 
]*\);/smU', array($this, 'fixImportStatementCallback'), $contents);
+
+    if($fix)
     {
-      
-      return $include; // no match in the recursion
+      $contents = $fix;
     }
     
-    return $content;
+    $this->path_pos--;
+        
+    return $contents;
   }
   
   public function fixImportImageCallback($matches)
@@ -93,19 +99,24 @@
     if(preg_match('/\.css/', $matches[2]))
     {
       
-      return  $matches[0];
+      return $matches[0];
     }
     
     // fix image path 
     $web_dir = sfConfig::get('sf_web_dir');
+        
+    $file = $this->paths[$this->path_pos].'/'.($matches[2]{0} == '/' ? 
substr($matches[2], 1) : $matches[2]);
+    $t = $file;
+    $file = realpath($file);
     
-    $infos = pathinfo($this->paths[$this->path_pos]);
+    if($file)
+    {
+      $file = str_replace($web_dir, '', $file);
+
+      return 'url('.$file.')';
+    }
     
-    $file = $infos['dirname'].'/'.($matches[2]{0} == '/' ? substr($matches[2], 
1) : $matches[2]);
-
-    $file = str_replace($web_dir, '', $file);
-
-    return 'url('.$file.')';
+    return 'none';
   }
   
   /**
@@ -113,20 +124,18 @@
    */
   public function fixImportStatementCallback($matches)
   {
-    $infos = pathinfo($this->paths[$this->path_pos]);
+    $infos = $this->paths[$this->path_pos];
+
+    $file = $this->paths[$this->path_pos].'/'.$matches[1];
     
-    $file = $infos['dirname'].'/'.$matches[2];
-    
     $content = @file_get_contents($file);
 
     if($content)
     {
       
-      // return $content;
       return $this->fixImportStatement($file, $content);
     }
     
-    // cannot fix import
-    return $matches[0]."/* cannot fix import statement */";
+    throw new sfException('Unable to import statement file : '.$file);
   }
 }

Modified: 
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php
===================================================================
--- 
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php   
    2010-05-18 10:00:05 UTC (rev 29498)
+++ 
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php   
    2010-05-18 11:59:58 UTC (rev 29499)
@@ -48,8 +48,11 @@
 
     $packages_files = array();
     
+    $configuration = $this->getParameterHolder()->get('configuration');
+    $packages = isset($configuration[$type]['packages']) ? 
$configuration[$type]['packages'] : array();
+    
     // build the package assets
-    
foreach($this->getParameterHolder()->get('configuration['.$type.'][packages]', 
array()) as $name => $package)
+    foreach($packages as $name => $package)
     {
       if(isset($package['auto_include']) && $package['auto_include'])
       {
@@ -87,6 +90,7 @@
       $combined[] = $value;
     }
     
+    // var_dump($combined, $this->getCombinedName($type, $combined));
     if(count($combined) > 0)
     {
       $final[] = sprintf('%s/%s', 
@@ -104,8 +108,10 @@
     $combined = $final = array();
     
     // build the package assets
+    $configuration = $this->getParameterHolder()->get('configuration');
+    $packages = isset($configuration[$type]['packages']) ? 
$configuration[$type]['packages'] : array();
     
-    
foreach($this->getParameterHolder()->get('configuration['.$type.'][packages]', 
array()) as $name => $package)
+    foreach($packages as $name => $package)
     {
       if(isset($package['auto_include']) && $package['auto_include'])
       {
@@ -145,8 +151,9 @@
     
   public function getCombinedName($type, array $assets)
   {
-    $format = 
$this->getParameterHolder()->get('configuration['.$type.'][filename]', '%s');
-
+    $configuration = $this->getParameterHolder()->get('configuration');
+    $format = isset($configuration[$type]['filename']) ? 
$configuration[$type]['filename'] : '%s';
+    
     // make sure we have a flat list
     foreach($assets as $pos => $asset)
     {
@@ -168,7 +175,9 @@
   
   public function getPackageName($type, $name)
   {
-    $format  = 
$this->getParameterHolder()->get('configuration['.$type.'][filename]', '%s');
+    $configuration = $this->getParameterHolder()->get('configuration');
+    $format = isset($configuration[$type]['filename']) ? 
$configuration[$type]['filename'] : '%s';
+    
     $name    = md5(sfInflector::underscore('package_'.$type.'_'.$name));
     
     return sprintf($format, $name);
@@ -209,8 +218,10 @@
   
   public function excludeFile($type, $file)
   {
-    $exclude = 
$this->getParameterHolder()->get('configuration['.$type.'][exclude]', array());
     
+    $configuration = $this->getParameterHolder()->get('configuration');
+    $exclude = isset($configuration[$type]['exclude']) ? 
$configuration[$type]['exclude'] : array();
+    
     if(in_array($file, $exclude))
     {
       

Modified: 
plugins/swCombinePlugin/trunk/lib/task/swOptimizeCreateFilesTask.class.php
===================================================================
--- plugins/swCombinePlugin/trunk/lib/task/swOptimizeCreateFilesTask.class.php  
2010-05-18 10:00:05 UTC (rev 29498)
+++ plugins/swCombinePlugin/trunk/lib/task/swOptimizeCreateFilesTask.class.php  
2010-05-18 11:59:58 UTC (rev 29499)
@@ -86,7 +86,10 @@
   public function combinePackagesFiles($type)
   {
     
-    foreach($this->view_parameters->get('configuration['.$type.'][packages]', 
array()) as $name => $package)
+    $configuration = $this->view_parameters->get('configuration');
+    $packages =  isset($configuration[$type]['packages']) ? 
$configuration[$type]['packages'] : array();
+    
+    foreach($packages as $name => $package)
     {
       $assets = array();
       foreach($package['files'] as $file)
@@ -169,8 +172,9 @@
   public function combineAndOptimize($type, $assets, $use_ignore = true, 
$force_name_to = false)
   {
     
-    $combine_class = 
$this->view_parameters->get('configuration['.$type.'][combine]');
-    
+    $configuration = $this->view_parameters->get('configuration');
+    $combine_class =  $configuration[$type]['combine'];
+
     if(!class_exists($combine_class))
     {
       
@@ -252,9 +256,9 @@
    */
   public function getDriver($type)
   {
+    $configuration = $this->view_parameters->get('configuration');
+    $driver =  $configuration[$type]['driver'];
     
-    $driver = $this->view_parameters->get('configuration['.$type.'][driver]', 
false);
-    
     if(!class_exists($driver))
     {
       

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to