public function __invoke($content, $file, $dir, $vars) { $content = preg_replace_callback('/@import\\s+["\']([a-z0-9\\/_-]+)["\']/i', function ($match) use($dir) { if ($match[1] == '/') { $filename = $match; } else { $filename = $dir . '/' . $match[1]; } $underscored = '_' . basename($filename); $underscored = dirname($filename) . '/' . $underscored; if ($this->pipeline->locator->hasFile($filename, 'css')) { $file = new File($filename . '.css'); } else { if ($this->pipeline->locator->hasFile($underscored, 'css')) { $file = new File($underscored . '.css'); } else { if ($this->pipeline->locator->hasFile($index_file = $filename . '/index', 'css')) { $file = new File($index_file . '.css'); } else { throw new \Sprockets\Exception\FileNotFound($filename, 'css'); } } } $this->pipeline->addDependency($file->getFilepath(), 'css'); return '@import "' . str_replace('//', '/', $file->getFilepath()) . '"'; }, $content); $content = $this->parser->toCss($content, false); return $content; }
public function __invoke($content, $file, $dir, $vars) { $base_url = str_repeat('../', substr_count($this->pipeline->getCacheDirectory(), '/')); return preg_replace_callback(self::URL_REGEX, function ($match) use($content, $dir, $base_url) { if (false !== strpos($match[1], '//')) { return 'url(' . $match[1] . ')'; } $file = new File(($dir ? $dir . '/' : '') . $match[1]); //XXX maybe we should actually cache the image? return 'url(' . preg_replace('/(?<!:)\\/\\//', '/', $base_url . $file->getFilepath()) . ')'; }, $content); }