/// <summary> /// Builds the content of the bundle. /// </summary> /// <param name="bundle">The bundle.</param> /// <param name="context">The context.</param> /// <param name="files">The files.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"> /// context /// or /// bundle /// </exception> public string BuildBundleContent(Bundle bundle, BundleContext context, IEnumerable <BundleFile> files) { if (files == null) { return(string.Empty); } if (context == null) { throw new ArgumentNullException("context"); } if (bundle == null) { throw new ArgumentNullException("bundle"); } StringBuilder stringBuilder = new StringBuilder(); string str1 = ""; if (context.EnableInstrumentation) { //str1 = HtmlTemplateBundleBuilder.GetBoundaryIdentifier(bundle); stringBuilder.AppendLine(HtmlTemplateBundleBuilder.GenerateBundlePreamble(str1)); } string str2 = (string)null; if (!string.IsNullOrEmpty(bundle.ConcatenationToken)) { str2 = bundle.ConcatenationToken; } else { foreach (object obj in (IEnumerable <IBundleTransform>)bundle.Transforms) { if (typeof(HtmlTemplateMinify).IsAssignableFrom(obj.GetType())) { str2 = ";" + Environment.NewLine; break; } } } if (str2 == null || context.EnableInstrumentation) { str2 = Environment.NewLine; } string tagFormat = "<script type=\"text/template\" id=\"{1}\">{0}</script>"; foreach (BundleFile bundleFile in files) { if (context.EnableInstrumentation) { stringBuilder.Append(HtmlTemplateBundleBuilder.GetFileHeader(context, bundleFile.VirtualFile, HtmlTemplateBundleBuilder.GetInstrumentedFileHeaderFormat(str1))); } string fileContent = bundleFile.ApplyTransforms(); fileContent = string.Format((IFormatProvider)CultureInfo.InvariantCulture, tagFormat, fileContent, bundleFile.VirtualFile.VirtualPath); stringBuilder.Append(fileContent); stringBuilder.Append(str2); } return(((object)stringBuilder).ToString()); }
/// <summary> /// Generates the bundle preamble. /// </summary> /// <param name="bundleHash">The bundle hash.</param> /// <returns></returns> private static string GenerateBundlePreamble(string bundleHash) { Dictionary <string, string> instrumentedBundlePreamble = HtmlTemplateBundleBuilder.GetInstrumentedBundlePreamble(bundleHash); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("/* "); foreach (string index in instrumentedBundlePreamble.Keys) { stringBuilder.Append(index + "=" + instrumentedBundlePreamble[index] + ";"); } stringBuilder.Append(" */"); return(((object)stringBuilder).ToString()); }
/// <summary> /// Gets the file header. /// </summary> /// <param name="context">The context.</param> /// <param name="file">The file.</param> /// <param name="fileHeaderFormat">The file header format.</param> /// <returns></returns> private static string GetFileHeader(BundleContext context, VirtualFile file, string fileHeaderFormat) { if (string.IsNullOrEmpty(fileHeaderFormat)) { return(string.Empty); } string applicationPath = HtmlTemplateBundleBuilder.GetApplicationPath(BundleTable.VirtualPathProvider); return(string.Format((IFormatProvider)CultureInfo.InvariantCulture, fileHeaderFormat, new object[1] { (object)HtmlTemplateBundleBuilder.ConvertToAppRelativePath(applicationPath, file.VirtualPath) }) + "\r\n"); }