Exemplo n.º 1
0
 public void Configure()
 {
     // Pass this configuration to the compactor, so that it is remembered.
     if (_config.Count > 0)
     {
         RejuicerEngine.AddConfiguration(_config);
     }
 }
Exemplo n.º 2
0
        private static IEnumerable <string> GetIncludesFor(string filename)
        {
            var toInclude = new List <string>();

            if (RejuicerEngine.IsPassThroughEnabled)
            {
                toInclude.AddRange(RejuicerEngine.GetVirtualPathsFor(filename));
            }
            else
            {
                toInclude.Add(filename);
            }

            return(toInclude);
        }
Exemplo n.º 3
0
        /// <summary>
        /// A request has been received.
        /// </summary>
        private static void context_BeginRequest(object sender, EventArgs e)
        {
            var request   = HttpContext.Current.Request;
            var requested = request.Url;

            if (RejuicerEngine.HasConfigurationFor(requested) || RejuicerEngine.PassThroughDebuggingFor(requested))
            {
                var result = RejuicerEngine.GetContentFor(requested);

                var response = HttpContext.Current.Response;

                response.ContentType = result.ContentType;

                if (HttpRuntime.UsingIntegratedPipeline)
                {
                    response.Headers.Add("Last-Modified", result.LastModifiedDate.ToString());
                }

                if (result.AllowClientCaching)
                {
                    response.Expires      = (int)(result.CacheFor ?? TimeSpan.FromDays(365)).TotalMinutes;
                    response.CacheControl = "public";
                    // Any entity can cache this - be it the browser or a proxy server
                }
                else
                {
                    response.CacheControl = "no-cache";
                }

                if (HttpRuntime.UsingIntegratedPipeline &&
                    result.LastModifiedDate.ToString().Equals(request.Headers["If-Modified-Since"]))
                {
                    response.StatusCode = 304;
                }
                else
                {
                    response.BinaryWrite(result.Content);
                }

                response.Flush();

                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
        }
Exemplo n.º 4
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.º 5
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());
        }