/// <summary> /// This returns the appropriate html string to include in the web page such that the requested bundle will be loaded. /// </summary> /// <param name="bundleName"></param> /// <param name="cssOrJs"></param> /// <param name="inDevelopment">This controls whether we supply individual files or development mode /// or single minified files/CDNs in non-development mode</param> /// <param name="getContentUrl">method to get url of content</param> /// <returns></returns> public string CalculateHtmlIncludes(string bundleName, CssOrJs cssOrJs, bool inDevelopment, Func<string, string> getContentUrl) { var settingFilePath = Path.Combine(_jsonDataDir, config.BundlesFileName); var reader = new ReadBundleFile(settingFilePath); var fileTypeInfo = config.GetFileTypeData(cssOrJs); if (inDevelopment) { var sb = new StringBuilder(); //we send the individual files as found in the bundle json file foreach (var relFilePath in _searcher.UnpackBundle(reader.GetBundleDebugFiles(bundleName))) { sb.AppendLine(fileTypeInfo.DebugHtmlFormatString .Replace(FileTypeConfigInfo.FileUrlParam, getContentUrl(relFilePath))); } return sb.ToString(); } //We are in nonDebug, i.e. production mode var cdnLinks = reader.GetBundleCdnInfo(bundleName); return cdnLinks.Any() ? FormCdnIncludes(cdnLinks, bundleName, cssOrJs, fileTypeInfo, getContentUrl) : FormSingleMinifiedFileInclude(bundleName, cssOrJs, fileTypeInfo, getContentUrl); }
public void TestGetBundleCdnInfoNonCdnOk() { //SETUP var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles01*.json")); //ATTEMPT var cdns = reader.GetBundleCdnInfo("standardLibsJs"); //VERIFY cdns.Count.ShouldEqual(0); }
public void TestGetBundleCdnInfoCdnOk() { //SETUP var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles02*.json")); //ATTEMPT var cdns = reader.GetBundleCdnInfo("standardLibsJs").ToList(); //VERIFY cdns.Count.ShouldEqual(2); var i = 0; cdns[i++].ToString().ShouldEqual("Development: jquery.js, Production: jquery.min.js, "+ "cdnUrl: https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js, cdnSuccessTest: window.jQuery"); cdns[i++].ToString().ShouldEqual("Development: bootstrap.js, Production: bootstrap.min.js, "+ "cdnUrl: https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.5/bootstrap.min.js, cdnSuccessTest: window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"); //foreach (var cdnInfo in cdns) //{ // Console.WriteLine("cdns[i++].ToString().ShouldEqual(\"{0}\");", cdnInfo); //} }
public void TestGetBundleCdnInfoCdnOk() { //SETUP var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles02*.json")); //ATTEMPT var cdns = reader.GetBundleCdnInfo("standardLibsJs").ToList(); //VERIFY cdns.Count.ShouldEqual(2); var i = 0; cdns[i++].ToString().ShouldEqual("Development: jquery.js, Production: jquery.min.js, " + "cdnUrl: https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js, cdnSuccessTest: window.jQuery"); cdns[i++].ToString().ShouldEqual("Development: bootstrap.js, Production: bootstrap.min.js, " + "cdnUrl: https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.5/bootstrap.min.js, cdnSuccessTest: window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"); //foreach (var cdnInfo in cdns) //{ // Console.WriteLine("cdns[i++].ToString().ShouldEqual(\"{0}\");", cdnInfo); //} }
/// <summary> /// Thic checks a specific bundle by name /// </summary> /// <param name="bundleName"></param> /// <returns>empty list if no error, otherwise a list of errors</returns> public ReadOnlyCollection <string> CheckSingleBundleIsValid(string bundleName) { var errors = new List <string>(); var allBundleDebugLines = _reader.GetBundleDebugFiles(bundleName, "", s => errors.Add(s)); var allCdns = _reader.GetBundleCdnInfo(bundleName); if (errors.Any()) { return(errors.AsReadOnly()); } if (!allCdns.Any()) { return(CheckNonCdnBundle(bundleName, allBundleDebugLines).AsReadOnly()); } //It has Cdns if (allBundleDebugLines.Count() != allCdns.Count()) { return new List <string> { $"The Bundle called {bundleName} contained both cdn and non cdn entries, which is not supported." } }