Пример #1
0
        public static void WriteDirectoryMarkdownFiles(Snippet[] snippets, string directoryPath, CharacterSequence[] characterSequences)
        {
            IOUtility.WriteAllText(
                Path.Combine(directoryPath, "README.md"),
                GenerateDirectoryReadme(snippets.Where(f => !f.HasTag(KnownTags.ExcludeFromReadme)), directoryPath, characterSequences));

            IOUtility.WriteAllText(
                Path.Combine(directoryPath, SnippetsByTitleFileName),
                GenerateSnippetList(snippets, directoryPath, SnippetTableWriter.CreateTitleThenShortcut(directoryPath)));

            IOUtility.WriteAllText(
                Path.Combine(directoryPath, SnippetsByShortcutFileName),
                GenerateSnippetList(snippets, directoryPath, SnippetTableWriter.CreateShortcutThenTitle(directoryPath)));
        }
Пример #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());
            }
        }