Skip to content

Commit

Permalink
Merge branch 'master' of http://github.com/vicb/sfLESSPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Jul 26, 2010
2 parents 50bf494 + 795452f commit 28987f9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
5 changes: 5 additions & 0 deletions config/sfLESSPluginConfiguration.class.php
Expand Up @@ -42,5 +42,10 @@ public function initialize()
)); ));
} }
} }

$this->dispatcher->connect(
'less_js.compile',
array('sfLESSListeners', 'findAndFixContentLinks')
);
} }
} }
26 changes: 26 additions & 0 deletions lib/config/LESSConfig.class.php
Expand Up @@ -32,6 +32,14 @@ class LESSConfig
*/ */
protected $useCompression; protected $useCompression;


/**
* Client side compilation
*
* @var boolean
*/
protected $compileClientSide = false;


/** /**
* Creates config instance * Creates config instance
* *
Expand Down Expand Up @@ -114,6 +122,24 @@ public function getLessJsPath()
return '/sfLESSPlugin/js/less-1.0.31.min.js'; return '/sfLESSPlugin/js/less-1.0.31.min.js';
} }


/**
* @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 * Returns debug info of the current state
* *
Expand Down
8 changes: 8 additions & 0 deletions lib/config/sfLESSConfig.class.php
Expand Up @@ -57,4 +57,12 @@ public function getLessJsPath()
{ {
return sfConfig::get('app_sf_less_plugin_js_lib', parent::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());
}
} }
5 changes: 2 additions & 3 deletions lib/helper/LESSHelper.php
Expand Up @@ -32,9 +32,8 @@ function get_less_stylesheets()
{ {
$response = sfContext::getInstance()->getResponse(); $response = sfContext::getInstance()->getResponse();


sfLESSListeners::findAndFixContentLinks( $dispatcher = sfContext::getInstance()->getEventDispatcher();
$response, sfConfig::get('app_sf_less_plugin_use_js', false) $dispatcher->notify(new sfEvent($response, 'less_js.compile'));
);


return get_stylesheets(); return get_stylesheets();
} }
Expand Down
14 changes: 7 additions & 7 deletions lib/less/sfLESSListeners.php
Expand Up @@ -21,13 +21,14 @@ class sfLESSListeners
/** /**
* Update the response by fixing less stylesheet path and adding the less js engine when required * 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 sfEvent $event An sfEvent instance
* @param boolean $useJs Wether the less stylesheets should be processed by the js on the client side
*/ */
static public function findAndFixContentLinks(sfWebResponse $response, $useJs) static public function findAndFixContentLinks(sfEvent $event)
{ {
$response = $event->getSubject();
$config = new sfLESSConfig();
$hasLess = false; $hasLess = false;

foreach ($response->getStylesheets() as $file => $options) foreach ($response->getStylesheets() as $file => $options)
{ {
if ( if (
Expand All @@ -36,7 +37,7 @@ static public function findAndFixContentLinks(sfWebResponse $response, $useJs)
) )
{ {
$response->removeStylesheet($file); $response->removeStylesheet($file);
if ($useJs) if ($config->isClientSideCompilation())
{ {
$response->addStylesheet( $response->addStylesheet(
'/less/' . $file, '', array_merge($options, array('rel' => 'stylesheet/less')) '/less/' . $file, '', array_merge($options, array('rel' => 'stylesheet/less'))
Expand All @@ -59,8 +60,7 @@ static public function findAndFixContentLinks(sfWebResponse $response, $useJs)
); );
} }
else else
{ {
$config = new sfLESSConfig();
$response->addJavascript($config->getLessJsPath()); $response->addJavascript($config->getLessJsPath());
} }
} }
Expand Down

0 comments on commit 28987f9

Please sign in to comment.