示例#1
0
        private void UpdateDeclarationCache(ParseItem item)
        {
            var visitor = new CssItemCollector <Declaration>(true);

            item.Accept(visitor);

            HashSet <RuleBlock> rules = new HashSet <RuleBlock>();

            foreach (Declaration dec in visitor.Items)
            {
                RuleBlock rule = dec.Parent as RuleBlock;

                if (rule == null || rules.Contains(rule))
                {
                    continue;
                }

                var images = rule.Declarations.Where(d => d.PropertyName != null && d.PropertyName.Text.Contains("background"));

                foreach (Declaration image in images)
                {
                    if (!Cache.Contains(image))
                    {
                        Cache.Add(image);
                    }
                }

                rules.Add(rule);
            }
        }
        private void UpdateCache(ParseItem item)
        {
            var visitor = new CssItemCollector<Declaration>(true);
            item.Accept(visitor);

            foreach (TokenItem token in visitor.Items.Where(d => d.Important != null).Select(d => d.Important))
            {
                if (!_cache.Contains(token))
                    _cache.Add(token);
            }
        }
示例#3
0
        private void UpdateCache(ParseItem item)
        {
            var visitor = new CssItemCollector <Declaration>(true);

            item.Accept(visitor);

            foreach (TokenItem token in visitor.Items.Where(d => d.Important != null).Select(d => d.Important))
            {
                if (!_cache.Contains(token))
                {
                    _cache.Add(token);
                }
            }
        }
示例#4
0
        private IEnumerable <ParseItem> GetColors(SnapshotSpan span)
        {
            List <ParseItem> items = new List <ParseItem>();

            // TODO: Refine this so it goes directly to the individual HexColorValue, FunctionColor and TokenItem
            ParseItem complexItem = _tree.StyleSheet.ItemFromRange(span.Start, span.Length);

            if (complexItem == null || (!(complexItem is AtDirective) && !(complexItem is RuleBlock) && !(complexItem is LessVariableDeclaration)))
            {
                return(items);
            }

            IEnumerable <ParseItem> declarations = new ParseItem[0];

            var lessVar = complexItem as LessVariableDeclaration;

            if (lessVar != null)
            {
                declarations = new List <ParseItem>()
                {
                    lessVar.Value
                };
            }
            else
            {
                var visitorRules = new CssItemCollector <Declaration>();
                complexItem.Accept(visitorRules);

                declarations = from d in visitorRules.Items
                               where d.Values.TextAfterEnd > span.Start && d.Values.TextStart < span.End && d.Length > 2
                               select d;
            }

            foreach (var declaration in declarations.Where(d => d != null))
            {
                var visitorHex = new CssItemCollector <HexColorValue>();
                declaration.Accept(visitorHex);
                items.AddRange(visitorHex.Items);

                var visitorFunc = new CssItemCollector <FunctionColor>();
                declaration.Accept(visitorFunc);
                items.AddRange(visitorFunc.Items);

                var visitorName = new CssItemCollector <TokenItem>();
                declaration.Accept(visitorName);
                items.AddRange(visitorName.Items.Where(i => (i.PreviousSibling == null || (i.PreviousSibling.Text != "@" && i.PreviousSibling.Text != "$")) && i.TokenType == CssTokenType.Identifier && Color.FromName(i.Text).IsNamedColor));
            }

            return(items);
        }
        private void UpdateCache(ParseItem item)
        {
            var visitor = new CssItemCollector<Declaration>(true);
            item.Accept(visitor);

            foreach (Declaration dec in visitor.Items)
            {
                string text = dec.Text;

                if (text.StartsWith("var-", StringComparison.Ordinal))
                {
                    if (!_cache.Contains(dec))
                        _cache.Add(dec);
                }
            }
        }
        private void UpdateCache(ParseItem item)
        {
            var visitor = new CssItemCollector<SimpleSelector>(true);
            item.Accept(visitor);

            foreach (SimpleSelector ss in visitor.Items)
            {
                string text = ss.Text;

                if (ModernizrProvider.IsModernizr(text))
                {
                    if (!_cache.Contains(ss))
                        _cache.Add(ss);
                }
            }
        }
示例#7
0
        private void UpdateCache(ParseItem item)
        {
            var visitor = new CssItemCollector <Declaration>(true);

            item.Accept(visitor);

            foreach (Declaration dec in visitor.Items)
            {
                string text = dec.Text;

                if (text.StartsWith("var-", StringComparison.Ordinal))
                {
                    if (!_cache.Contains(dec))
                    {
                        _cache.Add(dec);
                    }
                }
            }
        }
        private void UpdateCache(ParseItem item)
        {
            var visitor = new CssItemCollector <SimpleSelector>(true);

            item.Accept(visitor);

            foreach (SimpleSelector ss in visitor.Items)
            {
                string text = ss.Text;

                if (ModernizrProvider.IsModernizr(text))
                {
                    if (!_cache.Contains(ss))
                    {
                        _cache.Add(ss);
                    }
                }
            }
        }
        private void UpdateDeclarationCache(ParseItem item)
        {
            var visitor = new CssItemCollector <Declaration>(true);

            item.Accept(visitor);

            HashSet <RuleBlock> rules = new HashSet <RuleBlock>();

            foreach (Declaration dec in visitor.Items)
            {
                RuleBlock rule = dec.Parent as RuleBlock;
                if (rule == null || rules.Contains(rule))
                {
                    continue;
                }

                var vendors = rule.GetDeclarations().Where(d => d.IsValid && d.IsVendorSpecific());
                foreach (Declaration vendor in vendors)
                {
                    string      name     = GetStandardName(vendor);
                    Declaration standard = rule.GetDeclarations().FirstOrDefault(d => d.IsValid && d.PropertyName.Text == name);

                    if (standard != null)
                    {
                        if (!Cache.Contains(standard))
                        {
                            Cache.Add(standard);
                        }

                        if (GetValueText(standard) == GetValueText(vendor) && !Cache.Contains(vendor))
                        {
                            Cache.Add(vendor);
                        }
                    }
                }

                rules.Add(rule);
            }
        }
        private void UpdateDeclarationCache(ParseItem item)
        {
            var visitor = new CssItemCollector<Declaration>(true);
            item.Accept(visitor);

            HashSet<RuleBlock> rules = new HashSet<RuleBlock>();

            foreach (Declaration dec in visitor.Items)
            {
                RuleBlock rule = dec.Parent as RuleBlock;
                if (rule == null || rules.Contains(rule))
                    continue;

                var vendors = rule.Declarations.Where(d => d.IsValid && d.IsVendorSpecific());
                foreach (Declaration vendor in vendors)
                {
                    string name = GetStandardName(vendor);
                    Declaration standard = rule.Declarations.FirstOrDefault(d => d.IsValid && d.PropertyName.Text == name);

                    if (standard != null)
                    {
                        if (!Cache.Contains(standard))
                            Cache.Add(standard);

                        if (GetValueText(standard) == GetValueText(vendor) && !Cache.Contains(vendor))
                            Cache.Add(vendor);
                    }
                }

                rules.Add(rule);
            }
        }
        private void UpdateDeclarationCache(ParseItem item)
        {
            var visitor = new CssItemCollector<Declaration>(true);
            item.Accept(visitor);

            HashSet<RuleBlock> rules = new HashSet<RuleBlock>();

            foreach (Declaration dec in visitor.Items)
            {
                RuleBlock rule = dec.Parent as RuleBlock;

                if (rule == null || rules.Contains(rule))
                    continue;

                var images = rule.Declarations.Where(d => d.PropertyName.Text.Contains("background"));

                foreach (Declaration image in images)
                {
                    if (!Cache.Contains(image))
                        Cache.Add(image);
                }

                rules.Add(rule);
            }
        }
示例#12
0
 public ReadOnlyCollection <TResult> Crawl(ParseItem root)
 {
     root.Accept(this);
     return(Items);
 }