Ejemplo n.º 1
0
        public IEnumerable <SnippetGeneratorResult> GenerateSnippets(SnippetDirectory directory)
        {
            if (!ShouldGenerateSnippets(directory))
            {
                yield break;
            }

            yield return(new SnippetGeneratorResult(
                             GenerateSnippetsCore(directory),
                             directory.Name,
                             directory.Language,
                             isDevelopment: false,
                             tags: directory.Tags.ToArray()));

            string devPath = Path.Combine(directory.Path, KnownNames.Dev);

            if (!Directory.Exists(devPath))
            {
                yield break;
            }

            SnippetDirectory devDirectory = directory.WithPath(devPath);

            yield return(new SnippetGeneratorResult(
                             GenerateSnippetsCore(devDirectory, isDevelopment: true),
                             name: directory.Path + KnownNames.DevSuffix,
                             language: directory.Language,
                             isDevelopment: true,
                             tags: directory.Tags.ToArray()));
        }
Ejemplo n.º 2
0
        private List <Snippet> GenerateSnippetsCore(SnippetDirectory directory, bool isDevelopment = false)
        {
            var snippets = new List <Snippet>();

            snippets.AddRange(EnumerateSnippets(directory.Path));

#if DEBUG
            foreach (Snippet snippet in snippets)
            {
                foreach (string keyword in snippet.Keywords)
                {
                    if (keyword.StartsWith(KnownTags.MetaPrefix + KnownTags.GeneratePrefix, StringComparison.OrdinalIgnoreCase))
                    {
                        Debug.Fail(keyword + "\r\n" + snippet.FilePath);
                        break;
                    }
                }
            }
#endif

            snippets.AddRange(SnippetGenerator.GenerateAlternativeShortcuts(snippets));

            if (!isDevelopment &&
                directory.HasTag(KnownTags.GenerateXmlSnippets))
            {
                switch (directory.Language)
                {
                case Language.Xml:
                case Language.Xaml:
                case Language.Html:
                case Language.Markdown:
                {
                    snippets.AddRange(XmlSnippetGenerator.GenerateSnippets(directory.Language));
                    break;
                }
                }
            }

            KeywordDefinitionCollection keywords = LanguageDefinition.GetKeywords(directory.Language);

            if (keywords != null)
            {
                foreach (KeywordDefinition keyword in keywords)
                {
                    if (keyword.IsDevelopment == isDevelopment)
                    {
                        Snippet snippet = keyword.ToSnippet();
                        snippet.Language = directory.Language;
                        snippets.Add(snippet);
                    }
                }
            }

            string autoGenerationPath = Path.Combine(directory.Path, KnownNames.AutoGeneration);

            if (Directory.Exists(autoGenerationPath))
            {
                SnippetDirectory autoGenerationDirectory = directory.WithPath(autoGenerationPath);

                SnippetGenerator generator = CreateSnippetGenerator(autoGenerationDirectory);

                snippets.AddRange(generator.GenerateSnippets(autoGenerationDirectory.Path));
            }

            return(snippets);
        }