/// <summary> /// Constructs a instance of Clean CSS-minifier /// </summary> /// <param name="createJsEngineInstance">Delegate that creates an instance of JavaScript engine</param> /// <param name="cleanConfig">Configuration settings of Clean-css Minifier</param> public CleanCssMinifier(Func<IJsEngine> createJsEngineInstance, CleanSettings cleanConfig) { CssMinifierSettings cssMinifierConfig = cleanConfig.Css; Advanced = cssMinifierConfig.Advanced; AggressiveMerging = cssMinifierConfig.AggressiveMerging; Compatibility = cssMinifierConfig.Compatibility; KeepBreaks = cssMinifierConfig.KeepBreaks; KeepSpecialComments = cssMinifierConfig.KeepSpecialComments; MediaMerging = cssMinifierConfig.MediaMerging; Restructuring = cssMinifierConfig.Restructuring; RoundingPrecision = cssMinifierConfig.RoundingPrecision; SemanticMerging = cssMinifierConfig.SemanticMerging; ShorthandCompacting = cssMinifierConfig.ShorthandCompacting; Severity = cssMinifierConfig.Severity; if (createJsEngineInstance == null) { string jsEngineName = cleanConfig.JsEngine.Name; if (string.IsNullOrWhiteSpace(jsEngineName)) { throw new ConfigurationErrorsException( string.Format(CoreStrings.Configuration_JsEngineNotSpecified, "clean", @" * JavaScriptEngineSwitcher.Msie * JavaScriptEngineSwitcher.V8", "MsieJsEngine") ); } createJsEngineInstance = (() => JsEngineSwitcher.Current.CreateJsEngineInstance(jsEngineName)); } _createJsEngineInstance = createJsEngineInstance; }
/// <summary> /// Constructs a instance of Clean CSS minifier /// </summary> /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param> /// <param name="cleanConfig">Configuration settings of Clean-css Minifier</param> public CleanCssMinifier(Func <IJsEngine> createJsEngineInstance, CleanSettings cleanConfig) { CssMinifierSettings cssMinifierConfig = cleanConfig.Css; FormattingSettings formattingConfig = cssMinifierConfig.Formatting; BreaksInsertingSettings breaksInsertingConfig = formattingConfig.BreaksInserting; SpacesInsertingSettings spacesInsertingConfig = formattingConfig.SpacesInserting; Level1OptimizationSettings level1OptimizationConfig = cssMinifierConfig.Level1Optimizations; Level2OptimizationSettings level2OptimizationConfig = cssMinifierConfig.Level2Optimizations; Compatibility = cssMinifierConfig.Compatibility; FormattingOptions = new FormattingOptions { BreaksInsertingOptions = new BreaksInsertingOptions { AfterAtRule = breaksInsertingConfig.AfterAtRule, AfterBlockBegins = breaksInsertingConfig.AfterBlockBegins, AfterBlockEnds = breaksInsertingConfig.AfterBlockEnds, AfterComment = breaksInsertingConfig.AfterComment, AfterProperty = breaksInsertingConfig.AfterProperty, AfterRuleBegins = breaksInsertingConfig.AfterRuleBegins, AfterRuleEnds = breaksInsertingConfig.AfterRuleEnds, BeforeBlockEnds = breaksInsertingConfig.BeforeBlockEnds, BetweenSelectors = breaksInsertingConfig.BetweenSelectors }, IndentBy = formattingConfig.IndentBy, IndentWith = formattingConfig.IndentWith, SpacesInsertingOptions = new SpacesInsertingOptions { AroundSelectorRelation = spacesInsertingConfig.AroundSelectorRelation, BeforeBlockBegins = spacesInsertingConfig.BeforeBlockBegins, BeforeValue = spacesInsertingConfig.BeforeValue }, WrapAt = formattingConfig.WrapAt }; Level = cssMinifierConfig.Level; Level1OptimizationOptions = new Level1OptimizationOptions { CleanupCharsets = level1OptimizationConfig.CleanupCharsets, NormalizeUrls = level1OptimizationConfig.NormalizeUrls, OptimizeBackground = level1OptimizationConfig.OptimizeBackground, OptimizeBorderRadius = level1OptimizationConfig.OptimizeBorderRadius, OptimizeFilter = level1OptimizationConfig.OptimizeFilter, OptimizeFont = level1OptimizationConfig.OptimizeFont, OptimizeFontWeight = level1OptimizationConfig.OptimizeFontWeight, OptimizeOutline = level1OptimizationConfig.OptimizeOutline, RemoveEmpty = level1OptimizationConfig.RemoveEmpty, RemoveNegativePaddings = level1OptimizationConfig.RemoveNegativePaddings, RemoveQuotes = level1OptimizationConfig.RemoveQuotes, RemoveWhitespace = level1OptimizationConfig.RemoveWhitespace, ReplaceMultipleZeros = level1OptimizationConfig.ReplaceMultipleZeros, ReplaceTimeUnits = level1OptimizationConfig.ReplaceTimeUnits, ReplaceZeroUnits = level1OptimizationConfig.ReplaceZeroUnits, RoundingPrecision = level1OptimizationConfig.RoundingPrecision, SelectorsSortingMethod = level1OptimizationConfig.SelectorsSortingMethod, SpecialComments = level1OptimizationConfig.SpecialComments, TidyAtRules = level1OptimizationConfig.TidyAtRules, TidyBlockScopes = level1OptimizationConfig.TidyBlockScopes, TidySelectors = level1OptimizationConfig.TidySelectors }; Level2OptimizationOptions = new Level2OptimizationOptions { MergeAdjacentRules = level2OptimizationConfig.MergeAdjacentRules, MergeIntoShorthands = level2OptimizationConfig.MergeIntoShorthands, MergeMedia = level2OptimizationConfig.MergeMedia, MergeNonAdjacentRules = level2OptimizationConfig.MergeNonAdjacentRules, MergeSemantically = level2OptimizationConfig.MergeSemantically, OverrideProperties = level2OptimizationConfig.OverrideProperties, RemoveEmpty = level2OptimizationConfig.RemoveEmpty, ReduceNonAdjacentRules = level2OptimizationConfig.ReduceNonAdjacentRules, RemoveDuplicateFontRules = level2OptimizationConfig.RemoveDuplicateFontRules, RemoveDuplicateMediaBlocks = level2OptimizationConfig.RemoveDuplicateMediaBlocks, RemoveDuplicateRules = level2OptimizationConfig.RemoveDuplicateRules, RemoveUnusedAtRules = level2OptimizationConfig.RemoveUnusedAtRules, RestructureRules = level2OptimizationConfig.RestructureRules, SkipProperties = level2OptimizationConfig.SkipProperties }; Severity = cssMinifierConfig.Severity; if (createJsEngineInstance == null) { string jsEngineName = cleanConfig.JsEngine.Name; if (string.IsNullOrWhiteSpace(jsEngineName)) { throw new ConfigurationErrorsException( string.Format(CoreStrings.Configuration_JsEngineNotSpecified, "clean", @" * JavaScriptEngineSwitcher.Msie * JavaScriptEngineSwitcher.V8 * JavaScriptEngineSwitcher.ChakraCore", "MsieJsEngine") ); } createJsEngineInstance = () => JsEngineSwitcher.Current.CreateEngine(jsEngineName); } _createJsEngineInstance = createJsEngineInstance; }