Ejemplo n.º 1
0
        private PredefinedRuleSet ParsePredefinedRuleSet(string className, string css)
        {
            var predefinedRuleSet = new PredefinedRuleSet {
                Selector = className.Trim()
            };

            predefinedRuleSet.Declarations = ParseDeclarations(css);
            return(predefinedRuleSet);
        }
Ejemplo n.º 2
0
        private Keyframe ParseKeyframe(string css)
        {
            Keyframe keyframe          = new Keyframe();
            IRule    current           = keyframe;
            string   buffer            = string.Empty;
            bool     nestedClassClosed = true;

            foreach (char ch in css)
            {
                switch (ch)
                {
                case ';':
                    Declaration declaration = ParseDeclaration(buffer.Trim());
                    if (declaration != null)
                    {
                        current.Declarations.Add(declaration);
                    }
                    buffer = string.Empty;
                    break;

                case '{':
                    IRule nestedClass;
                    nestedClass = new PredefinedRuleSet
                    {
                        Selector = buffer.Trim()
                    };
                    keyframe.NestedRules.Add(nestedClass);
                    buffer            = string.Empty;
                    current           = nestedClass;
                    nestedClassClosed = false;
                    break;

                case '}':
                    nestedClassClosed = true;
                    break;

                default:
                    buffer += ch;
                    break;
                }
            }
            if (!nestedClassClosed)
            {
                throw StyledException.GetException(css, "A nested class is missing a '}' character", null);
            }
            if (buffer.Trim() != string.Empty)
            {
                throw StyledException.GetException(buffer, "This is usually caused by a missing ';' character at the end of a declaration", null);
            }
            keyframe.SetClassName();
            return(keyframe);
        }
Ejemplo n.º 3
0
        private RuleSet ParseRuleSet(string css)
        {
            RuleSet ruleSet = new RuleSet();
            IRule   current = ruleSet;
            string  buffer  = string.Empty;

            foreach (char ch in css)
            {
                switch (ch)
                {
                case ';':
                    var declaration = ParseDeclaration(buffer.Trim());
                    if (declaration != null)
                    {
                        current.Declarations.Add(declaration);
                    }
                    buffer = string.Empty;
                    break;

                case '{':
                    IRule nestedClass;
                    if (buffer.IndexOf("@media") == -1)
                    {
                        nestedClass          = new PredefinedRuleSet();
                        nestedClass.Selector = buffer.Trim();
                    }
                    else
                    {
                        nestedClass          = new MediaQuery();
                        nestedClass.Selector = buffer.Trim() + "{&";
                    }
                    ruleSet.NestedRules.Add(nestedClass);
                    buffer  = string.Empty;
                    current = nestedClass;
                    break;

                case '}':
                    break;

                default:
                    buffer += ch;
                    break;
                }
            }
            ruleSet.SetClassName();
            return(ruleSet);
        }
Ejemplo n.º 4
0
        private Keyframe ParseKeyframe(string css)
        {
            var    keyframe = new Keyframe();
            IRule  current  = keyframe;
            string buffer   = string.Empty;

            foreach (char ch in css)
            {
                switch (ch)
                {
                case ';':
                    var declaration = ParseDeclaration(buffer.Trim());
                    if (declaration != null)
                    {
                        current.Declarations.Add(declaration);
                    }
                    buffer = string.Empty;
                    break;

                case '{':
                    IRule nestedClass;
                    nestedClass = new PredefinedRuleSet
                    {
                        Selector = buffer.Trim()
                    };
                    keyframe.NestedRules.Add(nestedClass);
                    buffer  = string.Empty;
                    current = nestedClass;
                    break;

                case '}':
                    break;

                default:
                    buffer += ch;
                    break;
                }
            }
            keyframe.SetClassName();
            return(keyframe);
        }
Ejemplo n.º 5
0
        private RuleSet ParseRuleSet(string css)
        {
            RuleSet ruleSet = new RuleSet
            {
                Label = _id != DEFAULT ? _id : null
            };
            IRule  current           = ruleSet;
            string buffer            = string.Empty;
            bool   nestedClassClosed = true; //Start from true becuase the parent doesnt need to be closed

            foreach (char ch in css)
            {
                switch (ch)
                {
                case ';':
                    Declaration declaration = ParseDeclaration(buffer.Trim());
                    if (declaration != null)
                    {
                        if (declaration.Property == "label")
                        {
                            current.Label = current.Label == null?declaration.Value.Trim() : $"{current.Label}-{declaration.Value.Trim()}";
                        }
                        else
                        {
                            current.Declarations.Add(declaration);
                        }
                    }
                    buffer = string.Empty;
                    break;

                case '{':
                    IRule nestedClass;
                    if (buffer.IndexOf("@media") == -1)
                    {
                        nestedClass = new PredefinedRuleSet
                        {
                            Selector = buffer.Trim()
                        };
                    }
                    else
                    {
                        nestedClass = new MediaQuery
                        {
                            Selector = buffer.Trim() + "{&"
                        };
                    }
                    ruleSet.NestedRules.Add(nestedClass);
                    buffer            = string.Empty;
                    current           = nestedClass;
                    nestedClassClosed = false;
                    break;

                case '}':
                    nestedClassClosed = true;
                    break;

                default:
                    buffer += ch;
                    break;
                }
            }
            if (!nestedClassClosed)
            {
                throw StyledException.GetException(css, "A nested class is missing a '}' character", null);
            }
            if (buffer.Trim() != string.Empty)
            {
                throw StyledException.GetException(buffer, "This is usually caused by a missing ';' character at the end of a declaration", null);
            }
            ruleSet.SetClassName();
            return(ruleSet);
        }