function lessc::chunk in Less CSS Preprocessor 6.3
1 call to lessc::chunk()
- lessc::parse in lessphp/lessc.inc.php
File
- lessphp/lessc.inc.php, line 48
Class
- lessc
Code
function chunk() {
if (empty($this->buffer)) {
return false;
}
$s = $this
->seek();
if ($this
->keyword($key) && $this
->assign() && $this
->propertyValue($value) && $this
->end()) {
if ($key[0] == $this->imPrefix && strlen($key) > 1) {
$key = substr($key, 1);
if ($value[0] == 'list' && $value[1] == ' ') {
$value[2][] = array(
'keyword',
'!important',
);
}
else {
$value = array(
'list',
' ',
array(
$value,
array(
'keyword',
'!important',
),
),
);
}
}
$this
->append($key, $value);
if (count($this->env) == 1) {
return $this
->compileProperty($key, array(
$value,
)) . "\n";
}
else {
return true;
}
}
else {
$this
->seek($s);
}
if (count($this->env) == 1 && $this->count < strlen($this->buffer) && $this->buffer[$this->count] == '@') {
if ($this
->literal('@font-face') && $this
->literal('{')) {
$this
->push();
$this
->set('__tags', array(
'@font-face',
));
$this
->set('__dontsave', true);
return true;
}
else {
$this
->seek($s);
}
if ($this
->literal('@charset') && $this
->propertyValue($value) && $this
->end()) {
return "@charset " . $this
->compileValue($value) . ";\n";
}
else {
$this
->seek($s);
}
}
if ($this
->variable($name) && $this
->assign() && $this
->propertyValue($value) && $this
->end()) {
$this
->append($this->vPrefix . $name, $value);
return true;
}
else {
$this
->seek($s);
}
if ($this
->tag($tag, true) && $this
->argumentDef($args) && $this
->literal('{')) {
$this
->push();
if ($tag[0] == $this->vPrefix) {
$tag[0] = $this->mPrefix;
}
$this
->set('__tags', array(
$tag,
));
if (isset($args)) {
$this
->set('__args', $args);
}
return true;
}
else {
$this
->seek($s);
}
if ($this
->tags($tags) && $this
->literal('{')) {
foreach ($tags as &$tag) {
if ($tag[0] == $this->vPrefix) {
$tag[0] = $this->mPrefix;
}
}
$this
->push();
$this
->set('__tags', $tags);
return true;
}
else {
$this
->seek($s);
}
if ($this
->literal('}')) {
$tags = $this
->multiplyTags();
$env = end($this->env);
$ctags = $env['__tags'];
unset($env['__tags']);
if (isset($env['__args'])) {
foreach ($env['__args'] as $arg) {
if (isset($arg[1])) {
$this
->prepend($this->vPrefix . $arg[0], $arg[1]);
}
}
}
if (!empty($tags)) {
$out = $this
->compileBlock($tags, $env);
}
$this
->pop();
if (!isset($env['__dontsave'])) {
foreach ($ctags as $t) {
if ($this
->get($t, array(
end($this->env),
))) {
$this
->merge($t, $env);
}
else {
$this
->set($t, $env);
}
}
}
return isset($out) ? $out : true;
}
if ($this
->import($url, $media)) {
if ($this->importDisabled) {
return "/* import is disabled */\n";
}
$full = $this->importDir . $url;
if (file_exists($file = $full) || file_exists($file = $full . '.less')) {
$loaded = $this
->removeComments(ltrim(file_get_contents($file) . ";"));
$this->buffer = substr($this->buffer, 0, $this->count) . $loaded . substr($this->buffer, $this->count);
return true;
}
return '@import url("' . $url . '")' . ($media ? ' ' . $media : '') . ";\n";
}
if ($this
->tags($tags, true, '>') && ($this
->argumentValues($argv) || true) && $this
->end()) {
$env = $this
->getEnv($tags);
if ($env == null) {
return true;
}
if (!empty($env['__args'])) {
foreach ($env['__args'] as $arg) {
$vname = $this->vPrefix . $arg[0];
$value = is_array($argv) ? array_shift($argv) : null;
if ($value == null && isset($arg[1])) {
$value = $arg[1];
}
if (isset($env[$vname])) {
array_unshift($env[$vname], $value);
}
else {
$env[$vname] = array(
$value,
);
}
}
}
ob_start();
$blocks = array();
foreach ($env as $name => $value) {
if (preg_match('/^__/', $name)) {
continue;
}
if (!isset($value[0])) {
$blocks[] = array(
$name,
$value,
);
}
if ($this
->get($name, array(
end($this->env),
))) {
while ($tval = array_shift($value)) {
$this
->append($name, $tval);
}
}
else {
$this
->set($name, $value);
}
}
foreach ($blocks as $b) {
$rtags = $this
->multiplyTags(array(
$b[0],
));
echo $this
->compileBlock($rtags, $b[1]);
}
return ob_get_clean();
}
else {
$this
->seek($s);
}
if ($this
->literal(';')) {
return true;
}
return false;
}