Example #1
0
 public function libUrl(array $args, Compiler $compiler)
 {
     // Function has a single parameter.
     $parsed = reset($args);
     if (!$parsed) {
         $this->throwError('url() is missing parameter');
     }
     // Compile parsed value to string.
     $url = trim($compiler->compileValue($parsed), '\'"');
     // Handle ../ inside CSS files (points to current theme).
     $uri = strpos($url, '../') === 0 ? 'gantry-theme://' . substr($url, 3) : $url;
     // Generate URL, failed streams will be kept as they are to allow users to find issues.
     $url = Document::url($uri) ?: $url;
     // Changes absolute URIs to relative to make the path to work even if the site gets moved.
     if ($url[0] == '/' && $this->basePath) {
         $url = Folder::getRelativePathDotDot($url, $this->basePath);
     }
     // Return valid CSS.
     return "url('{$url}')";
 }
Example #2
0
 /**
  * @param string $name       Name of function to unregister.
  * @return $this
  */
 public function unregisterFunction($name)
 {
     $this->compiler->unregisterFunction($name);
     return $this;
 }