Пример #1
0
        public static IHtmlString AutoIncludeScriptsFor(ViewContext viewContext, IBundleResolver bundleResolver = null, Func<string[], IHtmlString> scriptRenderer = null)
        {
            bundleResolver = bundleResolver ?? BundleResolver.Current;
            scriptRenderer = scriptRenderer ?? Scripts.Render;

            return new HtmlString(String.Join("\n", GetControllerScripts(viewContext, bundleResolver, scriptRenderer)
                                                    .Union(GetActionScripts(viewContext, bundleResolver, scriptRenderer))));
        }
Пример #2
0
        public static IHtmlString AutoIncludeScriptsFor(ViewContext viewContext, IBundleResolver bundleResolver = null, Func <string[], IHtmlString> scriptRenderer = null)
        {
            bundleResolver = bundleResolver ?? BundleResolver.Current;
            scriptRenderer = scriptRenderer ?? Scripts.Render;

            return(new HtmlString(string.Join("\n", GetControllerScripts(viewContext, bundleResolver, scriptRenderer)
                                              .Union(GetActionScripts(viewContext, bundleResolver, scriptRenderer)))));
        }
Пример #3
0
 private static IEnumerable<string> GetControllerScripts(ViewContext viewContext, IBundleResolver bundleResolver, Func<string[], IHtmlString> scriptRenderer)
 {
     var scripts = new List<IHtmlString>();
     var controllerScripts = GetControllerScriptsBundleNameFor(viewContext);
     var bundle = bundleResolver.GetBundleContents(controllerScripts);
     if (bundle != null && bundle.Any())
     {
         scripts.Add(scriptRenderer(new[] {controllerScripts}));
     }
     return scripts.Select(s => s.ToHtmlString());
 }
Пример #4
0
        // Given a list of asset references, remove duplicate bundle references, and eliminate any explicit references to things inside bundles
        // NOTE: Will not eliminate references that show up twice inside different bundles
        private IEnumerable <AssetTag> EliminateDuplicatesAndResolveUrls(IEnumerable <AssetTag> refs)
        {
            List <AssetTag>  firstPass       = new List <AssetTag>();
            HashSet <string> pathMap         = new HashSet <string>();
            HashSet <string> bundledContents = new HashSet <string>();
            IBundleResolver  resolver        = Resolver;

            // first eliminate any duplicate paths
            foreach (AssetTag asset in refs)
            {
                // Leave static assets alone
                if (asset.IsStaticAsset)
                {
                    firstPass.Add(asset);
                    continue;
                }

                string path = asset.Value;
                if (!pathMap.Contains(path))
                {
                    // Need to crack open bundles to look at its contents for the second pass
                    if (resolver.IsBundleVirtualPath(path))
                    {
                        IEnumerable <string> contents = resolver.GetBundleContents(path);
                        foreach (string filePath in contents)
                        {
                            bundledContents.Add(ResolveVirtualPath(filePath));
                        }
                        // Also need to resolve the bundle url to get the unique version
                        asset.Value = resolver.GetBundleUrl(path);
                        firstPass.Add(asset);
                    }
                    // Non bundles we want to resolve the path and check its not a duplicate before adding
                    else
                    {
                        string resolvedPath = ResolveVirtualPath(path);
                        if (!pathMap.Contains(resolvedPath))
                        {
                            pathMap.Add(resolvedPath);
                            asset.Value = resolvedPath;
                            firstPass.Add(asset);
                        }
                    }

                    pathMap.Add(path);
                }
            }

            // Second pass to eliminate files that are contained inside of bundles
            return(firstPass.Where(asset => asset.IsStaticAsset || !bundledContents.Contains(asset.Value)));
        }
Пример #5
0
        private static IEnumerable <string> GetControllerScripts(ViewContext viewContext, IBundleResolver bundleResolver, Func <string[], IHtmlString> scriptRenderer)
        {
            var scripts           = new List <IHtmlString>();
            var controllerScripts = GetControllerScriptsBundleNameFor(viewContext);
            var bundle            = bundleResolver.GetBundleContents(controllerScripts);

            if (bundle != null && bundle.Any())
            {
                scripts.Add(scriptRenderer(new[] { controllerScripts }));
            }
            return(scripts.Select(s => s.ToHtmlString()));
        }