Beispiel #1
0
 /**
  * Compiles the node
  *
  * @param ILess_Environment $env
  */
 public function compile(ILess_Environment $env, $arguments = null, $important = null)
 {
     $inParenthesis = $this->parens && !$this->parensInOp;
     $doubleParen = false;
     if ($inParenthesis) {
         $env->inParenthesis();
     }
     $count = count($this->value);
     if ($count > 1) {
         $compiled = array();
         foreach ($this->value as $v) {
             $compiled[] = $v->compile($env);
         }
         $return = new ILess_Node_Expression($compiled);
     } elseif ($count === 1) {
         if (!isset($this->value[0])) {
             $this->value = array_slice($this->value, 0);
         }
         if (property_exists($this->value[0], 'parens') && $this->value[0]->parens && property_exists($this->value[0], 'parensInOp') && !$this->value[0]->parensInOp) {
             $doubleParen = true;
         }
         $return = $this->value[0]->compile($env);
     } else {
         $return = $this;
     }
     if ($inParenthesis) {
         $env->outOfParenthesis();
     }
     if ($this->parens && $this->parensInOp && !$env->isMathOn() && !$doubleParen) {
         $return = new ILess_Node_Paren($return);
     }
     return $return;
 }
Beispiel #2
0
 /**
  * Compiles the node
  *
  * @param ILess_Environment $env
  */
 public function compile(ILess_Environment $env, $arguments = null, $important = null)
 {
     if ($env->isMathOn()) {
         $operation = new ILess_Node_Operation('*', array(new ILess_Node_Dimension('-1'), $this->value));
         return $operation->compile($env);
     } else {
         return new ILess_Node_Negative($this->value->compile($env));
     }
 }
Beispiel #3
0
 /**
  * Converts the ruleset to CSS
  *
  * @param ILess_Node_Ruleset $ruleset
  * @param array $variables
  * @return string The generated CSS code
  */
 protected function toCSS(ILess_Node_Ruleset $ruleset, array $variables)
 {
     $this->setupMathAndLocale();
     $this->prepareVariables($this->env, $variables);
     // precompilation visitors
     foreach ($this->getPreCompileVisitors() as $visitor) {
         $visitor->run($ruleset);
     }
     // compile the ruleset
     $compiled = $ruleset->compile($this->env);
     // post compilation visitors
     foreach ($this->getPostCompileVisitors() as $visitor) {
         $visitor->run($compiled);
     }
     if ($this->getEnvironment()->sourceMap) {
         $generator = new ILess_SourceMap_Generator($compiled, $this->env->getContentsMap(), $this->env->sourceMapOptions);
         // will also save file
         // FIXME: should happen somewhere else?
         $css = $generator->generateCSS($this->env);
     } else {
         $css = $compiled->toCSS($this->env);
     }
     if ($this->env->compress) {
         $css = preg_replace('/(^(\\s)+)|((\\s)+$)/', '', $css);
     }
     $this->restoreMathAndLocale();
     return $css;
 }
Beispiel #4
0
 /**
  * Sets the imported file
  *
  * @param string $pathAbsolute The absolute path
  * @param ILess_ImportedFile $file The imported file
  * @param string $path The original path to import
  * @param ILess_FileInfo $currentFileInfo
  * @return ILess_Importer
  */
 public function setImportedFile($pathAbsolute, ILess_ImportedFile $file, $path, ILess_FileInfo $currentFileInfo)
 {
     $this->importedFiles[$pathAbsolute] = array($file, $path, $currentFileInfo);
     // save for source map generation
     $this->env->setFileContent($pathAbsolute, $file->getContent());
     return $this;
 }
Beispiel #5
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));
 }
Beispiel #6
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;
 }
Beispiel #7
0
 /**
  * Creates a copy of the environment
  *
  * @param ILess_Environment $env
  * @param array $frames
  * @return ILess_Environment
  */
 public static function createCopy(ILess_Environment $env, array $frames = array())
 {
     // what to copy?
     $copyProperties = array('compress', 'canShortenColors', 'precision', 'ieCompat', 'strictMath', 'strictUnits', 'sourceMap', 'sourceMapOptions', 'importMultiple', 'relativeUrls', 'rootPath', 'dumpLineNumbers', 'contentsMap', 'customVariables', 'currentFileInfo');
     $copy = new ILess_Environment(array(), $env->getFunctionRegistry());
     foreach ($copyProperties as $property) {
         if (property_exists($env, $property)) {
             $copy->{$property} = $env->{$property};
         }
     }
     $copy->frames = $frames;
     return $copy;
 }
Beispiel #8
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;
 }
Beispiel #9
0
 /**
  * Compiles the node
  *
  * @param ILess_Environment $env
  * @return ILess_Node_Directive
  */
 public function compile(ILess_Environment $env, $arguments = null, $important = null)
 {
     $evaldDirective = $this;
     if ($this->rules) {
         $env->unshiftFrame($this);
         $evaldDirective = new ILess_Node_Directive($this->name, null, $this->index, $this->currentFileInfo);
         $evaldDirective->rules = array($this->rules[0]->compile($env));
         $evaldDirective->rules[0]->root = true;
         $env->shiftFrame();
     }
     return $evaldDirective;
 }
Beispiel #10
0
 /**
  * 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;
 }