Пример #1
0
        private string InstallModuleScripts(IModule module)
        {
            var rootpath = System.Web.HttpContext.Current.Server.MapPath("~/Scripts/mods/");
            var rootDir  = new DirectoryInfo(rootpath);

            if (!rootDir.Exists)
            {
                rootDir.Create();
            }

            StringBuilder info = new StringBuilder();

            var moduleScripts = new List <ClientScript>();

            moduleScripts.AddRange(module.UIProvider.GetClientScripts(UserTypes.Admin));
            moduleScripts.AddRange(module.UIProvider.GetClientScripts(UserTypes.Customer));
            moduleScripts.AddRange(module.UIProvider.GetClientScripts(UserTypes.Librarian));
            info.AppendFormat("<h4>Scripts</h4>");
            info.Append("<ul>");
            SquishIt.Framework.Minifiers.JavaScript.JsMinMinifier min = new SquishIt.Framework.Minifiers.JavaScript.JsMinMinifier();
            foreach (var script in moduleScripts.Distinct(new ClientScriptComperer()))
            {
                var scriptpath = Path.Combine(rootpath, script.Name + ".js");
                if (System.IO.File.Exists(scriptpath))
                {
                    System.IO.File.Delete(scriptpath);
                }

                using (var writer = System.IO.File.CreateText(scriptpath))
                {
                    writer.Write(min.Minify(script.Content)); //TODO: Compress
                    writer.Flush();
                }
                info.AppendFormat("<li>{0}</li>", script.Name);
            }
            info.Append("</ul>");
            return(info.ToString());
        }
Пример #2
0
        public MinificationResult Get(JObject jsonData)
        {
            dynamic json = jsonData;
            string source = json.source;

            if (string.IsNullOrWhiteSpace(source))
            {
                throw new ArgumentNullException("source");
            }

            var result = new MinificationResult { OriginalSize = new FileSize(source.Length), };

            //var closureMin = new SquishIt.Framework.Minifiers.JavaScript.ClosureMinifier();
            //string closeureMinContent = closureMin.Minify(source).TrimStart('\n', ' ');

            //var closureResultType = new MinificationType(result, "JsMinMinifier")
            //                            {
            //                                MinifiedContent = closeureMinContent,
            //                                MinifiedSize =
            //                                    new FileSize(
            //                                    closeureMinContent.Length),
            //                            };

            var jsMin = new SquishIt.Framework.Minifiers.JavaScript.JsMinMinifier();
            string jsMinContent = jsMin.Minify(source).TrimStart('\n', ' ');

            var jsMinResultType = new MinificationType(result, "JsMinMinifier")
                                      {
                                          MinifiedContent = jsMinContent,
                                          MinifiedSize =
                                              new FileSize(jsMinContent.Length),
                                      };

            var ms = new SquishIt.Framework.Minifiers.JavaScript.MsMinifier();
            string msConfig = ms.Minify(source).TrimStart('\n', ' ');

            var msResultType = new MinificationType(result, "MsMinifier")
                                   {
                                       MinifiedContent = msConfig,
                                       MinifiedSize = new FileSize(msConfig.Length),
                                   };

            var yui = new Yahoo.Yui.Compressor.JavaScriptCompressor
                          {
                              CompressionType =
                                  Yahoo.Yui.Compressor.CompressionType
                                       .Standard,
                              DisableOptimizations = false,
                          };
            string yuiContent = yui.Compress(source).TrimStart('\n', ' ');

            var yuiResultType = new MinificationType(result, "YuiMinifier")
                                    {
                                        MinifiedContent = yuiContent,
                                        MinifiedSize =
                                            new FileSize(yuiContent.Length),
                                    };

            result.Types = new[] { jsMinResultType, msResultType, yuiResultType }; //, closureResultType };
            return result;
        }
Пример #3
0
        private string InstallModuleScripts(IModule module)
        {
            var rootpath = System.Web.HttpContext.Current.Server.MapPath("~/Scripts/mods/");
            var rootDir = new DirectoryInfo(rootpath);
            if (!rootDir.Exists)
                rootDir.Create();

            StringBuilder info = new StringBuilder();

            var moduleScripts = new List<ClientScript>();
            moduleScripts.AddRange(module.UIProvider.GetClientScripts(UserTypes.Admin));
            moduleScripts.AddRange(module.UIProvider.GetClientScripts(UserTypes.Customer));
            moduleScripts.AddRange(module.UIProvider.GetClientScripts(UserTypes.Librarian));
            info.AppendFormat("<h4>Scripts</h4>");
            info.Append("<ul>");
            SquishIt.Framework.Minifiers.JavaScript.JsMinMinifier min = new SquishIt.Framework.Minifiers.JavaScript.JsMinMinifier();
            foreach (var script in moduleScripts.Distinct(new ClientScriptComperer()))
            {
                var scriptpath = Path.Combine(rootpath, script.Name + ".js");
                if (System.IO.File.Exists(scriptpath))
                    System.IO.File.Delete(scriptpath);

                using (var writer = System.IO.File.CreateText(scriptpath))
                {
                    writer.Write(min.Minify(script.Content)); //TODO: Compress
                    writer.Flush();
                }
                info.AppendFormat("<li>{0}</li>", script.Name);
            }
            info.Append("</ul>");
            return info.ToString();
        }