Exemplo n.º 1
0
        public static MvcHtmlString IncludeRejuicedCssFor(this HtmlHelper instance, string filename)
        {
            var cachedValue = GetCachedIncludesFor(filename);

            if (cachedValue != null)
            {
                return(cachedValue.RenderHtml());
            }

            var toInclude = GetIncludesFor(filename);
            var config    = RejuicerEngine.GetConfigFor(filename);

            if (config == null)
            {
                return(MvcHtmlString.Create(""));
            }

            var dependencies = config.GetDependencies();

            var links = MvcHtmlString.Create(string.Join("\n", toInclude.Select(f =>
            {
                // Output <script src='' type=''>
                var link = new TagBuilder("link");
                link.Attributes.Add("href", virtualPathResolver.GetRelativeUrl(f));
                link.Attributes.Add("rel", "stylesheet");
                link.Attributes.Add("type", "text/css");

                return(link.ToString(TagRenderMode.SelfClosing));
            }).ToArray()));

            var cachedIncludes = new IncludesCacheModel {
                IncludesHtml = links, HashValue = config.GetHashValue(cacheProvider)
            };

            SetCachedIncludesFor(filename, cachedIncludes, dependencies);

            return(cachedIncludes.RenderHtml());
        }
Exemplo n.º 2
0
        public static MvcHtmlString IncludeRejuicedJsFor(HtmlHelper instance, string filename)
        {
            var cachedValue = GetCachedIncludesFor(filename);

            if (cachedValue != null)
            {
                return(cachedValue.RenderHtml());
            }

            var toInclude = GetIncludesFor(filename);
            var config    = RejuicerEngine.GetConfigFor(filename);

            if (config == null)
            {
                return(MvcHtmlString.Create(""));
            }

            var dependencies = config.GetDependencies();

            var scripts = MvcHtmlString.Create(string.Join("\n", toInclude.Select(f =>
            {
                // Output <script src='' type=''>
                var script = new TagBuilder("script");
                script.Attributes.Add("src", UrlHelper.GenerateContentUrl(f, new HttpContextWrapper(HttpContext.Current)));
                script.Attributes.Add("type", "text/javascript");

                return(script.ToString(TagRenderMode.Normal));
            }).ToArray()));

            var cachedIncludes = new IncludesCacheModel {
                IncludesHtml = scripts, HashValue = config.GetHashValue(cacheProvider)
            };

            SetCachedIncludesFor(filename, cachedIncludes, dependencies);

            return(cachedIncludes.RenderHtml());
        }