Beispiel #1
0
        public ActionResult Javascript(string keys)
        {
            string result = _provider.GetFromCache("resources.javascript." + Request.Url.PathAndQuery, () =>
            {
                var scriptFiles = keys.Split('|').ToList();

                var sb = new StringBuilder();

                foreach (var s in scriptFiles)
                {
                    var script = MothScriptHelper.GetFileContent(new List <string> {
                        s
                    }, HttpContext).ToString();
                    if (_provider.Enable.ScriptMinification)
                    {
                        script = JavaScriptCompressor.Compress(script, false, true, true, false, Int32.MaxValue, Encoding.UTF8, new CultureInfo("en-US"));
                    }
                    sb.AppendLine(script);
                }

                return(sb.ToString());
            }, _provider.CacheDurations.ExternalScript);

            return(new ContentResult()
            {
                Content = result,
                ContentType = "text/javascript",
            });
        }
Beispiel #2
0
        public ActionResult Css(string keys)
        {
            var cssFiles = keys.Split('|').ToList();

            string result = _provider.GetFromCache("resources.css." + Request.Url.PathAndQuery, () =>
            {
                var sb = new StringBuilder();
                string stylos;

                if (_provider.Enable.CssPreprocessing)
                {
                    foreach (var f in cssFiles)
                    {
                        CSSDocument doc;
                        var definition = GenerateSpriteDefinition(f);

                        sb.AppendLine(definition.Document.ToOutput());
                    }
                    stylos = sb.ToString();
                }
                else
                {
                    stylos = MothScriptHelper.GetFileContent(cssFiles, HttpContext).ToString();
                }

                if (_provider.Enable.ScriptMinification)
                {
                    // minification
                    stylos = CssCompressor.Compress(stylos);
                }
                return(stylos);
            }, _provider.CacheDurations.ExternalScript);


            return(new ContentResult()
            {
                Content = result,
                ContentType = "text/css"
            });
        }