/** * @inheritdoc */ public function generateCSS(Context $context, OutputInterface $output) { $isNotReference = !isset($this->path->currentFileInfo) || !$this->path->currentFileInfo->reference; if ($this->css && $isNotReference) { $output->add('@import '); $this->path->generateCSS($context, $output); if ($this->features) { $output->add(' '); $this->features->generateCSS($context, $output); } $output->add(';'); } return $output; }
/** * 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 Node $mimeType A mime type string * @param Node $url The URL of the file to inline. * @return UrlNode * @throws IOException */ public function dataUri(Node $mimeType, 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 = $this->getFilePath($path); list($fragment, $path) = Util::getFragmentAndPath($path); if ($mime === false) { $mime = Mime::lookup($path); if ($mime === 'image/svg+xml') { $useBase64 = false; } else { // use base 64 unless it's an ASCII or UTF-8 format $charset = Mime::charsetsLookup($mime); $useBase64 = !in_array($charset, ['US-ASCII', 'UTF-8']); } if ($useBase64) { $mime .= ';base64'; } } else { $useBase64 = (bool) preg_match('/;base64$/', $mime); } // the file was not found // FIXME: warn if (!is_readable($path)) { $url = new UrlNode($filePath ? $filePath : $mimeType, 0, $this->context->currentFileInfo); return $url->compile($this->context); } $buffer = file_get_contents($path); $buffer = $useBase64 ? base64_encode($buffer) : Util::encodeURIComponent($buffer); $uri = "data:" . $mime . ',' . $buffer . $fragment; // IE8 cannot handle a data-uri larger than 32KB. If this is exceeded // and the ieCompat option is enabled, return normal url() instead. if ($this->context->ieCompat) { if (strlen($uri) >= self::IE8_DATA_URI_MAX) { // FIXME: warn that we cannot use data uri here // FIXME: we don't have access to current index here! $url = new UrlNode($filePath ? $filePath : $mimeType); return $url->compile($this->context); } } // FIXME: we don't have any information about current index here! return new UrlNode(new QuotedNode('"' . $uri . '"', $uri, false)); }
/** * @covers getType */ public function testGetType() { $d = new UrlNode(new QuotedNode('"http://foobar.com/less.css"', 'http://foobar.com/less.css')); $this->assertEquals('Url', $d->getType()); }