Example #1
0
 private static AssetLocation CompressAndCompile(AssetKey key, IEnumerable<AssetLocation> assetLocations)
 {
     var text = assetLocations.Select(x =>
         {
             var fileContent = File.ReadAllText(x.PhysicalPath);
             var resourceProcessors = key.AssetType == AssetType.JS ? javaScriptProcessors : cssProcessors;
             foreach (var processor in resourceProcessors)
                 fileContent = processor.ProcessFile(fileContent, key.AssetType, x.PhysicalPath, x.ContentPath);
             return fileContent;
         });
     var compiled = CompileText(text);
     var compressed = string.Empty;
     if (key.AssetType == AssetType.JS)
     {
         compressed = new JavaScriptCompressor(compiled, false, Encoding.UTF8, CultureInfo.CurrentCulture).Compress();
     }
     else if (key.AssetType == AssetType.CSS)
     {
         compressed = CssCompressor.Compress(compiled);
     }
     else
         throw new NotSupportedException();
     var fileName = key.ToCompiledName() + "." + key.AssetType.ToString().ToLower();
     var physicalPath = Path.Combine(outputDirectoryPath, fileName);
     File.WriteAllText(physicalPath, compressed, Encoding.UTF8);
     var contentPath = outputContentPath + fileName;
     return new AssetLocation(contentPath, physicalPath);
 }