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); }
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); }
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()); }
public function testIssue() { $parser = new ILess_Parser(); $parser->parseString('.test{ background-color: darken("#ffffff",2%); }'); $this->setExpectedException('ILess_Exception_Function'); $parser->getCSS(); }
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(); }
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); }
} $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); $css = 'cache/database.css'; } catch (Exception $e) { @header('HTTP/1.0 500 Internal Server Error'); echo $e; exit; } $example = 'database importer';
{ 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); $css = 'cache/function.css'; $example = 'custom function'; include '_page.php';
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()); }
<?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';
/** * 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; }