private function import(&$lines, &$i, $extension = '.stylus') { $name = preg_replace('~@import\\s*[\'"]([^\'"]+)[\'"].*$~', '$1', $lines[$i]); if (preg_match('~^(.+)(\\..*)$~', $name, $matches)) { $name = $matches[1]; $extension = $matches[2]; } $dir = $this->import_dir ? $this->import_dir : $this->read_dir; $publicDir = app_path() . '/../public/css'; $isStylus = in_array($extension, array('.stylus', '.styl')); $path = ($isStylus && file_exists($dir . '/' . $name . $extension) ? $dir : $publicDir) . '/' . $name . $extension; if (!file_exists($path)) { $path = $publicDir . '/lib/' . $name . $extension; } $file_handle = fopen($path, 'r') or StylusException::report('Could not open ' . $path); $contents = fread($file_handle, filesize($path)) or StylusException::report('Could not read ' . $path); fclose($file_handle); DependancesCache::add($this->read_file, $path); if ($isStylus && class_exists('CssParser') && isset(CssParser::$activeInstance)) { $contents = CssParser::$activeInstance->filterCssb($contents); } $contents = str_replace(array('*/', '/*'), array("*/\n", "\n/*"), $contents); $c = count($lines); array_splice($lines, $i, 1, array_values(array_filter(preg_replace('~^\\s*}\\s*$~', '', preg_split('~\\r\\n|\\n|\\r~', $contents)), 'strlen')) + array("\n")); $lines = array_values($lines); $i -= $isStylus ? 1 : 1 + $c - count($lines); }
public static function resolveRequire($coffeeFile, $firstFile = null) { if (is_null($firstFile)) { $firstFile = $coffeeFile; } return preg_replace_callback('#\\/\\/-\\s*require\\s*\\(?\\s*([\'"])(.*(?<!\\\\)(?:\\\\{2})*)\\1(?:[ \\t]*,[ \\t]*(' . static::YES . '|' . static::NO . '))?[ \\t]*\\)?[ \\t]*(?=[\\n\\r]|$)#i', function ($match) use($coffeeFile, $firstFile) { $file = stripslashes($match[2]); $file = preg_match('#^(http|https|ftp|sftp|ftps):\\/\\/#', $file) ? $file : static::findFile($file); $isCoffee = empty($match[3]) ? ends_with($file, '.coffee') : in_array(strtolower($match[3]), explode('|', static::YES)); DependancesCache::add($firstFile, $file); $file = static::resolveRequire($file, $firstFile); if (!$isCoffee) { $file = "`{$file}`"; } return $file; }, file_get_contents($coffeeFile)); }