protected function doParsingTest(Parser $parser)
    {
        $parser->parseFile(__DIR__ . '/_fixtures/test.less');
        $expected = <<<EXPECTED
body {
  color: red;
}
#foo {
  border: 10px solid blue;
}

EXPECTED;
        $css = $parser->getCSS();
        $this->assertEquals($expected, $css, 'The file was imported.');
    }
Beispiel #2
0
<?php

use ILess\Exception\Exception;
use ILess\Parser;
require_once '_bootstrap.php';
try {
    $cacheDir = dirname(__FILE__) . '/cache';
    // create the parser
    $parser = new Parser(array('compress' => false, 'source_map' => true, 'source_map_options' => array('source_contents' => true)));
    // parse file
    $parser->parseFile(__DIR__ . '/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';
Beispiel #3
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;