示例#1
0
 /**
  * @covers createCopy
  */
 public function testNormalizePath()
 {
     $env = new ILess_Environment();
     $copy = ILess_Environment::createCopy($env, array(1));
     $this->assertInstanceOf('ILess_Environment', $copy);
     $this->assertEquals($copy->frames, array(1));
 }
示例#2
0
文件: Importer.php 项目: poef/ariadne
 /**
  * Does the import
  *
  * @param ILess_ImportedFile $file The imported file
  * @param string $path The original path
  * @param ILess_FileInfo $currentFileInfo Current file info
  * @param array $importOptions Import options
  * @param boolean $fromCache Is the imported file coming from cache?
  * @return array
  */
 protected function doImport(ILess_ImportedFile $file, $path, ILess_FileInfo $currentFileInfo, array $importOptions = array(), $fromCache = false)
 {
     $newEnv = ILess_Environment::createCopy($this->env, $this->env->frames);
     $newFileInfo = clone $currentFileInfo;
     if ($this->env->relativeUrls) {
         // Pass on an updated rootPath if path of imported file is relative and file
         // is in a (sub|sup) directory
         //
         // Examples:
         // - If path of imported file is 'module/nav/nav.less' and rootPath is 'less/',
         //   then rootPath should become 'less/module/nav/'
         // - If path of imported file is '../mixins.less' and rootPath is 'less/',
         //   then rootPath should become 'less/../'
         if (!ILess_Util::isPathAbsolute($path) && ($lastSlash = strrpos($path, '/')) !== false) {
             $relativeSubDirectory = substr($path, 0, $lastSlash + 1);
             $newFileInfo->rootPath = $newFileInfo->rootPath . $relativeSubDirectory;
         }
     }
     // we need to clone here, to prevent modification of node current info object
     $newEnv->currentFileInfo = $newFileInfo;
     $newEnv->processImports = false;
     if ($currentFileInfo->reference || isset($importOptions['reference']) && $importOptions['reference']) {
         $newEnv->currentFileInfo->reference = true;
     }
     $key = $file->getPath();
     $error = $root = null;
     $alreadyImported = false;
     // check for already imported file
     if (isset($this->importedFiles[$key])) {
         $alreadyImported = true;
     } elseif (!$file->getRuleset()) {
         $parser = new ILess_Parser_Core($newEnv, $this);
         try {
             // we do not parse the root but load the file as is
             if (isset($importOptions['inline']) && $importOptions['inline']) {
                 $root = $file->getContent();
             } else {
                 $root = $parser->parseFile($file, true);
                 $root->root = false;
                 $root->firstRoot = false;
             }
             $file->setRuleset($root);
             // we need to catch parse exceptions
         } catch (ILess_Exception_Parser $e) {
             // rethrow
             throw $e;
         } catch (Exception $error) {
             // FIXME: what other exceptions are allowed here?
             $file->setError($error);
         }
         $this->setImportedFile($key, $file, $path, $currentFileInfo);
     } else {
         $this->setImportedFile($key, $file, $path, $currentFileInfo);
     }
     if ($fromCache) {
         $ruleset = $this->importedFiles[$key][0]->getRuleset();
         if ($ruleset instanceof ILess_Node) {
             // FIXME: this is a workaround for reference and import one issues
             // when taken cache
             $this->updateReferenceInCurrentFileInfo($ruleset, $newEnv->currentFileInfo->reference);
         }
     }
     return array($alreadyImported, $this->importedFiles[$key][0]);
 }
示例#3
0
文件: Import.php 项目: poef/ariadne
 /**
  * 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;
 }
示例#4
0
 /**
  * Match a condition
  *
  * @param array $arguments
  * @param ILess_Environment $env
  * @return boolean
  */
 public function matchCondition(array $arguments, ILess_Environment $env)
 {
     if (!$this->condition) {
         return true;
     }
     $frame = $this->compileParams($env, ILess_Environment::createCopy($env, array_merge($this->frames, $env->frames)), $arguments);
     $compileEnv = ILess_Environment::createCopy($env, array_merge(array($frame), $this->frames, $env->frames));
     if (!$this->condition->compile($compileEnv)) {
         return false;
     }
     return true;
 }
示例#5
0
文件: Ruleset.php 项目: poef/ariadne
 /**
  * Match condition
  *
  * @param array $arguments
  * @param ILess_Environment $env
  * @return boolean
  */
 public function matchCondition(array $arguments, ILess_Environment $env)
 {
     $lastSelector = end($this->selectors);
     if ($lastSelector->condition && !$lastSelector->condition->compile(ILess_Environment::createCopy($env, $env->frames))) {
         return false;
     }
     return true;
 }