Example #1
0
 public function testCompile()
 {
     $env = new ILess_Environment();
     $d = new ILess_Node_Import(new ILess_Node_Url(new ILess_Node_Quoted('"foobar.css"', 'foobar.css')));
     $result = $d->compile($env);
     $this->assertInstanceOf('ILess_Node_Import', $result);
     $this->assertEquals('@import url("foobar.css");', $result->toCSS($env));
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * @see ILess_Node
  */
 public function compile(ILess_Environment $env, $arguments = null, $important = null)
 {
     if ($this->skip) {
         return array();
     }
     if ($this->getOption('inline')) {
         // FIXME: this section is marked as "todo" in less.js project
         // see: lib/less/tree/import.js
         // original comment: todo needs to reference css file not import
         // $this->root is string here!
         $contents = new ILess_Node_Anonymous($this->root, 0, new ILess_FileInfo(array('filename' => $this->importedFilename)), true);
         return $this->features ? new ILess_Node_Media(array($contents), $this->features->value) : array($contents);
     } elseif ($this->css) {
         $features = $this->features ? $this->features->compile($env) : null;
         $import = new ILess_Node_Import($this->compilePath($env), $features, $this->options, $this->index);
         if (!$import->css && $import->hasError()) {
             throw $import->getError();
         }
         return $import;
     } else {
         $ruleset = new ILess_Node_Ruleset(array(), $this->root ? $this->root->rules : array());
         $ruleset->compileImports($env);
         return $this->features ? new ILess_Node_Media($ruleset->rules, $this->features->value) : $ruleset->rules;
     }
 }