예제 #1
0
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     // Inits sfLESS instance for compilation help
     $less = new sfLESS(new sfLESSConfig(false, isset($options['compress']) && $options['compress']));
     // Remove old CSS files if --clean option specified
     if (isset($options['clean']) && $options['clean']) {
         foreach ($less->findCssFiles() as $cssFile) {
             if (!isset($arguments['file']) || false !== strpos($cssFile, $arguments['file'] . '.css')) {
                 unlink($cssFile);
                 $this->logSection('removed', str_replace(sfLESS::getConfig()->getCssPaths(), '', $cssFile));
             }
         }
     }
     // Outputs debug info
     if (isset($options['debug']) && $options['debug']) {
         foreach (sfLESS::getConfig()->getDebugInfo() as $key => $value) {
             $this->logSection('debug', sprintf("%s:\t%s", $key, $value), null, 'INFO');
         }
     }
     // Compiles LESS files
     foreach ($less->findLessFiles() as $lessFile) {
         if (!isset($arguments['file']) || false !== strpos($lessFile, $arguments['file'] . '.less')) {
             if ($less->compile($lessFile)) {
                 if (isset($options['debug']) && $options['debug']) {
                     $this->logSection('compiled', sprintf("%s => %s", sfLESSUtils::getProjectRelativePath($lessFile), sfLESSUtils::getProjectRelativePath($less->getCssPathOfLess($lessFile))), null, 'COMMAND');
                 } else {
                     $this->logSection('compiled', str_replace(sfLESS::getConfig()->getLessPaths(), '', $lessFile), null, 'COMMAND');
                 }
             }
         }
     }
 }
 /**
  * Compute the dependencies of the file
  *
  * @param   file  $lessFile A less file
  * @param   array $deps     An array of pre-existing dependencies
  * 
  * @return  array           The updated array of dependencies
  */
 protected function computeDependencies($lessFile, array $deps)
 {
     if (!sfLESSUtils::isPathAbsolute($lessFile)) {
         $lessFile = realpath($this->path . '/' . $lessFile);
     }
     if (is_file($lessFile)) {
         $less = sfLESSUtils::stripLessComments(file_get_contents($lessFile));
         if (preg_match_all("/@import\\s+(?:url\\s*\\(\\s*)?(['\"])(.*?)\\1\\s*(?:\\))?\\s*;/", $less, $files)) {
             foreach ($files[2] as $file) {
                 // Append the .less when the extension is omitted
                 if (!preg_match('/\\.(le?|c)ss$/', $file)) {
                     $file .= '.less';
                 }
                 // Compute the canonical path
                 if (sfLESSUtils::isPathAbsolute($file)) {
                     $file = realpath($this->path . $file);
                 } else {
                     $file = realpath(dirname($lessFile) . '/' . $file);
                 }
                 if ($file !== false && !in_array($file, $deps) && !preg_match('/\\.css$/', $file)) {
                     $deps[] = $file;
                     // Recursively add dependencies
                     $deps += $this->computeDependencies($file, $deps);
                 }
             }
         }
         return $deps;
     } else {
         return array();
     }
 }
예제 #3
0
 /**
  * @see LESSConfig
  */
 public function getLessPaths()
 {
     return sfLESSUtils::getSepFixedPath(sfConfig::get('sf_web_dir')) . '/less/';
 }
 /**
  * Write the CSS content to a file
  *
  * @param   string  $cssFile  a CSS file
  * @param   string  $buffer   the css content
  *
  * @return  boolean           true if succesfully written & false in other way
  */
 public function writeCssFile($cssFile, $buffer)
 {
     // Fix duplicate lines
     if (self::getConfig()->getFixDuplicate()) {
         $buffer = sfLESSUtils::fixDuplicateLines($buffer);
     }
     // Compress CSS if we use compression
     if (self::getConfig()->isUseCompression()) {
         $buffer = sfLESSUtils::getCompressedCss($buffer);
     }
     // Add compiler header to CSS & writes it to file
     $status = file_put_contents($cssFile, sfLESSUtils::getCssHeader() . "\n\n" . $buffer);
     if ('\\' != DIRECTORY_SEPARATOR && $status !== false && fileowner($cssFile) == posix_geteuid()) {
         // Only attempt to chmod files we own
         chmod($cssFile, 0666);
     }
     return $status;
 }