예제 #1
0
 /**
  * Runs the task
  * @return \Robo\Result A Robo\Result instance containing info on wether the task was successful
  */
 public function run()
 {
     $parser = new \ILess_Parser(['import_dirs' => $this->importDirs]);
     $success = true;
     foreach ($this->paths as $destination => $source) {
         $this->printTaskInfo(sprintf('Compiling <info>%s</info> to <info>%s</info>', $source, $destination));
         try {
             $parser->parseFile($source);
             // I couldn't find a better solution to write the generated CSS
             // to file yet. There should be a stream writer, or similar...
             file_put_contents($destination, $parser->getCSS());
             $this->printTaskInfo(sprintf('Compiling <info>%s</info> to <info>%s</info>', $source, $destination));
         } catch (\ILess_Exception $e) {
             $this->printTaskError(sprintf('Compiling <info>%s</info> to <info>%s</info> FAILED', $source, $destination));
             $success = false;
         }
     }
     return $success ? Result::success($this) : Result::error($this, 'Some, or all of the sources could not be compiled.');
 }
예제 #2
0
$rebuild = true;
$cssLastModified = -1;
if ($cache->has($cacheKey)) {
    $rebuild = false;
    list($css, $importedFiles) = $cache->get($cacheKey);
    // we need to check if the file has been modified
    foreach ($importedFiles as $importedFileArray) {
        list($lastModifiedBefore, $path, $currentFileInfo) = $importedFileArray;
        $lastModified = $importer->getLastModified($path, $currentFileInfo);
        $cssLastModified = max($lastModified, $cssLastModified);
        if ($lastModifiedBefore != $lastModified) {
            $rebuild = true;
            // no need to continue, we will rebuild the CSS
            break;
        }
    }
}
if ($rebuild) {
    $parser->parseFile($file);
    $css = $parser->getCSS();
    // what have been imported?
    $importedFiles = array();
    foreach ($importer->getImportedFiles() as $importedFile) {
        $importedFiles[] = array($importedFile[0]->getLastModified(), $importedFile[1], $importedFile[2]);
        $cssLastModified = max($cssLastModified, $importedFile[0]->getLastModified());
    }
    $cache->set($cacheKey, array($css, $importedFiles));
}
header('Content-Type: text/css');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s ', $cssLastModified) . 'GMT');
echo $css;
예제 #3
0
파일: source_map.php 프로젝트: poef/ariadne
<?php

require_once '_bootstrap.php';
try {
    $cacheDir = dirname(__FILE__) . '/cache';
    // create the parser
    $parser = new ILess_Parser(array('compress' => false, 'source_map' => true, 'import_dirs' => array(dirname(__FILE__) . '/less/import')), new ILess_Cache_FileSystem($cacheDir));
    // parse file
    $parser->parseFile('less/test.less');
    // parse additional string
    $parser->parseString('
  #header {
    background: black;
  }');
    $cssContent = $parser->getCSS();
    file_put_contents($cacheDir . '/screen.css', $cssContent);
    $css = 'cache/screen.css';
} catch (Exception $e) {
    @header('HTTP/1.0 500 Internal Server Error');
    echo $e;
    exit;
}
$example = 'source map output';
include '_page.php';
예제 #4
0
파일: CLI.php 프로젝트: poef/ariadne
 /**
  * Runs the task based on the arguments
  *
  * @return true|integer True on success, error code on failure
  */
 public function run()
 {
     if (!$this->isValid()) {
         echo $this->getUsage();
         // return error
         return 1;
     } elseif ($this->getOption('version')) {
         echo ILess_Parser::VERSION . PHP_EOL;
         return;
     } elseif ($this->getOption('help')) {
         echo $this->getUsage();
         return;
     }
     try {
         $parser = new ILess_Parser($this->prepareOptionsForTheParser());
         $toBeParsed = $this->cliArguments['arguments'][0];
         // read from stdin
         if (in_array($toBeParsed, $this->stdAliases)) {
             $content = file_get_contents('php://stdin');
             $parser->parseString($content);
         } else {
             if (!ILess_Util::isPathAbsolute($toBeParsed)) {
                 $toBeParsed = sprintf('%s/%s', $this->currentDir, $toBeParsed);
             }
             $parser->parseFile($toBeParsed);
         }
         $toBeSavedTo = null;
         if (isset($this->cliArguments['arguments'][1])) {
             $toBeSavedTo = $this->cliArguments['arguments'][1];
             if (!ILess_Util::isPathAbsolute($toBeSavedTo)) {
                 $toBeSavedTo = sprintf('%s/%s', $this->currentDir, $toBeSavedTo);
             }
         }
         $css = $parser->getCSS();
         // where to put the css?
         if ($toBeSavedTo) {
             // write the result
             $this->saveCSS($toBeSavedTo, $css, $this->getOption('append'));
         } else {
             echo $css;
         }
     } catch (Exception $e) {
         if (!$this->getOption('silent')) {
             $this->renderException($e);
         }
         return $e->getCode();
     }
     return true;
 }