Skip to content

Commit

Permalink
Merge pull request #6 from vworldat/master
Browse files Browse the repository at this point in the history
Updated lesscss to current release 1.1.3
  • Loading branch information
everzet committed Dec 19, 2011
2 parents 27ff159 + 7b58b9a commit 738e274
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 92 deletions.
19 changes: 17 additions & 2 deletions lib/config/LESSConfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class LESSConfig
*/
protected $fixDuplicate = false;

/**
* Use lessphp for client-side compilation.
*
* @var boolean
*/
protected $useLessphp = false;

/**
* Creates config instance
*
Expand Down Expand Up @@ -106,7 +113,7 @@ public function setIsUseCompression($useCompression)
* @return string a path to CSS files directory
*/
public function getCssPaths()
{
{
return 'web/css/';
}

Expand All @@ -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';
}

/**
Expand All @@ -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
*
Expand Down
10 changes: 9 additions & 1 deletion lib/config/sfLESSConfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function isUseCompression()
* @see LESSConfig
*/
public function getCssPaths()
{
{
return sfLESSUtils::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/css/';
}

Expand Down Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/debug/sfWebDebugPanelLESS.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
53 changes: 31 additions & 22 deletions lib/less/sfLESS.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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'),
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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
*
Expand All @@ -278,7 +287,7 @@ public function canThrowExceptions()
* Throws formatted compiler error
*
* @param string $line error line
*
*
* @return boolean
*/
public function throwCompilerError($line)
Expand Down
Loading

0 comments on commit 738e274

Please sign in to comment.