/// <summary> /// Writes the actual contents of a file or request result to the stream and ensures the contents are minified if necessary /// </summary> /// <param name="provider"></param> /// <param name="sw"></param> /// <param name="content"></param> /// <param name="type"></param> /// <param name="context"></param> /// <param name="originalUrl">The original Url that the content is related to</param> internal static void WriteContentToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, string content, ClientDependencyType type, HttpContextBase context, string originalUrl) { if (type == ClientDependencyType.Css) { IEnumerable <string> importedPaths; var removedImports = CssHelper.ParseImportStatements(content, out importedPaths); //need to write the imported sheets first since these theoretically should *always* be at the top for browser to support them foreach (var importPath in importedPaths) { var uri = new Uri(originalUrl, UriKind.RelativeOrAbsolute) .MakeAbsoluteUri(context); var absolute = uri.ToAbsolutePath(importPath); provider.WritePathToStream(ClientDependencyType.Css, absolute, context, sw); } //ensure the Urls in the css are changed to absolute var parsedUrls = CssHelper.ReplaceUrlsWithAbsolutePaths(removedImports, originalUrl, context); //then we write the css with the removed import statements sw.WriteLine(provider.MinifyFile(parsedUrls, ClientDependencyType.Css)); } else { sw.WriteLine(provider.MinifyFile(content, type)); } }
private static void WriteContentToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, FileInfo inputFile, Stream stream, ClientDependencyType type, HttpContextBase context, string originalUrl) { if (type == ClientDependencyType.Css) { IEnumerable <string> importedPaths; string externalImports; CssHelper.ParseImportStatements(stream, out importedPaths, out externalImports); //we can write the external imports found at the top sw.WriteLine(externalImports); //need to write the imported sheets first since these theoretically should *always* be at the top for browser to support them foreach (var importPath in importedPaths) { var uri = new Uri(originalUrl, UriKind.RelativeOrAbsolute) .MakeAbsoluteUri(context); var absolute = uri.ToAbsolutePath(importPath); provider.WritePathToStream(ClientDependencyType.Css, absolute, context, sw); } var minified = GetMinifiedOutput(provider, type, inputFile, stream); //ensure the Urls in the css are changed to absolute var parsedUrls = CssHelper.ReplaceUrlsWithAbsolutePaths(minified, originalUrl, context); //then we write the css with the removed import statements sw.WriteLine(parsedUrls); } else { sw.WriteLine(GetMinifiedOutput(provider, type, inputFile, stream)); } }