/** * @covers getImporters */ public function testGetImporters() { $env = new ILess_Environment(); $importer = new ILess_Importer_FileSystem(); $i = new ILess_Importer($env, array('disc' => $importer), new ILess_Cache_None()); $this->assertEquals(array('disc' => $importer), $i->getImporters()); }
/** * Visits a import node * * @param ILess_Node_Import $node The node * @param ILess_Visitor_Arguments $arguments The arguments */ public function visitImport(ILess_Node_Import $node, ILess_Visitor_Arguments $arguments) { $arguments->visitDeeper = false; $inlineCSS = $node->getOption('inline'); if (!$node->css || $inlineCSS) { $e = null; try { $compiledNode = $node->compileForImport($this->env); } catch (ILess_Exception $e) { $compiledNode = false; if (!$e->getCurrentFile()) { if ($node->currentFileInfo) { $e->setCurrentFile($node->currentFileInfo, $node->index); } else { $e->setIndex($node->index); } } $node->css = true; $node->error = $e; } if ($compiledNode && (!$compiledNode->css || $inlineCSS)) { $node = $compiledNode; $env = ILess_Environment::createCopy($this->env, $this->env->frames); if ($node->getOption('multiple')) { $env->importMultiple = true; } // import the file list($alreadyImported, $file) = $this->importer->import($node->getPath(), $node->currentFileInfo, $node->options, $node->index); /* @var $file ILess_ImportedFile */ if ($alreadyImported && $node->currentFileInfo && $node->currentFileInfo->reference) { $node->skip = true; } elseif ($alreadyImported && !$env->importMultiple) { $node->skip = true; } if ($root = $file->getRuleset()) { /* @var $root ILess_Node_Ruleset */ $node->root = $root; $node->importedFilename = $file->getPath(); if (!$inlineCSS && !$node->skip) { $visitor = new ILess_Visitor_Import($env, $this->importer); $visitor->visit($root); } } } } return $node; }
/** * Parses a string * * @param string $string The string to parse * @param string $filename The filename for reference (will be visible in the source map) * @return ILess_Parser_Core */ public function parseString($string, $filename = '__string_to_parse__') { $string = ILess_Util::normalizeString((string) $string); // we need unique key $key = sprintf('%s[__%s__]', $filename, md5($string)); // create a dummy information, since we are not parsing a real file, // but a string comming from outside $this->env->setCurrentFile($filename); $importedFile = new ILess_ImportedFile($key, $string, time()); // save information, so the exceptions can handle errors in the string // and source map is generated for the string $this->env->currentFileInfo->importedFile = $importedFile; $this->importer->setImportedFile($key, $importedFile, $key, $this->env->currentFileInfo); if ($this->env->sourceMap) { $this->env->setFileContent($key, $string); } $this->rules = array_merge($this->rules, $this->parse($string)); return $this; }