Exemplo n.º 1
0
    [updated_at] TIMESTAMP
  )', 'CREATE UNIQUE INDEX [filename_idx] ON [less] ([filename])');
foreach ($statements as $statement) {
    if (!$pdo->query($statement)) {
        $error = $pdo->errorInfo();
        throw new Exception($error[2], $error[1]);
    }
}
$stmt = $pdo->prepare('INSERT INTO less(filename, data, updated_at) VALUES(?, ?, ?)');
foreach (array(array('foo.less', 'body { background: @color; }', time()), array('mixins.less', '.mixin(@a) { background: @a; }', time())) as $line) {
    $result = $stmt->execute(array($line[0], $line[1], $line[2]));
}
try {
    $cacheDir = dirname(__FILE__) . '/cache';
    $parser = new ILess_Parser();
    $parser->getImporter()->registerImporter(new ILess_Importer_Database($pdo, array('table_name' => 'less', 'filename_column' => 'filename', 'data_column' => 'data', 'updated_at_column' => 'data')));
    $parser->parseString('

  @color: red;

  @import url("foo.less");
  @import (reference) url("mixins.less");

  #head {
    color: @color + #fff;
    .mixin(yellow);
  }

  ');
    $cssContent = $parser->getCSS();
    file_put_contents($cacheDir . '/database.css', $cssContent);
Exemplo n.º 2
0
<?php

require_once '_bootstrap.php';
// create the parser
$parser = new ILess_Parser(array(), new ILess_Cache_FileSystem(array('cache_dir' => dirname(__FILE__) . '/cache')));
$file = dirname(__FILE__) . '/less/test.less';
// create your cache key
$cacheKey = md5($file);
$importer = $parser->getImporter();
$cache = $parser->getCache();
$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?