Esempio n. 1
0
        /// <summary>
        /// Cleans/compresses several aspects of CSS code.
        /// </summary>
        /// <remarks>
        /// This should be everything...
        /// </remarks>
        /// <param name="css">The string value of the file(s).</param>
        /// <returns>A minified version of the supplied CSS string.</returns>
        public static string MakeItUgly( string css )
        {
            var colors = new ColorConversions();

            // Clear the lists
            _urls.Clear();
            _data.Clear();
            _contents.Clear();

            // Insert placeholders
            SwapForPlaceholders( ref css );

            // Run through the rest of the minify methods
            InitialCleaning( ref css );
            CleanSelectors( ref css );
            CleanBraces( ref css );
            CleanUnnecessary( ref css );
            ConvertColors( ref css );
            CompressHexValues( ref css );
            css = colors.SwapOutNames( css );
            FixIllFormedHsl( ref css );

            // 'transparent' == rgba(0,0,0,0) == hsla(0,0%,0%,0)
            // Should be fine, if it supports Alpha should support the 'transparent' color literal
            // ...right?
            css = css.Replace( "rgba(0,0,0,0)", "transparent" )
                     .Replace( "hsla(0,0%,0%,0)", "transparent" );

            // Replace placeholders
            ReplacePlaceholders( ref css );

            // Return the string after trimming any leading or trailing spaces
            return css.Trim();
        }