public static HtmlString Stylesheet(this HtmlHelper helper, string cssUrl)
        {
            if (helper == null)
            {
                throw new ArgumentNullException("helper");
            }

            if (String.IsNullOrEmpty(cssUrl))
            {
                throw new ArgumentNullException("cssUrl");
            }

            var context = helper.ViewContext.HttpContext;

            var css      = CssBundleManager.GetCssBundle(cssUrl);
            var included = GetIncludedCssList(context);

            if (!included.Contains(css))
            {
                included.Add(css);

                return(new HtmlString(String.Format("    <link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\"/>\n",
#if !ASPNETMVC
                                                    WebUtility.HtmlEncode(ContentHashCache.ResolveWithHash(css)))));
#else
                                                    HttpUtility.HtmlAttributeEncode(ContentHashCache.ResolveWithHash(css))));
#endif
            }
            else
            {
                return(new HtmlString(""));
            }
        }
        public static IHtmlString StyleBundle(this HtmlHelper helper, string bundleKey)
        {
            if (helper == null)
            {
                throw new ArgumentNullException("helper");
            }

            if (String.IsNullOrEmpty(bundleKey))
            {
                throw new ArgumentNullException("bundleKey");
            }

            var context = helper.ViewContext.HttpContext;

            if (!CssBundleManager.IsEnabled)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var include in CssBundleManager.GetBundleIncludes(bundleKey))
                {
                    var cssUrl = include;
                    if (string.IsNullOrEmpty(cssUrl))
                    {
                        continue;
                    }

                    if (cssUrl != null && cssUrl.StartsWith("dynamic://", StringComparison.OrdinalIgnoreCase))
                    {
                        var scriptName = cssUrl.Substring(10);
                        cssUrl = DynamicScriptManager.GetScriptInclude(scriptName, ".css");
                        cssUrl = VirtualPathUtility.ToAbsolute("~/DynJS.axd/" + cssUrl);
                    }
                    else
                    {
                        cssUrl = BundleUtils.ExpandVersionVariable(cssUrl);
                        cssUrl = VirtualPathUtility.ToAbsolute(cssUrl);
                    }

                    var cssList = GetIncludedCssList(context);

                    if (!cssList.Contains(cssUrl))
                    {
                        cssList.Add(cssUrl);
                        sb.AppendLine(String.Format("    <link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\"/>\n",
#if !ASPNETMVC
                                                    WebUtility.HtmlEncode(ContentHashCache.ResolveWithHash(cssUrl))));
#else
                                                    HttpUtility.HtmlAttributeEncode(ContentHashCache.ResolveWithHash(cssUrl))));
#endif
                    }
                }

                return(new HtmlString(sb.ToString()));
            }

            return(Stylesheet(helper, "dynamic://CssBundle." + bundleKey));
        }
Esempio n. 3
0
        private static void Changed(string name)
        {
            var extension = Path.GetExtension(name);

            if (extension == null || string.Compare(extension, ".css", StringComparison.OrdinalIgnoreCase) != 0)
            {
                return;
            }

            ContentHashCache.ScriptsChanged();
            CssBundleManager.CssChanged();
        }
Esempio n. 4
0
        public static void CssChanged()
        {
            BundleUtils.ClearVersionCache();
            var instance = CssBundleManager.instance;

            if (instance != null &&
                instance.bundleByKey != null)
            {
                foreach (var bundle in instance.bundleByKey.Values)
                {
                    bundle.Changed();
                }
            }

            instance = null;
        }