public static string Adjust(string content, Config config) { string cssFileContents = content; string absoluteOutputPath = config.GetAbsoluteOutputFile().FullName; // apply the RegEx to the file (to change relative paths) var matches = _rxUrl.Matches(cssFileContents); // Ignore the file if no match if (matches.Count > 0) { string cssDirectoryPath = config.GetAbsoluteInputFile().DirectoryName; if (!Directory.Exists(cssDirectoryPath)) { return(cssFileContents); } foreach (Match match in matches) { string quoteDelimiter = match.Groups[1].Value; //url('') vs url("") string relativePathToCss = match.Groups[2].Value; // Ignore root relative references if (relativePathToCss.StartsWith("/", StringComparison.Ordinal)) { continue; } //prevent query string from causing error var pathAndQuery = relativePathToCss.Split(new[] { '?' }, 2, StringSplitOptions.RemoveEmptyEntries); var pathOnly = pathAndQuery[0]; var queryOnly = pathAndQuery.Length == 2 ? pathAndQuery[1] : string.Empty; string absolutePath = GetAbsolutePath(cssDirectoryPath, pathOnly); if (string.IsNullOrEmpty(absoluteOutputPath) || string.IsNullOrEmpty(absolutePath)) { continue; } string serverRelativeUrl = FileHelpers.MakeRelative(absoluteOutputPath, absolutePath); if (!string.IsNullOrEmpty(queryOnly)) { serverRelativeUrl += "?" + queryOnly; } string replace = string.Format("url({0}{1}{0})", quoteDelimiter, serverRelativeUrl); cssFileContents = cssFileContents.Replace(match.Groups[0].Value, replace); } } return(cssFileContents); }
private void Processor_AfterWritingSourceMap(object sender, SourceMapEventArgs e) { Log.LogMessage(MessageImportance.High, "\tSourceMap " + FileHelpers.MakeRelative(FileName, e.ResultFile)); }
private void FileMinifier_AfterWritingGzipFile(object sender, MinifyFileEventArgs e) { Log.LogMessage(MessageImportance.High, "\tGzipped " + FileHelpers.MakeRelative(FileName, e.ResultFile)); }