示例#1
0
 public function parse($buffer, $presets = array())
 {
     $this->setVariables($presets);
     $parser = new Less_Parser($this->getOptions());
     $parser->setImportDirs($this->getImportDirs());
     if (count($this->registeredVars)) {
         $parser->ModifyVars($this->registeredVars);
     }
     foreach ($this->libFunctions as $name => $func) {
         $parser->registerFunction($name, $func);
     }
     $parser->parse($buffer);
     return $parser->getCss();
 }
示例#2
0
 public function parse($buffer, $presets = array())
 {
     $options = array();
     $this->setVariables($presets);
     switch ($this->formatterName) {
         case 'compressed':
             $options['compress'] = true;
             break;
     }
     $parser = new Less_Parser($options);
     $parser->setImportDirs($this->getImportDirs());
     if (count($this->registeredVars)) {
         $parser->ModifyVars($this->registeredVars);
     }
     $parser->parse($buffer);
     return $parser->getCss();
 }
/**
 * 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 '';
    }
}