Permalink
Browse files

Merge pull request #6 from vworldat/master

Updated lesscss to current release 1.1.3
  • Loading branch information...
everzet committed Dec 19, 2011
2 parents 27ff159 + 7b58b9a commit 738e274ed131e9bdfad3bed7c2c4d031baf1511c
@@ -48,6 +48,13 @@ class LESSConfig
*/
protected $fixDuplicate = false;
/**
* Use lessphp for client-side compilation.
*
* @var boolean
*/
protected $useLessphp = false;
/**
* Creates config instance
*
@@ -106,7 +113,7 @@ public function setIsUseCompression($useCompression)
* @return string a path to CSS files directory
*/
public function getCssPaths()
{
{
return 'web/css/';
}
@@ -127,7 +134,7 @@ public function getLessPaths()
*/
public function getLessJsPath()
{
return '/sfLESSPlugin/js/less-1.0.33.min.js';
return '/sfLESSPlugin/js/less-1.1.3.min.js';
}
/**
@@ -138,6 +145,14 @@ public function isClientSideCompilation()
return $this->compileClientSide;
}
/**
* @return boolean Whether to use lessphp for client side compilation
*/
public function isUseLessphp()
{
return $this->useLessphp;
}
/**
* Enable the client side compilation
*
@@ -38,7 +38,7 @@ public function isUseCompression()
* @see LESSConfig
*/
public function getCssPaths()
{
{
return sfLESSUtils::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/css/';
}
@@ -66,6 +66,14 @@ public function isClientSideCompilation()
return sfConfig::get('app_sf_less_plugin_use_js', parent::isClientSideCompilation());
}
/**
* @see LESSConfig
*/
public function isUseLessphp()
{
return sfConfig::get('app_sf_less_plugin_use_lessphp', parent::isClientSideCompilation());
}
/**
* @see LESSConfig
*/
@@ -51,7 +51,8 @@ public static function listenToLoadDebugWebPanelEvent(sfEvent $event)
*/
public function getTitle()
{
return '<img src="/sfLESSPlugin/images/css_go.png" alt="LESS helper" height="16" width="16" /> less';
$path = sfContext::getInstance()->getRequest()->getRelativeUrlRoot();
return '<img src="'.$path.'/sfLESSPlugin/images/css_go.png" alt="LESS helper" height="16" width="16" /> less';
}
/**
@@ -121,7 +121,7 @@ public function findLessFiles()
* Returns CSS file path by its LESS alternative
*
* @param string $lessFile LESS file path
*
*
* @return string CSS file path
*/
public function getCssPathOfLess($lessFile)
@@ -135,7 +135,7 @@ public function getCssPathOfLess($lessFile)
* Compiles LESS file to CSS
*
* @param string $lessFile a LESS file
*
*
* @return boolean true if succesfully compiled & false in other way
*/
public function compile($lessFile)
@@ -152,7 +152,7 @@ public function compile($lessFile)
// If we check dates - recompile only really old CSS
if (self::getConfig()->isCheckDates())
{
{
try
{
$d = new sfLESSDependency(sfConfig::get('sf_web_dir'),
@@ -174,7 +174,7 @@ public function compile($lessFile)
$buffer = $this->callLesscCompiler($lessFile, $cssFile);
if ($buffer !== false)
{
$isCompiled = $this->writeCssFile($cssFile, $buffer) !== false;
$isCompiled = $this->writeCssFile($cssFile, $buffer) !== false;
}
}
@@ -228,40 +228,49 @@ public function writeCssFile($cssFile, $buffer)
*
* @param string $lessFile a LESS file
* @param string $cssFile a CSS file
*
*
* @return string output
*/
public function callLesscCompiler($lessFile, $cssFile)
{
// Setting current file. We will output this var if compiler throws error
$this->currentFile = $lessFile;
// Compile with lessc
$fs = new sfFilesystem;
$command = sprintf('lessc "%s" "%s"', $lessFile, $cssFile);
if ('1.3.0' <= SYMFONY_VERSION)
if (self::getConfig()->isUseLessphp())
{
try
{
$fs->execute($command, null, array($this, 'throwCompilerError'));
}
catch (RuntimeException $e)
{
return false;
}
require_once(sfConfig::get('sf_lib_dir').'/vendor/lessc.inc.php');
$less = new lessc($lessFile);
file_put_contents($cssFile, $less->parse());
}
else
{
$fs->sh($command);
// Compile with lessc
$fs = new sfFilesystem;
$command = sprintf('lessc "%s" "%s"', $lessFile, $cssFile);
if ('1.3.0' <= SYMFONY_VERSION)
{
try
{
$fs->execute($command, null, array($this, 'throwCompilerError'));
}
catch (RuntimeException $e)
{
return false;
}
}
else
{
$fs->sh($command);
}
}
// Setting current file to null
$this->currentFile = null;
return file_get_contents($cssFile);
}
/**
* Returns true if compiler can throw RuntimeException
*
@@ -278,7 +287,7 @@ public function canThrowExceptions()
* Throws formatted compiler error
*
* @param string $line error line
*
*
* @return boolean
*/
public function throwCompilerError($line)
Oops, something went wrong.

0 comments on commit 738e274

Please sign in to comment.