예제 #1
0
        private static MinificationResult MinifyCss(Config config, string file)
        {
            string content  = File.ReadAllText(file);
            var    settings = CssOptions.GetSettings(config);

            if (config.Minify.ContainsKey("enabled") && config.Minify["enabled"].ToString().Equals("false", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var minifier = new Minifier();

            // Remove control characters which AjaxMin can't handle
            content = Regex.Replace(content, @"[\u0000-\u0009\u000B-\u000C\u000E-\u001F]", string.Empty);

            string result          = minifier.MinifyStyleSheet(content, settings);
            string minFile         = GetMinFileName(file);
            bool   containsChanges = FileHelpers.HasFileContentChanged(minFile, result);

            OnBeforeWritingMinFile(file, minFile, containsChanges);

            if (containsChanges)
            {
                File.WriteAllText(minFile, result, new UTF8Encoding(true));
            }

            OnAfterWritingMinFile(file, minFile, containsChanges);

            GzipFile(config, minFile, containsChanges);

            return(new MinificationResult(result, null));
        }
예제 #2
0
        private static MinificationResult MinifyCss(Config config, string file)
        {
            string content  = File.ReadAllText(file);
            var    settings = CssOptions.GetSettings(config);

            if (config.Minify.ContainsKey("enabled") && config.Minify["enabled"].ToString().Equals("false", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var minifier = new Minifier();

            string result = minifier.MinifyStyleSheet(content, settings);

            if (!string.IsNullOrEmpty(result))
            {
                string minFile         = GetMinFileName(file);
                bool   containsChanges = FileHelpers.HasFileContentChanged(minFile, result);

                OnBeforeWritingMinFile(file, minFile, containsChanges);

                if (containsChanges)
                {
                    File.WriteAllText(minFile, result, new UTF8Encoding(true));
                }

                OnAfterWritingMinFile(file, minFile, containsChanges);

                GzipFile(config, minFile, containsChanges);
            }

            return(new MinificationResult(result, null));
        }
예제 #3
0
        private static MinificationResult MinifyCss(Config config, string file)
        {
            string content  = File.ReadAllText(file);
            var    settings = CssOptions.GetSettings(config);
            var    minifier = new Minifier();

            string result = minifier.MinifyStyleSheet(content, settings);

            if (!string.IsNullOrEmpty(result))
            {
                string minFile = GetMinFileName(file);

                OnBeforeWritingMinFile(file, minFile);
                File.WriteAllText(minFile, result, new UTF8Encoding(true));
                OnAfterWritingMinFile(file, minFile);

                GzipFile(config, minFile);
            }

            return(new MinificationResult(result, null));
        }