Пример #1
0
        /// <summary>
        /// Clones the Css settings object by copying all the properties.
        /// </summary>
        /// <returns>The copy of the current object.</returns>
        public CssSettings Clone()
        {
            // create the new settings object and copy all the properties from
            // the current settings
            var newSettings = new CssSettings()
            {
                AllowEmbeddedAspNetBlocks = this.AllowEmbeddedAspNetBlocks,
                ColorNames             = this.ColorNames,
                CommentMode            = this.CommentMode,
                IgnoreAllErrors        = this.IgnoreAllErrors,
                IgnoreErrorList        = this.IgnoreErrorList,
                IndentSize             = this.IndentSize,
                KillSwitch             = this.KillSwitch,
                LineBreakThreshold     = this.LineBreakThreshold,
                MinifyExpressions      = this.MinifyExpressions,
                OutputMode             = this.OutputMode,
                PreprocessorDefineList = this.PreprocessorDefineList,
                TermSemicolons         = this.TermSemicolons,
                CssType = this.CssType,
                BlocksStartOnSameLine = this.BlocksStartOnSameLine,
            };

            // add the resource strings (if any)
            newSettings.AddResourceStrings(this.ResourceStrings);

            return(newSettings);
        }
        public MinifierParser()
        {
            // initialize with default values
            JSSettings = new JsSettings();
            CssSettings = new CssSettings();

            // see if this is running under the Mono runtime (on UNIX)
            m_isMono = Type.GetType("Mono.Runtime") != null;
        }
Пример #3
0
        /// <summary>
        /// Minifies the CSS stylesheet passes to it using the given settings, returning the minified results
        /// The ErrorList property will be set with any errors found during the minification process.
        /// </summary>
        /// <param name="source">CSS Source</param>
        /// <param name="settings">CSS minification settings</param>
        /// <param name="scriptSettings">JS minification settings to use for expression-minification</param>
        /// <returns>Minified StyleSheet</returns>
        public string MinifyStyleSheet(string source, CssSettings settings, JsSettings scriptSettings)
        {
            // initialize some values, including the error list (which shoudl start off empty)
            string minifiedResults = string.Empty;

            m_errorList = new List <MinifierError>();

            // create the parser object and if we specified some settings,
            // use it to set the Parser's settings object
            CssParser parser = new CssParser();

            parser.FileContext = FileName;

            if (settings != null)
            {
                parser.Settings = settings;
            }

            if (scriptSettings != null)
            {
                parser.JSSettings = scriptSettings;
            }

            // hook the error handler
            parser.CssError += new EventHandler <CssErrorEventArgs>(OnCssError);

            // try parsing the source and return the results
            try
            {
                minifiedResults = parser.Parse(source);
            }
            catch (Exception e)
            {
                m_errorList.Add(new MinifierError(
                                    true,
                                    0,
                                    null,
                                    null,
                                    null,
                                    this.FileName,
                                    0,
                                    0,
                                    0,
                                    0,
                                    e.Message));
                throw;
            }
            return(minifiedResults);
        }
Пример #4
0
        /// <summary>
        /// Minifies the CSS stylesheet passes to it using the given settings, returning the minified results
        /// The ErrorList property will be set with any errors found during the minification process.
        /// </summary>
        /// <param name="source">CSS Source</param>
        /// <param name="settings">CSS minification settings</param>
        /// <param name="scriptSettings">JS minification settings to use for expression-minification</param>
        /// <returns>Minified StyleSheet</returns>
        public string MinifyStyleSheet(string source, CssSettings settings, JsSettings scriptSettings)
        {
            // initialize some values, including the error list (which shoudl start off empty)
            string minifiedResults = string.Empty;
            m_errorList = new List<MinifierError>();

            // create the parser object and if we specified some settings,
            // use it to set the Parser's settings object
            CssParser parser = new CssParser();
            parser.FileContext = FileName;

            if (settings != null)
            {
                parser.Settings = settings;
            }

            if (scriptSettings != null)
            {
                parser.JSSettings = scriptSettings;
            }

            // hook the error handler
            parser.CssError += new EventHandler<CssErrorEventArgs>(OnCssError);

            // try parsing the source and return the results
            try
            {
                minifiedResults = parser.Parse(source);
            }
            catch (Exception e)
            {
                m_errorList.Add(new MinifierError(
                    true,
                    0,
                    null,
                    null,
                    null,
                    this.FileName,
                    0,
                    0,
                    0,
                    0,
                    e.Message));
                throw;
            }
            return minifiedResults;
        }
Пример #5
0
 /// <summary>
 /// Minifies the CSS stylesheet passes to it using the given settings, returning the minified results
 /// The ErrorList property will be set with any errors found during the minification process.
 /// </summary>
 /// <param name="source">CSS Source</param>
 /// <param name="settings">CSS minification settings</param>
 /// <returns>Minified StyleSheet</returns>
 public string MinifyStyleSheet(string source, CssSettings settings)
 {
     // just pass in default settings
     return MinifyStyleSheet(source, settings, new JsSettings());
 }
Пример #6
0
        /// <summary>
        /// Clones the Css settings object by copying all the properties.
        /// </summary>
        /// <returns>The copy of the current object.</returns>
        public CssSettings Clone()
        {
            // create the new settings object and copy all the properties from
            // the current settings
            var newSettings = new CssSettings()
            {
                AllowEmbeddedAspNetBlocks = this.AllowEmbeddedAspNetBlocks,
                ColorNames = this.ColorNames,
                CommentMode = this.CommentMode,
                IgnoreAllErrors = this.IgnoreAllErrors,
                IgnoreErrorList = this.IgnoreErrorList,
                IndentSize = this.IndentSize,
                KillSwitch = this.KillSwitch,
                LineBreakThreshold = this.LineBreakThreshold,
                MinifyExpressions = this.MinifyExpressions,
                OutputMode = this.OutputMode,
                PreprocessorDefineList = this.PreprocessorDefineList,
                TermSemicolons = this.TermSemicolons,
                CssType = this.CssType,
                BlocksStartOnSameLine = this.BlocksStartOnSameLine,
            };

            // add the resource strings (if any)
            newSettings.AddResourceStrings(this.ResourceStrings);

            return newSettings;
        }
Пример #7
0
        private string m_valueReplacement; // = null;

        #endregion Fields

        #region Constructors

        public CssParser()
        {
            // default settings
            Settings = new CssSettings();

            // create the default settings we'll use for JS expression minification
            // use the defaults, other than to set the kill switch so that it leaves
            // string literals alone (so we don't inadvertently change any delimiter chars)
            JSSettings = null;

            // create a list of strings that represent the namespaces declared
            // in a @namespace statement. We will clear this every time we parse a new source string.
            m_namespaces = new HashSet<string>();
        }
 public MinifierParser(JsSettings scriptSettings, CssSettings cssSettings)
 {
     // apply the switches to these two settings objects
     JSSettings = scriptSettings ?? new JsSettings();
     CssSettings = cssSettings ?? new CssSettings();
 }
Пример #9
0
 /// <summary>
 /// Minifies the CSS stylesheet passes to it using the given settings, returning the minified results
 /// The ErrorList property will be set with any errors found during the minification process.
 /// </summary>
 /// <param name="source">CSS Source</param>
 /// <param name="settings">CSS minification settings</param>
 /// <returns>Minified StyleSheet</returns>
 public string MinifyStyleSheet(string source, CssSettings settings)
 {
     // just pass in default settings
     return(MinifyStyleSheet(source, settings, new JsSettings()));
 }