Esempio n. 1
0
 /**
  * @see ILess_Node
  */
 public function generateCSS(ILess_Environment $env, ILess_Output $output)
 {
     if ($this->css) {
         $output->add('@import ', $this->currentFileInfo, $this->index);
         $this->path->generateCSS($env, $output);
         if ($this->features) {
             $output->add(' ');
             $this->features->generateCSS($env, $output);
         }
         $output->add(';');
     }
     return $output;
 }
Esempio n. 2
0
 /**
  * Inlines a resource and falls back to url() if the ieCompat option is on
  * and the resource is too large, or if you use the function in the browser.
  * If the mime is not given then node uses the mime package to determine the correct mime type.
  *
  * @param string $mimeType A mime type string
  * @param string $url The URL of the file to inline.
  */
 public function dataUri(ILess_Node $mimeType, ILess_Node $filePath = null)
 {
     if (func_num_args() < 2) {
         $path = $mimeType->value;
         $mime = false;
         // we will detect it later
     } else {
         $path = $filePath->value;
         $mime = $mimeType->value;
     }
     $path = ILess_Util::sanitizePath($path);
     if (ILess_Util::isPathRelative($path)) {
         if ($this->env->relativeUrls) {
             $path = $this->env->currentFileInfo->currentDirectory . $path;
         } else {
             $path = $this->env->currentFileInfo->entryPath . $path;
         }
         $path = ILess_Util::normalizePath($path);
     }
     if ($mime === false) {
         $mime = ILess_Mime::lookup($path);
         // use base 64 unless it's an ASCII or UTF-8 format
         $charset = ILess_Mime::charsetsLookup($mime);
         $useBase64 = !in_array($charset, array('US-ASCII', 'UTF-8'));
         if ($useBase64) {
             $mime .= ';base64';
         }
     } else {
         $useBase64 = preg_match('/;base64$/', $mime);
     }
     $buffer = false;
     if (is_readable($path)) {
         $buffer = file_get_contents($path);
     }
     // IE8 cannot handle a data-uri larger than 32KB. If this is exceeded
     // and the --ieCompat option is enabled, return a normal url() instead.
     if ($this->env->ieCompat && $buffer !== false) {
         $fileSizeInKB = round(strlen($buffer) / 1024);
         if ($fileSizeInKB >= self::IE8_DATA_URI_MAX_KB) {
             $url = new ILess_Node_Url($filePath ? $filePath : $mimeType, $this->env->currentFileInfo);
             return $url->compile($this->env);
         }
     }
     if ($buffer !== false) {
         $buffer = $useBase64 ? base64_encode($buffer) : rawurlencode($buffer);
         $path = "'data:" . $mime . ',' . $buffer . "'";
     }
     return new ILess_Node_Url(new ILess_Node_Anonymous($path));
 }
Esempio n. 3
0
 /**
  * @covers getType
  */
 public function testGetType()
 {
     $d = new ILess_Node_Url(new ILess_Node_Quoted('"http://foobar.com/less.css"', 'http://foobar.com/less.css'));
     $this->assertEquals('Url', $d->getType());
 }