/** * Parse a Less string from a given file * * @throws ILess_Exception_Parser * @param string|ILess_ImportedFile $fil The file to parse (Will be loaded via the importers) * @param boolean $returnRuleset Indicates whether the parsed rules should be wrapped in a ruleset. * @return mixed If $returnRuleset is true, ILess_Parser_Core, ILess_Node_Ruleset otherwise */ public function parseFile($file, $returnRuleset = false) { // save the previous information $previousFileInfo = $this->env->currentFileInfo; if (!$file instanceof ILess_ImportedFile) { $this->env->setCurrentFile($file); if ($previousFileInfo) { $this->env->currentFileInfo->reference = $previousFileInfo->reference; } // try to load it via importer list(, $file) = $this->importer->import($file, $this->env->currentFileInfo); $this->env->setCurrentFile($file->getPath()); } else { $this->env->setCurrentFile($file->getPath()); if ($previousFileInfo) { $this->env->currentFileInfo->reference = $previousFileInfo->reference; } } $this->env->currentFileInfo->importedFile = $file; $rules = $this->parse($file->getContent()); if ($previousFileInfo) { $this->env->currentFileInfo = $previousFileInfo; } if ($returnRuleset) { return new ILess_Node_Ruleset(array(), $rules); } $this->rules = array_merge($this->rules, $rules); return $this; }
/** * 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; }