Example #1
0
 /**
  * Convert LESS to CSS
  * @param string $string
  * @return string
  */
 public static function compile($string)
 {
     self::init();
     $parser = new \Less_Parser();
     $parser->SetOptions(['compress' => !Debugger::isEnabled()]);
     $parser->parse($string);
     return $parser->getCss();
 }
Example #2
0
File: Less.php Project: jjok/Robo
 /**
  * less compiler
  * @link https://github.com/oyejorge/less.php
  *
  * @param string $file
  *
  * @return string
  */
 protected function less($file)
 {
     if (!class_exists('\\Less_Parser')) {
         return Result::errorMissingPackage($this, 'Less_Parser', 'oyejorge/less.php');
     }
     $lessCode = file_get_contents($file);
     $parser = new \Less_Parser();
     $parser->SetOptions($this->compilerOptions);
     if (isset($this->compilerOptions['importDirs'])) {
         $importDirs = [];
         foreach ($this->compilerOptions['importDirs'] as $dir) {
             $importDirs[$dir] = $dir;
         }
         $parser->SetImportDirs($importDirs);
     }
     $parser->parse($lessCode);
     return $parser->getCss();
 }
Example #3
0
 public function read()
 {
     parent::read();
     if (!$this->is_cached()) {
         if (class_exists('\\Less_Parser')) {
             $parser = new \Less_Parser();
             $parser->SetOptions(array('compress' => $this->minify));
             try {
                 $parser->parse($this->content);
             } catch (\Exception $e) {
                 throw new \System\Error\Format(sprintf('Error while parsing LESS styles: %s', $e->getMessage()));
             }
             $this->content = $parser->getCss();
         } else {
             throw new \System\Error\MissingDependency('Missing less parser. Please install oyejorge/less.php');
         }
     }
 }
Example #4
0
 /**
  * Handle SCSS/LESS files
  *
  * @param string $content The file content
  * @param array  $arrFile The file array
  *
  * @return string The modified file content
  */
 protected function handleScssLess($content, $arrFile)
 {
     if ($arrFile['extension'] == self::SCSS) {
         $objCompiler = new Compiler();
         $objCompiler->setImportPaths(array(TL_ROOT . '/' . dirname($arrFile['name']), TL_ROOT . '/vendor/contao-components/compass/css'));
         $objCompiler->setFormatter(\Config::get('debugMode') ? 'Leafo\\ScssPhp\\Formatter\\Expanded' : 'Leafo\\ScssPhp\\Formatter\\Compressed');
         return $this->fixPaths($objCompiler->compile($content), $arrFile);
     } else {
         $strPath = dirname($arrFile['name']);
         $arrOptions = array('strictMath' => true, 'compress' => !\Config::get('debugMode'), 'import_dirs' => array(TL_ROOT . '/' . $strPath => $strPath));
         $objParser = new \Less_Parser();
         $objParser->SetOptions($arrOptions);
         $objParser->parse($content);
         return $this->fixPaths($objParser->getCss(), $arrFile);
     }
 }
Example #5
0
 /**
  * Allows to set different configurations for the less compiler,
  * like the compress mode or css source maps.
  *
  * @param array $configuration
  * @return void
  */
 public function setConfiguration(array $configuration)
 {
     $this->compiler->SetOptions($configuration);
 }