HTML minification view model
Inheritance: MarkupMinificationViewModelBase
コード例 #1
0
        public IActionResult Index(HtmlMinificationViewModel model)
        {
            if (ModelState.IsValid)
            {
                model = _minificationService.Minify(model);

                ModelState.Clear();
            }

            return View(model);
        }
コード例 #2
0
        public HtmlMinificationViewModel GetInitializationData()
        {
            var settings = Mapper.Map<HtmlMinificationSettingsViewModel>(new HtmlMinificationSettings());
            var model = new HtmlMinificationViewModel
            {
                SourceCode = string.Empty,
                Settings = settings,
                Result = null
            };

            return model;
        }
コード例 #3
0
        public HtmlMinificationViewModel Minify(HtmlMinificationViewModel model)
        {
            string cssMinifierName = model.Settings.CssMinifierName;
            string jsMinifierName = model.Settings.JsMinifierName;

            var settings = Mapper.Map<HtmlMinificationSettings>(model.Settings);
            ICssMinifier cssMinifier = _cssMinifierFactory.CreateMinifier(cssMinifierName);
            IJsMinifier jsMinifier = _jsMinifierFactory.CreateMinifier(jsMinifierName);

            var htmlMinifier = new HtmlMinifier(settings, cssMinifier, jsMinifier);
            var result = htmlMinifier.Minify(model.SourceCode, true);

            model.Result = Mapper.Map<MarkupMinificationResultViewModel>(result);

            return model;
        }