Example #1
1
    public function testIssueWithCompression()
    {
        $parser = new ILess_Parser(array('compress' => true));
        $parser->parseString('
@grid-gutter-width: 10px;
.elem {
  width: calc(~\'100% + @{grid-gutter-width}\');
}');
        $css = $parser->getCSS();
        $expected = '.elem{width:calc(100% + 10px)}';
        $this->assertEquals($expected, $css);
    }
Example #2
1
    public function testIssue()
    {
        $parser = new ILess_Parser();
        $parser->setVariables(array('mycolor' => 'transparent'));
        $parser->parseString('.test{
  background-color: @mycolor;
}');
        $css = $parser->getCSS();
        $expected = '.test {
  background-color: transparent;
}
';
        $this->assertEquals($expected, $css);
    }
Example #3
0
 public function testImport()
 {
     $importer = new ILess_Importer_Array(array('vendor/foo.less' => '@import "bar";', 'vendor/bar.less' => '@import "foobar"; @import "../parent"; a { color: blue; }', 'foobar.less' => 'b { color: red; }', 'parent.less' => '/* comment */'));
     $parser = new ILess_Parser(array(), null, array($importer));
     $parser->parseString('@import "vendor/foo";');
     $this->assertEquals("b {\n  color: red;\n}\n/* comment */\na {\n  color: blue;\n}\n", $parser->getCSS());
 }
Example #4
0
 /**
  * @covers getCache
  */
 public function testGetCache()
 {
     $parser = new ILess_Parser();
     $this->assertInstanceOf('ILess_CacheInterface', $parser->getCache());
     $parser = new ILess_Parser(array(), new ILess_Cache_FileSystem(array('cache_dir' => sys_get_temp_dir())));
     $this->assertInstanceOf('ILess_CacheInterface', $parser->getCache());
 }
Example #5
0
    public function testIssue()
    {
        $parser = new ILess_Parser();
        $parser->parseString('.test{
  background-color: darken("#ffffff",2%);
}');
        $this->setExpectedException('ILess_Exception_Function');
        $parser->getCSS();
    }
Example #6
0
    public function testIssueWithApiVariables()
    {
        $parser = new ILess_Parser(array('compress' => false));
        $parser->parseString('
@import "../../../bootstrap3/less/@{swatch}/variables.less";
');
        $parser->setVariables(array('swatch' => 'foobar'));
        $this->setExpectedException('ILess_Exception_Import', '/bootstrap3/less/foobar/variables.less');
        $css = $parser->getCSS();
    }
Example #7
0
    public function testIssue()
    {
        $parser = new ILess_Parser(array('compress' => false));
        $parser->parseString('
#mxtest {
  color2: @b;
  alpha: alpha(@a);
  color: darken(@a, 20);
  background: -moz-linear-gradient(top, @a 0%, darken(@a, 20) 100%);
}');
        $parser->setVariables(array('a' => 'rgb(46, 120, 176)', 'b' => 'rgba(0,1,2,0.3)'));
        $css = $parser->getCSS();
        $this->assertContains('alpha: 1;', $css);
        $this->assertContains('color2: rgba(0, 1, 2, 0.3);', $css);
    }
Example #8
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.');
 }
Example #9
0
    [data] LONGVARCHAR,
    [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();
Example #10
0
require_once '_bootstrap.php';
class myLessUtils
{
    public static function foobar(ILess_FunctionRegistry $registry, ILess_Node $color = null)
    {
        // what can you do here, look to FunctionRegistry.php
        if ($color instanceof ILess_Node_Color) {
            return new ILess_Node_Anonymous('"Color is here"');
        }
        return new ILess_Node_Anonymous('"Foobar is here!"');
    }
}
try {
    $cacheDir = dirname(__FILE__) . '/cache';
    $parser = new ILess_Parser();
    // adds a function with an alias: fb
    $parser->addFunction('foobar', array('myLessUtils', 'foobar'), array('fb'));
    $parser->parseString('
  @color: red;
  #head {
    color: foobar(@color);
    font-size: fb();
  }');
} catch (Exception $e) {
    @header('HTTP/1.0 500 Internal Server Error');
    echo $e;
    exit;
}
$cssContent = $parser->getCSS();
file_put_contents($cacheDir . '/function.css', $cssContent);
Example #11
0
 public function testIssue()
 {
     $parser = new ILess_Parser();
     $parser->parseString("body {\n  color: fade(#ffcc00, 10%);\n}\n");
     $this->assertSame("body {\n  color: rgba(255, 204, 0, 0.1);\n}\n", $parser->getCSS());
 }
Example #12
0
<?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';
Example #13
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?
Example #14
0
File: CLI.php Project: 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;
 }