Author: rande
Date: 2010-05-18 20:52:55 +0200 (Tue, 18 May 2010)
New Revision: 29509
Modified:
plugins/swCombinePlugin/trunk/README
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php
Log:
[swCombinePlugin] implement the package feature
Modified: plugins/swCombinePlugin/trunk/README
===================================================================
--- plugins/swCombinePlugin/trunk/README 2010-05-18 18:30:56 UTC (rev
29508)
+++ plugins/swCombinePlugin/trunk/README 2010-05-18 18:52:55 UTC (rev
29509)
@@ -85,7 +85,7 @@
- /js/main.js
packages:
common:
- auto_include: true
+ auto_include: true # this will include the
package on ALL pages
files:
- /js/jQuery/jquery.1.2.6.js
- /js/jQuery/ui-1.5.3/jquery.ui.all.js
@@ -96,12 +96,11 @@
- /js/scrollTo/jquery.scrollTo-min.js
- /js/main.js
-
stylesheet:
combine: swCombineStylesheet
driver: swDriverCssmin
filename: %s.css # %s will by replace by
the combined name
- exclude:
+ exclude: # this will include the
package on ALL pages
- /css/main.css
- /css/draft/ui-theme.css
- /css/mg-theme.css
@@ -124,7 +123,25 @@
./symfony sw:combine frontend
./symfony sw:combine backend
-
+
+## Packages
+
+ You can include packages into the view.yml, just add these lines into the
view.yml file
+
+ [yml]
+ all:
+ sw_combine:
+ include_packages:
+ javascripts: [common]
+ stylesheets: [common]
+
+ myViewSuccess:
+ sw_combine:
+ include_packages:
+ javascripts: [extra_code]
+
+
+
## Assets version (optional)
This plugin has a hidden gem : asset versioning. When css files are combined,
a version number is added to all externals references. This feature must be
use with helper functions `sw_include_stylesheets()` and
`sw_include_javascripts()`, this two helpers add the version number on each
declared assets.
Modified:
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php
===================================================================
---
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php
2010-05-18 18:30:56 UTC (rev 29508)
+++
plugins/swCombinePlugin/trunk/lib/config/swCombineViewConfigHandler.class.php
2010-05-18 18:52:55 UTC (rev 29509)
@@ -29,12 +29,21 @@
// Merge the current view's stylesheets with the app's default stylesheets
$stylesheets = $this->mergeConfigValue('stylesheets', $viewName);
+ // clean stylesheet list (-*)
+ $stylesheets = $this->addAssets('stylesheets', $stylesheets, false);
+
+ // combine
$stylesheets = $this->combineValues('stylesheet', $stylesheets, $viewName);
$css = $this->addAssets('Stylesheet', $stylesheets);
// Merge the current view's javascripts with the app's default javascripts
$javascripts = $this->mergeConfigValue('javascripts', $viewName);
+
+ // clean stylesheet list (-*)
+ $stylesheets = $this->addAssets('javascripts', $stylesheets, false);
+
+ // combine
$javascripts = $this->combineValues('javascript', $javascripts, $viewName);
$js = $this->addAssets('Javascript', $javascripts);
@@ -42,7 +51,7 @@
return implode("\n", array_merge($css, $js))."\n";
}
- public function combineValues($type, $values)
+ public function combineValues($type, $values, $viewName)
{
$combined = $final = array();
@@ -63,34 +72,64 @@
$packages_files = array_merge($packages_files, $package['files']);
}
}
-
+
+ // load packages defined in the yaml
+ if($viewName == '')
+ {
+ $viewName = 'all';
+ }
+
+ if(
+ isset($this->yamlConfig[$type]) &&
+ isset($this->yamlConfig[$viewName]['sw_combine']) &&
+ isset($this->yamlConfig[$viewName]['sw_combine']['include_packages']) &&
+
isset($this->yamlConfig[$viewName]['sw_combine']['include_packages'][$type])
+ )
+ {
+
foreach($this->yamlConfig[$viewName]['sw_combine']['include_packages'][$type]
as $package_name)
+ {
+ if(!isset($packages[$package_name]))
+ {
+ continue;
+ }
+
+ $final[] = sprintf('%s/%s',
+ $this->getParameterHolder()->get('public_path'),
+ $this->getPackageName($type, $name)
+ );
+
+ $packages_files = array_merge($packages_files, $package['files']);
+ }
+ }
+
// build the combined assets
foreach($values as $value)
{
- $assert_name = is_array($value) ? key($value) : $value;
+ $asset_name = $value[1];
- if(in_array($assert_name, $packages_files))
+ if(in_array($asset_name, $packages_files))
{
// the file is present in a package file, skip it
continue;
}
- if($this->excludeFile($type, $assert_name))
+ if($this->excludeFile($type, $asset_name))
{
- $final[] = $value;
+
+ $final[] = $asset_name;
continue;
}
- if(!$this->isCombinable($type, $value))
+ if(!$this->isCombinable($type, $asset_name))
{
- $final[] = $value;
+
+ $final[] = $asset_name;
continue;
}
-
- $combined[] = $value;
+
+ $combined[] = $asset_name;
}
- // var_dump($combined, $this->getCombinedName($type, $combined));
if(count($combined) > 0)
{
$final[] = sprintf('%s/%s',
@@ -176,7 +215,7 @@
public function getPackageName($type, $name)
{
$configuration = $this->getParameterHolder()->get('configuration');
- $format = isset($configuration[$type]['filename']) ?
$configuration[$type]['filename'] : '%s';
+ $format = isset($configuration[$type]['filename']) ?
$configuration[$type]['filename'] : '%s';
$name = md5(sfInflector::underscore('package_'.$type.'_'.$name));
@@ -271,13 +310,12 @@
{
if($raw_php)
{
- $tmp[$key] = $tmp[$key] = sprintf(" \$response->add%s('%s', '%s',
%s);", $type, $key, $position, str_replace("\n", '', var_export($options,
true)));
+ $tmp[$key] = sprintf(" \$response->add%s('%s', '%s', %s);", $type,
$key, $position, str_replace("\n", '', var_export($options, true)));
}
else
{
$tmp[$key] = array($type, $key, $position, $options);
}
-
}
}
--
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.