Permalink
Browse files

Rearranged helpers to mimic templating component dir structure and ap…

…pend the asset version on assets. Remove the already cached file if in debug mode
  • Loading branch information...
1 parent 94056fd commit 95e7d7c7baff9b2d91c9a84a6a002798f8683302 @henrikbjorn henrikbjorn committed Dec 27, 2010
View
15 Asset/Optimizer.php
@@ -7,7 +7,7 @@
use Symfony\Component\HttpFoundation\Request;
-use Bundle\Adenclassifieds\AssetOptimizerBundle\Helper\BaseHelper;
+use Bundle\Adenclassifieds\AssetOptimizerBundle\Templating\Helper\BaseHelper;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper;
@@ -42,12 +42,17 @@
*/
protected $eventDispatcher;
+ /**
+ * @var Boolean
+ */
+ protected $debug = false;
+
/**
* Constructor.
*
* @param acHelperAsset $assetHelper A acHelperAsset instance
*/
- public function __construct(EventDispatcher $eventDispatcher, Request $request, $assetPath, $cachePath)
+ public function __construct(EventDispatcher $eventDispatcher, Request $request, $assetPath, $cachePath, $debug = false)
{
$this->setEventDispatcher($eventDispatcher);
@@ -56,6 +61,8 @@ public function __construct(EventDispatcher $eventDispatcher, Request $request,
$this->setAssetPath($assetPath);
$this->setCachePath($cachePath);
+
+ $this->debug = (Boolean) $debug;
}
/**
@@ -79,6 +86,10 @@ public function optimize(BaseHelper $helper)
$filePath = $this->getCachePath().'/'.$name;
+ if (true === $this->debug && file_exists($filePath)) {
+ unlink($filePath);
+ }
+
if ( ! file_exists($filePath)) {
$code = $this->process($resources);
if (false === file_put_contents($filePath, $code)) {
View
10 Resources/config/assetoptimizer.xml
@@ -5,18 +5,18 @@
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd">
<parameters>
- <parameter key="templating.helper.javascripts.class">Bundle\Adenclassifieds\AssetOptimizerBundle\Helper\JavascriptsHelper</parameter>
- <parameter key="templating.helper.stylesheets.class">Bundle\Adenclassifieds\AssetOptimizerBundle\Helper\StylesheetsHelper</parameter>
+ <parameter key="templating.helper.javascripts.class">Bundle\Adenclassifieds\AssetOptimizerBundle\Templating\Helper\JavascriptsHelper</parameter>
+ <parameter key="templating.helper.stylesheets.class">Bundle\Adenclassifieds\AssetOptimizerBundle\Templating\Helper\StylesheetsHelper</parameter>
<parameter key="assetoptimizer.assets_path">%kernel.root_dir%/../web</parameter>
<parameter key="assetoptimizer.cache_path">%assetoptimizer.assets_path%/cache</parameter>
</parameters>
<services>
- <service id="templating.helper.stylesheets" class="%templating.helper.stylesheets.class%">
+ <service id="templating.helper.stylesheets" class="%templating.helper.stylesheets.class%">
<tag name="templating.helper" alias="stylesheets" />
<argument type="service" id="templating.helper.assets" />
</service>
- <service id="templating.helper.javascripts" class="%templating.helper.javascripts.class%">
+ <service id="templating.helper.javascripts" class="%templating.helper.javascripts.class%">
<tag name="templating.helper" alias="javascripts" />
<argument type="service" id="templating.helper.assets" />
</service>
@@ -25,12 +25,14 @@
<argument type="service" id="request" />
<argument>%assetoptimizer.assets_path%</argument>
<argument>%assetoptimizer.cache_path%</argument>
+ <argument>%kernel.debug%</argument>
</service>
<service id="asset.optimizer.stylesheet" class="Bundle\Adenclassifieds\AssetOptimizerBundle\Asset\Optimizer\Stylesheet\MinifyOptimizer">
<argument type="service" id="event_dispatcher" />
<argument type="service" id="request" />
<argument>%assetoptimizer.assets_path%</argument>
<argument>%assetoptimizer.cache_path%</argument>
+ <argument>%kernel.debug%</argument>
</service>
</services>
View
5 Helper/BaseHelper.php → Templating/Helper/BaseHelper.php
@@ -1,5 +1,6 @@
<?php
-namespace Bundle\Adenclassifieds\AssetOptimizerBundle\Helper;
+namespace Bundle\Adenclassifieds\AssetOptimizerBundle\Templating\Helper;
+
/**
* resourcesHelper is a helper that manages resources.
*
@@ -157,4 +158,4 @@ public function flush()
{
$this->resources = array();
}
-}
+}
View
8 Helper/JavascriptsHelper.php → Templating/Helper/JavascriptsHelper.php
@@ -1,7 +1,7 @@
<?php
-namespace Bundle\Adenclassifieds\AssetOptimizerBundle\Helper;
+namespace Bundle\Adenclassifieds\AssetOptimizerBundle\Templating\Helper;
-use Bundle\Adenclassifieds\AssetOptimizerBundle\Helper\ResourceCollectionHelper;
+use Bundle\Adenclassifieds\AssetOptimizerBundle\Helper\Templating\ResourceCollectionHelper;
/**
*
* Enter description here ...
@@ -15,7 +15,7 @@ class JavascriptsHelper extends BaseHelper
*/
protected function renderTag($path, $atts)
{
- return sprintf('<script type="text/javascript" src="%s"%s></script>', $path, $atts);
+ return sprintf('<script type="text/javascript" src="%s?%s"%s></script>', $path, $this->assetHelper->getVersion(), $atts);
}
/**
@@ -27,4 +27,4 @@ public function getName()
{
return 'javascripts';
}
-}
+}
View
10 Helper/StylesheetsHelper.php → Templating/Helper/StylesheetsHelper.php
@@ -1,7 +1,6 @@
<?php
-namespace Bundle\Adenclassifieds\AssetOptimizerBundle\Helper;
+namespace Bundle\Adenclassifieds\AssetOptimizerBundle\Templating\Helper;
-use Bundle\Adenclassifieds\AssetOptimizerBundle\Helper\ResourceCollectionHelper;
/**
*
* Enter description here ...
@@ -10,12 +9,11 @@
class StylesheetsHelper extends BaseHelper
{
/**
- * (non-PHPdoc)
- * @see Bundle\Adenclassifieds\AssetOptimizerBundle\Helper.ResourceCollectionHelper::renderTag()
+ * @{inheritDoc}
*/
protected function renderTag($path, $atts)
{
- return sprintf('<link href="%s" rel="stylesheet" type="text/css"%s />', $path, $atts);
+ return sprintf('<link href="%s?%s" rel="stylesheet" type="text/css"%s />', $path, $this->assetHelper->getVersion(), $atts);
}
/**
@@ -27,4 +25,4 @@ public function getName()
{
return 'stylesheets';
}
-}
+}

0 comments on commit 95e7d7c

Please sign in to comment.