Author: rande
Date: 2010-05-20 19:12:20 +0200 (Thu, 20 May 2010)
New Revision: 29560

Modified:
   plugins/swCombinePlugin/trunk/README
   plugins/swCombinePlugin/trunk/config/swCombinePluginConfiguration.class.php
   plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php
   plugins/swCombinePlugin/trunk/lib/helper/swCombineHelper.php
Log:
[swCombinePlugin] add combined file debugging, avoid combined files to be 
loaded twice

Modified: plugins/swCombinePlugin/trunk/README
===================================================================
--- plugins/swCombinePlugin/trunk/README        2010-05-20 16:21:43 UTC (rev 
29559)
+++ plugins/swCombinePlugin/trunk/README        2010-05-20 17:12:20 UTC (rev 
29560)
@@ -122,8 +122,14 @@
     
         ./symfony sw:combine frontend
         ./symfony sw:combine backend
-        
 
+ * update your templates files to use these helpers :
+ 
+      sw_include_stylesheets()
+      sw_include_javascripts()
+      sw_combine_debug() 
+                    
+
 ## Packages
 
   You can include packages into the view.yml, just add these lines into the 
view.yml file

Modified: 
plugins/swCombinePlugin/trunk/config/swCombinePluginConfiguration.class.php
===================================================================
--- plugins/swCombinePlugin/trunk/config/swCombinePluginConfiguration.class.php 
2010-05-20 16:21:43 UTC (rev 29559)
+++ plugins/swCombinePlugin/trunk/config/swCombinePluginConfiguration.class.php 
2010-05-20 17:12:20 UTC (rev 29560)
@@ -10,8 +10,29 @@
 
 class swCombinePluginConfiguration extends sfPluginConfiguration
 {
+  protected $loaded_assets = array();
+  
   public function initialize()
   {
     
+    $this->dispatcher->connect('response.method_not_found', array($this, 
'listenToMethodNotFound'));
   }
+  
+  public function listenToMethodNotFound(sfEvent $event)
+  {
+    $parameters = $event->getParameters();
+    
+    if($parameters['method'] == 'defineCombinedAssets')
+    {
+      $this->loaded_assets = count($parameters['arguments']) > 0 ? 
$parameters['arguments'][0] : array();
+      
+      $event->setProcessed(true);
+    }
+    
+    if($parameters['method'] == 'getCombinedAssets')
+    {
+      $event->setReturnValue($this->loaded_assets);
+      $event->setProcessed(true);
+    }
+  }
 }
\ No newline at end of file

Modified: 
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php
===================================================================
--- 
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php   
    2010-05-20 16:21:43 UTC (rev 29559)
+++ 
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php   
    2010-05-20 17:12:20 UTC (rev 29560)
@@ -17,6 +17,9 @@
 class swCombineViewConfigHandler extends sfViewConfigHandler
 {
 
+  protected
+    $assets_loaded = array();
+    
   /**
    * Adds stylesheets and javascripts statements to the data.
    *
@@ -48,7 +51,9 @@
 
     $js = $this->addAssets('Javascript', $javascripts);
   
-    return implode("\n", array_merge($css, $js))."\n";
+    // set current js and css loaded, also add information about the current 
defined assets
+    return implode("\n", array_merge($css, $js)).
+      "\n  \$response->defineCombinedAssets(".var_export($this->assets_loaded, 
1).");\n";
   }
   
   public function combineValues($type, $values, $viewName)
@@ -138,6 +143,9 @@
       );
     }
     
+    // keep a track of combined filed files for this view
+    $this->assets_loaded = array_merge($this->assets_loaded, $packages_files, 
$combined);
+    
     return $final;
   }
   

Modified: plugins/swCombinePlugin/trunk/lib/helper/swCombineHelper.php
===================================================================
--- plugins/swCombinePlugin/trunk/lib/helper/swCombineHelper.php        
2010-05-20 16:21:43 UTC (rev 29559)
+++ plugins/swCombinePlugin/trunk/lib/helper/swCombineHelper.php        
2010-05-20 17:12:20 UTC (rev 29560)
@@ -14,11 +14,20 @@
   $version = $params['version'];
   
   $response = sfContext::getInstance()->getResponse();
+  $included_files = $response->getCombinedAssets();
+  
   sfConfig::set('symfony.asset.javascripts_included', true);
 
   $html = '';
   foreach ($response->getJavascripts() as $file => $options)
   {
+    // avoid loading combined files
+    if(in_array($file, $included_files))
+    {
+
+     continue;
+    }
+     
     $file = $version ? $file.'?v='.$version : $file;
     
     $html .= javascript_include_tag($file, $options);
@@ -33,11 +42,20 @@
   $version = $params['version'];
   
   $response = sfContext::getInstance()->getResponse();
+  $included_files = $response->getCombinedAssets();
+  
   sfConfig::set('symfony.asset.stylesheets_included', true);
 
   $html = '';
   foreach ($response->getStylesheets() as $file => $options)
   {
+    // avoid loading combined files
+    if(in_array($file, $included_files))
+    {
+
+     continue;
+    }
+    
     $file = $version ? $file.'?v='.$version : $file;
     
     $html .= stylesheet_tag($file, $options);
@@ -56,3 +74,11 @@
   echo sw_get_javascripts();  
 }
 
+function sw_combine_debug()
+{
+  if(ProjectConfiguration::getActive()->isDebug())
+  {
+    $response = sfContext::getInstance()->getResponse();
+    echo "<!-- DEBUG MODE - \nCombined files : 
\n".var_export($response->getCombinedAssets(), 1)."\n -->\n";
+  }
+}
\ No newline at end of file

-- 
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