B4BCore.BundlerForBower.CalculateHtmlIncludes C# (CSharp) Method

CalculateHtmlIncludes() public method

This returns the appropriate html string to include in the web page such that the requested bundle will be loaded.
public CalculateHtmlIncludes ( string bundleName, CssOrJs cssOrJs, bool inDevelopment, string>.Func getContentUrl ) : string
bundleName string
cssOrJs CssOrJs
inDevelopment bool This controls whether we supply individual files or development mode /// or single minified files/CDNs in non-development mode
getContentUrl string>.Func method to get url of content
return string
        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);
        }

Usage Example

        public void TestBundlerForBowerCssNonDebugOk()
        {
            //SETUP
            var b4b = new BundlerForBower(B4BSetupHelper.GetDirRelToTestDirectory("NoConfig\\"),
                B4BSetupHelper.GetActualFilePathFromVirtualPath(), B4BSetupHelper.GetChecksumFromRelPath());

            //ATTEMPT
            var output = b4b.CalculateHtmlIncludes("mainCss", CssOrJs.Css, false, s => "url:" + s.Substring(2));

            //VERIFY
            output.ShouldEqual("<link href='url:css/mainCss.min.css?v=TdTxYoaXjmCw1qNZ3ECkVr0eMx3rj6OFikZ6GH_a_Hw' rel='stylesheet'/>");
        }
All Usage Examples Of B4BCore.BundlerForBower::CalculateHtmlIncludes