/** * Compiler des styles inline LESS en CSS * * @param string $style * contenu du .less * @param array $contexte * file : chemin du fichier compile * utilise en cas de message d'erreur, et pour le repertoire de reference des @import * @return string */ function lesscss_compile($style, $contexte = array()) { static $import_dirs = null; require_once 'less.php/Less.php'; if (is_null($import_dirs)) { $path = _chemin(); $import_dirs = array(); foreach ($path as $p) { $import_dirs[$p] = protocole_implicite(url_absolue($p ? $p : "./")); } } $parser = new Less_Parser(); include_spip('inc/config'); $parser->setOption('sourceMap', lire_config('lesscss/activer_sourcemaps', false) == "on" ? true : false); $parser->setImportDirs($import_dirs); $parser->relativeUrls = true; try { $url_absolue = $contexte['file'] ? protocole_implicite(url_absolue($contexte['file'])) : null; $parser->parse($style, $url_absolue); $out = $parser->getCss(); if ($files = Less_Parser::AllParsedFiles() and count($files)) { $l = strlen(_DIR_RACINE); foreach ($files as $k => $file) { if (strncmp($file, _DIR_RACINE, $l) == 0) { $files[$k] = substr($file, $l); } } $out = "/*\n#@" . implode("\n#@", $files) . "\n*" . "/\n" . $out; } return $out; } catch (exception $ex) { spip_log('less.php fatal error:' . $ex->getMessage(), 'less' . _LOG_ERREUR); erreur_squelette("LESS : Echec compilation" . (isset($contexte['file']) ? " fichier " . $contexte['file'] : "") . "<br />" . $ex->getMessage()); return ''; } }
/** * Compile into a single string using PHPLess * * @access protected * @param mixed $contents * @return string */ protected function _compile_css() { $parser = new Less_Parser(); if (Arr::get($this->_config, 'minify_css', false)) { $parser->setOption('compress', true); } if (!empty($this->_import_dirs)) { $parser->SetImportDirs($this->_import_dirs); } foreach ($this->_paths['css'] as $file) { $file_location = $this->_get_file_location('css', $file); $parser->parseFile($file_location); } $css = $parser->getCss(); return $css; }