/** * Adds a chunk to the stack * The $index for less.php may be different from less.js since less.php does not chunkify inputs * * @param string $chunk * @param string $fileInfo * @param integer $index * @param mixed $mapLines */ public function add($chunk, $fileInfo = null, $index = 0, $mapLines = null) { //ignore adding empty strings if ($chunk === '') { return; } $sourceLines = array(); $sourceColumns = ' '; if ($fileInfo) { $url = $fileInfo['currentUri']; if (isset($this->contentsMap[$url])) { $inputSource = substr($this->contentsMap[$url], 0, $index); $sourceLines = explode("\n", $inputSource); $sourceColumns = end($sourceLines); } else { throw new Exception('Filename ' . $url . ' not in contentsMap'); } } $lines = explode("\n", $chunk); $columns = end($lines); if ($fileInfo) { if (!$mapLines) { $this->generator->addMapping($this->lineNumber + 1, $this->column, count($sourceLines), strlen($sourceColumns), $fileInfo['currentUri']); } else { for ($i = 0, $count = count($lines); $i < $count; $i++) { $this->generator->addMapping($this->lineNumber + $i + 1, $i === 0 ? $this->column : 0, count($sourceLines) + $i, $i === 0 ? strlen($sourceColumns) : 0, $fileInfo['currentUri']); } } } if (count($lines) === 1) { $this->column += strlen($columns); } else { $this->lineNumber += count($lines) - 1; $this->column = strlen($columns); } // add only chunk parent::add($chunk); }
/** * Get the current css buffer * * @return string */ public function getCss() { $precision = ini_get('precision'); @ini_set('precision', 16); $locale = setlocale(LC_NUMERIC, 0); setlocale(LC_NUMERIC, "C"); $root = new Less_Tree_Ruleset(array(), $this->rules); $root->root = true; $root->firstRoot = true; $this->PreVisitors($root); self::$has_extends = false; $evaldRoot = $root->compile($this->env); $this->PostVisitors($evaldRoot); if (Less_Parser::$options['sourceMap']) { $generator = new Less_SourceMap_Generator($evaldRoot, Less_Parser::$contentsMap, Less_Parser::$options); // will also save file // FIXME: should happen somewhere else? $css = $generator->generateCSS(); } else { $css = $evaldRoot->toCSS(); } if (Less_Parser::$options['compress']) { $css = preg_replace('/(^(\\s)+)|((\\s)+$)/', '', $css); } //reset php settings @ini_set('precision', $precision); setlocale(LC_NUMERIC, $locale); return $css; }
public function getCss() { $precision = ini_get('precision'); @ini_set('precision', 16); $locale = setlocale(LC_NUMERIC, 0); setlocale(LC_NUMERIC, "C"); try { $root = new Less_Tree_Ruleset(array(), $this->rules); $root->root = true; $root->firstRoot = true; $this->PreVisitors($root); self::$has_extends = false; $evaldRoot = $root->compile($this->env); $this->PostVisitors($evaldRoot); if (Less_Parser::$options['sourceMap']) { $generator = new Less_SourceMap_Generator($evaldRoot, Less_Parser::$contentsMap, Less_Parser::$options); $css = $generator->generateCSS(); } else { $css = $evaldRoot->toCSS(); }if (Less_Parser::$options['compress']) { $css = preg_replace('/(^(\s)+)|((\s)+$)/', '', $css); } } catch (Exception$exc) { }@ini_set('precision', $precision); setlocale(LC_NUMERIC, $locale); if ($this->mb_internal_encoding != '') { @ini_set("mbstring.internal_encoding", $this->mb_internal_encoding); $this->mb_internal_encoding = ''; }if (!empty($exc)) { throw $exc; }return $css; }
/** * Get the current css buffer * * @return string */ public function getCss() { $precision = ini_get('precision'); @ini_set('precision', 16); $locale = setlocale(LC_NUMERIC, 0); setlocale(LC_NUMERIC, "C"); try { $root = new Less_Tree_Ruleset(array(), $this->rules); $root->root = true; $root->firstRoot = true; $this->PreVisitors($root); self::$has_extends = false; $evaldRoot = $root->compile($this->env); $this->PostVisitors($evaldRoot); if (Less_Parser::$options['sourceMap']) { $generator = new Less_SourceMap_Generator($evaldRoot, Less_Parser::$contentsMap, Less_Parser::$options); // will also save file // FIXME: should happen somewhere else? $css = $generator->generateCSS(); } else { $css = $evaldRoot->toCSS(); } if (Less_Parser::$options['compress']) { $css = preg_replace('/(^(\\s)+)|((\\s)+$)/', '', $css); } } catch (Exception $exc) { // Intentional fall-through so we can reset environment } //reset php settings @ini_set('precision', $precision); setlocale(LC_NUMERIC, $locale); // If you previously defined $this->mb_internal_encoding // is required to return the encoding as it was before if ($this->mb_internal_encoding != '') { @ini_set("mbstring.internal_encoding", $this->mb_internal_encoding); $this->mb_internal_encoding = ''; } // Rethrow exception after we handled resetting the environment if (!empty($exc)) { throw $exc; } return $css; }