当前位置: 首页>>代码示例>>C#>>正文


C# CssItemCollector类代码示例

本文整理汇总了C#中CssItemCollector的典型用法代码示例。如果您正苦于以下问题:C# CssItemCollector类的具体用法?C# CssItemCollector怎么用?C# CssItemCollector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CssItemCollector类属于命名空间,在下文中一共展示了CssItemCollector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddMissingStandardDeclaration

        private string AddMissingStandardDeclaration(StringBuilder sb, CssEditorDocument doc, ICssSchemaInstance rootSchema)
        {
            var visitor = new CssItemCollector<RuleBlock>(true);
            doc.Tree.StyleSheet.Accept(visitor);

            //var items = visitor.Items.Where(d => d.IsValid && d.IsVendorSpecific());
            foreach (RuleBlock rule in visitor.Items.Reverse())
            {
                HashSet<string> list = new HashSet<string>();
                foreach (Declaration dec in rule.Declarations.Where(d => d.IsValid && d.IsVendorSpecific()).Reverse())
                {
                    ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, dec);
                    ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(dec, schema);

                    if (entry != null && !list.Contains(entry.DisplayText) && !rule.Declarations.Any(d => d.PropertyName != null && d.PropertyName.Text == entry.DisplayText))
                    {
                        int index = dec.Text.IndexOf(":", StringComparison.Ordinal);
                        string standard = entry.DisplayText + dec.Text.Substring(index);

                        sb.Insert(dec.AfterEnd, standard);
                        list.Add(entry.DisplayText);
                    }
                }
            }

            return sb.ToString();
        }
开发者ID:jonantoine,项目名称:WebEssentials2012,代码行数:27,代码来源:CssAddMissingStandardCommandTarget.cs

示例2: GetListEntries

        public IEnumerable<ICssCompletionListEntry> GetListEntries(CssCompletionContext context)
        {
            if (!IsFontFamilyContext(context))
                yield break;

            StyleSheet stylesheet = context.ContextItem.StyleSheet;
            var visitorRules = new CssItemCollector<FontFaceDirective>();
            stylesheet.Accept(visitorRules);

            foreach (FontFaceDirective item in visitorRules.Items)
            {
                var visitorDec = new CssItemCollector<Declaration>();
                item.Block.Accept(visitorDec);

                Declaration family = visitorDec.Items.FirstOrDefault(i => i.PropertyName.Text == "font-family");

                if (family != null)
                {
                    string value = string.Join(string.Empty, family.Values.Select(v => v.Text));
                    yield return new FontFamilyCompletionListEntry(value.Trim('\'', '"'));
                }
            }

            yield return new FontFamilyCompletionListEntry("Pick from file...");
        }
开发者ID:NickCraver,项目名称:WebEssentials2013,代码行数:25,代码来源:FontCompletionProvider.cs

示例3: ParseDocument

        private async static Task ParseDocument()
        {
            string fileName = GetSolutionFilePath();

            if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName))
            {
                CssParser parser = new CssParser();
                StyleSheet stylesheet = parser.Parse(await FileHelpers.ReadAllTextRetry(fileName), false);

                if (stylesheet.IsValid)
                {
                    var visitor = new CssItemCollector<AtDirective>();
                    stylesheet.Accept(visitor);

                    AtDirective at = visitor.Items.SingleOrDefault(a => a.Keyword.Text == _rootDirective);
                    if (at != null)
                    {
                        var visitorPalette = new CssItemCollector<AtDirective>(true);
                        at.Accept(visitorPalette);
                        _directives = visitorPalette.Items.Where(a => a.Keyword.Text != at.Keyword.Text).ToList();
                    }
                }

                InitializeWatcher(fileName);
            }
            else
            {
                _hasFile = false;
            }
        }
开发者ID:EdsonF,项目名称:WebEssentials2013,代码行数:30,代码来源:XmlColorPaletteProvider.cs

示例4: CheckItem

        public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context)
        {
            if (!WESettings.Instance.Css.ValidateVendorSpecifics)
                return ItemCheckResult.Continue;

            AtDirective directive = (AtDirective)item;

            if (context == null || !directive.IsValid || !directive.IsVendorSpecific())
                return ItemCheckResult.Continue;

            ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(directive, context);

            if (entry != null)
            {
                var visitor = new CssItemCollector<AtDirective>();
                directive.Parent.Accept(visitor);

                if (!visitor.Items.Any(a => a != null && a.Keyword != null && "@" + a.Keyword.Text == entry.DisplayText))
                {
                    string message = string.Format(CultureInfo.InvariantCulture, Resources.BestPracticeAddMissingStandardDirective, entry.DisplayText);
                    context.AddError(new SimpleErrorTag(directive.Keyword, message));
                    return ItemCheckResult.CancelCurrentItem;
                }
            }

            return ItemCheckResult.Continue;
        }
开发者ID:venux,项目名称:WebEssentials2015,代码行数:27,代码来源:MissingStandardDirectiveErrorTagProvider.cs

示例5: AddMissingVendorDeclarations

        private static string AddMissingVendorDeclarations(StringBuilder sb, CssEditorDocument doc, ICssSchemaInstance rootSchema, out int count)
        {
            var visitor = new CssItemCollector<Declaration>(true);
            doc.Tree.StyleSheet.Accept(visitor);
            count = 0;

            var items = visitor.Items.Where(d => d.IsValid && !d.IsVendorSpecific() && d.PropertyName.Text != "filter");

            foreach (Declaration dec in items.Reverse())
            {
                ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, dec);
                var missingEntries = dec.GetMissingVendorSpecifics(schema);

                if (missingEntries.Any())
                {
                    var missingPrefixes = missingEntries.Select(e => e.Substring(0, e.IndexOf('-', 1) + 1));
                    string vendors = GetVendorDeclarations(missingPrefixes, dec);

                    sb.Insert(dec.Start, vendors);
                    count++;
                }
            }

            return sb.ToString();
        }
开发者ID:vikramgoudr,项目名称:WebEssentials2013,代码行数:25,代码来源:CssAddVendorStandardCommandTarget.cs

示例6: FindRuleSetInFile

        private string FindRuleSetInFile(IEnumerable<string> extensions, string className, out RuleSet rule)
        {
            string root = ProjectHelpers.GetProjectFolder(peekableItem._textbuffer.GetFileName());
            string result = null;
            bool isLow = false, isMedium = false;
            rule = null;

            foreach (string ext in extensions)
            {
                ICssParser parser = CssParserLocator.FindComponent(Mef.GetContentType(ext.Trim('.'))).CreateParser();

                foreach (string file in Directory.EnumerateFiles(root, "*" + ext, SearchOption.AllDirectories))
                {
                    if (file.EndsWith(".min" + ext, StringComparison.OrdinalIgnoreCase) ||
                        file.Contains("node_modules") ||
                        file.Contains("bower_components"))
                        continue;

                    string text = FileHelpers.ReadAllTextRetry(file).ConfigureAwait(false).GetAwaiter().GetResult();
                    int index = text.IndexOf("." + className, StringComparison.Ordinal);

                    if (index == -1)
                        continue;

                    var css = parser.Parse(text, true);
                    var visitor = new CssItemCollector<ClassSelector>(false);
                    css.Accept(visitor);

                    var selectors = visitor.Items.Where(c => c.ClassName.Text == className);
                    var high = selectors.FirstOrDefault(c => c.FindType<AtDirective>() == null && (c.Parent.NextSibling == null || c.Parent.NextSibling.Text == ","));

                    if (high != null)
                    {
                        rule = high.FindType<RuleSet>();
                        return file;
                    }

                    var medium = selectors.FirstOrDefault(c => c.Parent.NextSibling == null || c.Parent.NextSibling.Text == ",");

                    if (medium != null && !isMedium)
                    {
                        rule = medium.FindType<RuleSet>();
                        result = file;
                        isMedium = true;
                        continue;
                    }

                    var low = selectors.FirstOrDefault();

                    if (low != null && !isLow && !isMedium)
                    {
                        rule = low.FindType<RuleSet>();
                        result = file;
                        isLow = true;
                    }
                }
            }

            return result;
        }
开发者ID:venux,项目名称:WebEssentials2015,代码行数:60,代码来源:ClassPeekResultSource.cs

示例7: Calculate

        private void Calculate()
        {
            // IDs
            var visitorIDs = new CssItemCollector<IdSelector>();
            _selector.Accept(visitorIDs);

            if (visitorIDs.Items.Count > 0)
                IDs = visitorIDs.Items.Count;// *100;

            // Classes
            var visitorClasses = new CssItemCollector<ClassSelector>();
            _selector.Accept(visitorClasses);

            if (visitorClasses.Items.Count > 0)
                Classes = visitorClasses.Items.Count;// *10;

            // Attributes
            var visitorAttribute = new CssItemCollector<AttributeSelector>();
            _selector.Accept(visitorAttribute);

            if (visitorAttribute.Items.Count > 0)
                Attributes = visitorAttribute.Items.Count;// *10;

            // Elements
            var visitorElements = new CssItemCollector<ItemName>();
            _selector.Accept(visitorElements);
            Elements = visitorElements.Items.Where(i => i.Text != "*" && i.FindType<AttributeSelector>() == null).Count();

            // Pseudo Elements
            var visitorPseudoElementSelector = new CssItemCollector<PseudoElementSelector>();
            _selector.Accept(visitorPseudoElementSelector);

            var visitorPseudoElementFunctionSelector = new CssItemCollector<PseudoElementFunctionSelector>();
            _selector.Accept(visitorPseudoElementFunctionSelector);

            PseudoElements = visitorPseudoElementSelector.Items.Count + visitorPseudoElementFunctionSelector.Items.Count;

            // Pseudo Classes
            var visitorPseudoClassSelector = new CssItemCollector<PseudoClassSelector>();
            _selector.Accept(visitorPseudoClassSelector);

            var visitorPseudoClassFunctionSelector = new CssItemCollector<PseudoClassFunctionSelector>(true);
            _selector.Accept(visitorPseudoClassFunctionSelector);

            int pseudoClases = visitorPseudoClassSelector.Items.Count(p => !p.IsPseudoElement());
            pseudoClases += visitorPseudoClassFunctionSelector.Items.Where(p => !p.Text.StartsWith(":not(") && !p.Text.StartsWith(":matches(")).Count();
            Elements += visitorPseudoClassSelector.Items.Count(p => p.IsPseudoElement());

            if (pseudoClases > 0)
                PseudoClasses = pseudoClases;// *10;

            // Total
            //Total = IDs + Classes + Attributes + Elements + PseudoElements + PseudoClasses;
        }
开发者ID:joeriks,项目名称:WebEssentials2013,代码行数:54,代码来源:SelectorSpecificity.cs

示例8: GetListEntries

        public IEnumerable<ICssCompletionListEntry> GetListEntries(CssCompletionContext context)
        {
            var visitor = new CssItemCollector<Declaration>();
            context.ContextItem.StyleSheet.Accept(visitor);

            foreach (Declaration dec in visitor.Items)
            {
                if (dec.IsValid && dec.PropertyName.Text.StartsWith("var-"))
                    yield return new CompletionListEntry(dec.PropertyName.Text.Substring(4));
            }
        }
开发者ID:GProulx,项目名称:WebEssentials2013,代码行数:11,代码来源:VariableNameCompletionProvider.cs

示例9: GetListEntries

        public IEnumerable<ICssCompletionListEntry> GetListEntries(CssCompletionContext context)
        {
            StyleSheet stylesheet = context.ContextItem.StyleSheet;
            var visitorRules = new CssItemCollector<ClassSelector>();
            stylesheet.Accept(visitorRules);

            foreach (string item in visitorRules.Items.Where(s => s != context.ContextItem).Select(s => s.Text).Distinct())
            {
                yield return new CompletionListEntry(item);
            }
        }
开发者ID:kodybrown,项目名称:WebEssentials2013,代码行数:11,代码来源:ClassCompletionProvider.cs

示例10: UpdateCache

        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);
            }
        }
开发者ID:GProulx,项目名称:WebEssentials2013,代码行数:11,代码来源:ImportantClassifier.cs

示例11: GetMissingVendorSpecifics

        public static IEnumerable<string> GetMissingVendorSpecifics(this AtDirective directive, ICssSchemaInstance schema)
        {
            IEnumerable<string> possible = GetPossibleVendorSpecifics(directive, schema);

            var visitorRules = new CssItemCollector<AtDirective>();
            directive.Parent.Accept(visitorRules);

            foreach (string item in possible)
            {
                if (!visitorRules.Items.Any(d => d.Keyword != null && "@" + d.Keyword.Text == item))
                    yield return item;
            }
        }
开发者ID:alexdresko,项目名称:WebEssentials2013,代码行数:13,代码来源:AtDirectiveExtensions.cs

示例12: InitializeCache

        private void InitializeCache(StyleSheet stylesheet)
        {
            _cache.Clear();

            var visitor = new CssItemCollector<Declaration>(true);
            stylesheet.Accept(visitor);

            foreach (Declaration dec in visitor.Items.Where(d => d.PropertyName != null))
            {
                if (dec.PropertyName.Text == "display" && dec.Values.Any(v => v.Text == "inline"))
                    _cache.Add(dec);
            }
        }
开发者ID:LogoPhonix,项目名称:WebEssentials2012,代码行数:13,代码来源:DisplayInlineErrorTagProvider.cs

示例13: BuildCache

        private List<RuleResult> BuildCache(RuleSet rule)
        {
            var visitor = new CssItemCollector<RuleSet>();
            rule.Parent.Accept(visitor);
            List<RuleResult> list = new List<RuleResult>();

            foreach (RuleSet rs in visitor.Items)
            {
                RuleResult result = new RuleResult(rs, rs.Start, GetSelectorText(rs));
                list.Add(result);
            }

            return list;
        }
开发者ID:LogoPhonix,项目名称:WebEssentials2012,代码行数:14,代码来源:DuplicateSelectorErrorTagProvider.cs

示例14: UpdateCache

        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);
                }
            }
        }
开发者ID:venux,项目名称:WebEssentials2015,代码行数:16,代码来源:VariableClassifier.cs

示例15: UpdateCache

        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);
                }
            }
        }
开发者ID:NickCraver,项目名称:WebEssentials2013,代码行数:16,代码来源:ModernizrClassifier.cs


注:本文中的CssItemCollector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。