Пример #1
0
        private static void SetCachedIncludesFor(string filename, IncludesCacheModel value, IEnumerable <FileInfo> files)
        {
            // Create a depdency on all of the files
            var dependencies = RejuicerEngine.IsPassThroughEnabled ? null :
                               files.Where(f => f != null);

            cacheProvider.Add(GetCacheKeyFor(filename), value, dependencies);
        }
Пример #2
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());
        }
Пример #3
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());
        }