Example #1
0
        private static string GenerateDirectoryReadme(SnippetDirectory snippetDirectory, CharacterSequence[] characterSequences, GeneralSettings settings)
        {
            using (var sw = new StringWriter())
            {
                string directoryName = snippetDirectory.DirectoryName;

                sw.WriteLine($"## {directoryName}");
                sw.WriteLine();

                characterSequences = characterSequences?
                                     .Where(f => f.Languages.Select(language => settings.DirectoryNamePrefix + language.ToString())
                                            .Contains(snippetDirectory.DirectoryName)).ToArray();

                if (characterSequences?.Length > 0)
                {
                    sw.WriteLine("### Quick Reference");
                    sw.WriteLine();

                    string filePath = $@"..\..\..\..\..\text\{directoryName}.md";

                    if (File.Exists(filePath))
                    {
                        sw.WriteLine(File.ReadAllText(filePath, Encoding.UTF8));
                        sw.WriteLine();
                    }

                    using (CharacterSequenceTableWriter tableWriter = CharacterSequenceTableWriter.Create())
                    {
                        tableWriter.WriteTable(characterSequences);
                        sw.Write(tableWriter.ToString());
                    }

                    sw.WriteLine();
                }

                if (!snippetDirectory.HasTag(KnownTags.Dev))
                {
                    sw.WriteLine($"* [full list of snippets](http://pihrt.net/Snippetica/Snippets?Language={snippetDirectory.Language})");
                    sw.WriteLine();
                }

                sw.WriteLine("### List of Selected Snippets");
                sw.WriteLine();

                using (SnippetTableWriter tableWriter = SnippetTableWriter.CreateTitleWithLinkThenShortcut(snippetDirectory.Path))
                {
                    IEnumerable <Snippet> snippets = snippetDirectory
                                                     .EnumerateSnippets()
                                                     .Where(f => !f.HasTag(KnownTags.ExcludeFromReadme));

                    tableWriter.WriteTable(snippets);
                    sw.Write(tableWriter.ToString());
                }

                return(sw.ToString());
            }
        }
Example #2
0
        private static string GenerateDirectoryReadme(IEnumerable <Snippet> snippets, string directoryPath, CharacterSequence[] characterSequences)
        {
            using (var sw = new StringWriter())
            {
                string directoryName = Path.GetFileName(directoryPath);

                sw.WriteLine($"## {directoryName}");
                sw.WriteLine();

                if (characterSequences.Length > 0)
                {
                    sw.WriteLine("### Quick Reference");
                    sw.WriteLine();

                    string filePath = $@"..\..\..\..\..\text\{directoryName}.md";

                    if (File.Exists(filePath))
                    {
                        sw.WriteLine(File.ReadAllText(filePath, Encoding.UTF8));
                        sw.WriteLine();
                    }

                    using (CharacterSequenceTableWriter tableWriter = CharacterSequenceTableWriter.Create())
                    {
                        tableWriter.WriteTable(characterSequences);
                        sw.Write(tableWriter.ToString());
                    }

                    sw.WriteLine();
                }

                sw.WriteLine($"* [full list of snippets (sorted by title)]({SnippetsByTitleFileName})");
                sw.WriteLine($"* [full list of snippets (sorted by shortcut)]({SnippetsByShortcutFileName})");
                sw.WriteLine();

                sw.WriteLine("### List of Selected Snippets");
                sw.WriteLine();

                using (SnippetTableWriter tableWriter = SnippetTableWriter.CreateTitleThenShortcut(directoryPath))
                {
                    tableWriter.WriteTable(snippets);
                    sw.Write(tableWriter.ToString());
                }

                return(sw.ToString());
            }
        }