void UseSnippetExtractor() { // get files containing snippets var filesToParse = Directory.EnumerateFiles(@"C:\path", "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".vm") || s.EndsWith(".cs")); // setup version convention and extract snippets from files var snippetExtractor = new SnippetExtractor(InferVersion); var readSnippets = snippetExtractor.FromFiles(filesToParse); // Grouping var snippetGroups = SnippetGrouper.Group(readSnippets) .ToList(); // Merge with some markdown text var markdownProcessor = new MarkdownProcessor(); //In this case the text will be extracted from a file path ProcessResult result; using (var reader = File.OpenText(@"C:\path\myInputMarkdownFile.md")) using (var writer = File.CreateText(@"C:\path\myOutputMarkdownFile.md")) { result = markdownProcessor.Apply(snippetGroups, reader, writer); } // List of all snippets that the markdown file expected but did not exist in the input snippets var missingSnippets = result.MissingSnippets; // List of all snippets that the markdown file used var usedSnippets = result.UsedSnippets; }
void Run(string folder, string input, string expectedOutput) { var extractor = new SnippetExtractor(s => VersionRange.All); var snippets = extractor.FromFiles(Directory.EnumerateFiles(folder, "code.cs")); var snippetGroups = SnippetGrouper.Group(snippets) .ToList(); using (var reader = File.OpenText(input)) { var markdownProcessor = new MarkdownProcessor(alsoParseImportSyntax:true); var stringBuilder = new StringBuilder(); using (var writer = new StringWriter(stringBuilder)) { markdownProcessor.Apply(snippetGroups, reader, writer); } var expected = File.ReadAllText(expectedOutput).FixNewLines(); var fixNewLines = stringBuilder .ToString() .FixNewLines() .TrimTrailingNewLine(); Assert.AreEqual(expected, fixNewLines, folder); } }
public void Foo() { var extractor = new SnippetExtractor(InferVersion); var snippets = extractor.FromFiles(Directory.EnumerateFiles(@"C:\Code\docs.particular.net\Snippets", "*.cs",SearchOption.AllDirectories)); Trace.WriteLine(snippets.ToList()); }
/// <summary> /// Constructor. /// </summary> /// <param name="versionFromFilePathExtractor">The version convention that is passed to <see cref="SnippetExtractor"/>.</param> /// <param name="includeDirectory">Directories to include.</param> /// <param name="includeFile">Files to include.</param> public CachedSnippetExtractor(Func<string, VersionRange> versionFromFilePathExtractor, Func<string, bool> includeDirectory, Func<string, bool> includeFile) { Guard.AgainstNull(versionFromFilePathExtractor, "versionFromFilePathExtractor"); Guard.AgainstNull(includeDirectory, "includeDirectory"); Guard.AgainstNull(includeFile, "includeFile"); this.includeDirectory = includeDirectory; this.includeFile = includeFile; snippetExtractor = new SnippetExtractor(versionFromFilePathExtractor); }
void ConstructSnippetExtractorWIthCustomVersionInferer() { var snippetExtractor = new SnippetExtractor(InferVersion); }
public ReadSnippets FromText(string contents) { using (var stringReader = new StringReader(contents)) { var extractor = new SnippetExtractor(s => VersionRange.All); return extractor.FromReader(stringReader); } }
public void CanExtractVersionFromFile() { var input = @" <!-- startcode CodeKey --> <configSections/> <!-- endcode -->"; using (var stringReader = new StringReader(input)) { var versionRange = new VersionRange(new NuGetVersion(1, 1, 0)); var extractor = new SnippetExtractor(s => versionRange); var readSnippets = extractor.FromReader(stringReader); ObjectApprover.VerifyWithJson(readSnippets); } }