Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Call findAndFixContentLinks via an event for consistency

  • Loading branch information...
commit 795452f7bef2f04dcf9cf7278718a33e80c8e48a 1 parent b3e4e1f
@vicb vicb authored
View
5 config/sfLESSPluginConfiguration.class.php
@@ -42,5 +42,10 @@ public function initialize()
));
}
}
+
+ $this->dispatcher->connect(
+ 'less_js.compile',
+ array('sfLESSListeners', 'findAndFixContentLinks')
+ );
}
}
View
26 lib/config/LESSConfig.class.php
@@ -33,6 +33,14 @@ class LESSConfig
protected $useCompression;
/**
+ * Client side compilation
+ *
+ * @var boolean
+ */
+ protected $compileClientSide = false;
+
+
+ /**
* Creates config instance
*
* @param boolean $checkDates whether we check dates before compile
@@ -115,6 +123,24 @@ public function getLessJsPath()
}
/**
+ * @return boolean Wether to compile on the client side
+ */
+ public function isClientSideCompilation()
+ {
+ return $this->compileClientSide;
+ }
+
+ /**
+ * Enable the client side compilation
+ *
+ * @param boolean $clientSide Wether to compile on the client side
+ */
+ public function setIsClientSideCompilation($clientSide)
+ {
+ $this->compileClientSide = $clientSide;
+ }
+
+ /**
* Returns debug info of the current state
*
* @return array state
View
8 lib/config/sfLESSConfig.class.php
@@ -57,4 +57,12 @@ public function getLessJsPath()
{
return sfConfig::get('app_sf_less_plugin_js_lib', parent::getLessJsPath());
}
+
+ /**
+ * @see LESSConfig
+ */
+ public function isClientSideCompilation()
+ {
+ sfConfig::get('app_sf_less_plugin_use_js', parent::isClientSideCompilation());
+ }
}
View
5 lib/helper/LESSHelper.php
@@ -32,9 +32,8 @@ function get_less_stylesheets()
{
$response = sfContext::getInstance()->getResponse();
- sfLESSListeners::findAndFixContentLinks(
- $response, sfConfig::get('app_sf_less_plugin_use_js', false)
- );
+ $dispatcher = sfContext::getInstance()->getEventDispatcher();
+ $dispatcher->notify(new sfEvent($response, 'less_js.compile'));
return get_stylesheets();
}
View
14 lib/less/sfLESSListeners.php
@@ -21,13 +21,14 @@ class sfLESSListeners
/**
* Update the response by fixing less stylesheet path and adding the less js engine when required
*
- * @param sfWebResponse $response The response that will be sent back to the browser
- * @param boolean $useJs Wether the less stylesheets should be processed by the js on the client side
+ * @param sfEvent $event An sfEvent instance
*/
- static public function findAndFixContentLinks(sfWebResponse $response, $useJs)
+ static public function findAndFixContentLinks(sfEvent $event)
{
+ $response = $event->getSubject();
+ $config = new sfLESSConfig();
$hasLess = false;
-
+
foreach ($response->getStylesheets() as $file => $options)
{
if (
@@ -36,7 +37,7 @@ static public function findAndFixContentLinks(sfWebResponse $response, $useJs)
)
{
$response->removeStylesheet($file);
- if ($useJs)
+ if ($config->isClientSideCompilation())
{
$response->addStylesheet(
'/less/' . $file, '', array_merge($options, array('rel' => 'stylesheet/less'))
@@ -59,8 +60,7 @@ static public function findAndFixContentLinks(sfWebResponse $response, $useJs)
);
}
else
- {
- $config = new sfLESSConfig();
+ {
$response->addJavascript($config->getLessJsPath());
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.