Example #1
0
        public void ToEdit(IValueProvider valueProvider)
        {
            var jsFile = valueProvider.GetFiles(Entities.FileType.Js)
                         .Where(i => !isInternal ^ i.IsInternal);

            var remover  = new Js.Visitors.JsEofTokenRemover();
            var wsEditor = new Js.Visitors.JsWsSymbolsEditor();

            foreach (var item in jsFile)
            {
                var jso    = new JsOptimizerFacade();
                var result = jso.ToOptimize(item.FileName, item.Tree.GetStream(), valueProvider.GetOutputMessages());
                if (result != null)
                {
                    item.Tree = new JsParser().ToParse(result);
                    remover.Remove(item.Tree);
                    wsEditor.Edit(item.Tree);
                }
            }
        }
Example #2
0
        public List <IOutputMessage> ToMinimize(MinimizationType min)
        {
            valueProvider = new ValueProvider();

            var csso = new CssOptimizer.Csso();
            var jso  = new JsOptimizerFacade();

            Parallel.ForEach(files, item => {
                var filePath = item.Key.Replace('/', '\\');

                var type      = fileIdentifying.GetType(filePath, item.Value);
                Stream stream = item.Value;

                if (type == Entities.FileType.Css &&
                    min.IsCommonCss)
                {
                    stream = csso.ToOptimize(item.Value) ?? stream;
                }
                else if (type == Entities.FileType.Js &&
                         min.IsCommonJs)
                {
                    stream = jso.ToOptimize(filePath, item.Value, valueProvider.GetOutputMessages()) ?? stream;
                }

                valueProvider.AddFile(parseFile.ToParse(filePath, stream, type));
            });

            List <Abstract.IEditor> listOpt = new List <Abstract.IEditor>();

            if (min.IsLoadExtJsFile)
            {
                listOpt.Add(new HtmlLoadExtJsEditor());
            }

            listOpt.Add(new HtmlInternalContentEditor());

            if (min.IsUnionJsFile)
            {
                listOpt.Add(new HtmlUnionJsEditor());
            }

            if (min.IsUnionCssFile)
            {
                listOpt.Add(new HtmlUnionCssEditor());
            }

            listOpt.Add(new JsWsSymbolsEditor());
            listOpt.Add(new JsEofTokenRemover());
            listOpt.Add(new HtmlWsSymbolsEditor());

            if (min.IsCommentHtml)
            {
                listOpt.Add(new HtmlCommentEditor());
            }

            if (min.IsCommonJs)
            {
                listOpt.Add(new JsMinifyingEditor());
                if (min.IsUnionJsFile)
                {
                    listOpt.Add(new JsMinifyingEditor(false));
                }
            }

            if (min.IsCommonCss)
            {
                listOpt.Add(new CssMinifyingEditor());
                if (min.IsUnionCssFile)
                {
                    listOpt.Add(new CssMinifyingEditor(false));
                }
            }

            if (min.IsNames)
            {
                listOpt.Add(new NamesEditor());
            }

            if (min.IsImage)
            {
                listOpt.Add(new ImageEditor());
            }

            listOpt.ForEach(i => i.ToEdit(valueProvider));

            var list = new List <IOutputMessage>();

            list.AddRange(valueProvider.GetOutputMessages());

            return(list);
        }