Exemplo n.º 1
0
 /**
  * @see ILess_Importer::getLastModified
  */
 public function getLastModified($path, ILess_FileInfo $currentFileInfo)
 {
     $normalizedPath = ILess_Util::normalizePath($currentFileInfo->currentDirectory . $path);
     if (isset($this->files[$normalizedPath])) {
         $path = $normalizedPath;
     }
     if (isset($this->lastModified[$path])) {
         return $this->lastModified[$path];
     }
     return false;
 }
Exemplo n.º 2
0
Arquivo: Url.php Projeto: poef/ariadne
 /**
  * @see ILess_Node
  */
 public function compile(ILess_Environment $env, $arguments = null, $important = null)
 {
     $value = $this->value->compile($env);
     $rootPath = isset($this->currentFileInfo) && $this->currentFileInfo->rootPath ? $this->currentFileInfo->rootPath : false;
     if ($rootPath && is_string($value->value) && ILess_Util::isPathRelative($value->value)) {
         $quoteExists = self::propertyExists($value, 'quote');
         if ($quoteExists && empty($value->quote) || !$quoteExists) {
             $rootPath = preg_replace_callback('/[\\(\\)\'"\\s]/', array($this, 'rootPathReplaceCallback'), $rootPath);
         }
         $value->value = $rootPath . $value->value;
     }
     $value->value = ILess_Util::normalizePath($value->value, false);
     return new ILess_Node_Url($value, null);
 }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
0
 /**
  * Compiles the path
  *
  * @param ILess_Environment $env
  * @return ILess_Node_Url
  */
 public function compilePath(ILess_Environment $env)
 {
     $path = $this->path->compile($env);
     if (!$path instanceof ILess_Node_Url) {
         $rootPath = $this->currentFileInfo && $this->currentFileInfo->rootPath ? $this->currentFileInfo->rootPath : false;
         if ($rootPath) {
             $pathValue = $path->value;
             // Add the base path if the import is relative
             if ($pathValue && ILess_Util::isPathRelative($pathValue)) {
                 $path->value = $rootPath . $pathValue;
             }
         }
         $path->value = ILess_Util::normalizePath($path->value);
     }
     return $path;
 }
Exemplo n.º 5
0
 /**
  * Sets current file
  *
  * @param string $file The path to a file
  */
 public function setCurrentFile($file)
 {
     $file = ILess_Util::normalizePath($file);
     $dirname = preg_replace('/[^\\/\\\\]*$/', '', $file);
     $this->currentFileInfo = new ILess_FileInfo(array('currentDirectory' => $dirname, 'filename' => $file, 'rootPath' => $this->currentFileInfo && $this->currentFileInfo->rootPath ? $this->currentFileInfo->rootPath : $this->rootPath, 'entryPath' => $dirname));
 }
Exemplo n.º 6
0
 /**
  * @covers       normalizePath
  * @dataProvider getDataForNormalizePathTest
  */
 public function testNormalizePath($path, $expected)
 {
     $this->assertEquals(ILess_Util::normalizePath($path), $expected);
 }