This repository was archived by the owner on Apr 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUsage.cs
More file actions
107 lines (87 loc) · 3.39 KB
/
Copy pathUsage.cs
File metadata and controls
107 lines (87 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CaptureSnippets;
using NuGet.Versioning;
class Usage
{
void ReadingFiles()
{
#region ReadingFiles
var files = Directory.EnumerateFiles(@"C:\path", "*.cs", SearchOption.AllDirectories);
var snippetExtractor = FileSnippetExtractor.Build(
fileVersion: VersionRange.Parse("[1.1,2.0)"),
package: "ThePackageName",
isCurrent: true);
var snippets = snippetExtractor.Read(files);
#endregion
}
void ReadingDirectory()
{
#region ReadingDirectory
IEnumerable<string> PackageOrder(string component)
{
if (component == "component1")
{
return new List<string>
{
"package1",
"package2"
};
}
return Enumerable.Empty<string>();
}
string TranslatePackage(string packageAlias)
{
if (packageAlias == "shortName")
{
return "theFullPackageName";
}
return packageAlias;
}
// setup version convention and extract snippets from files
var snippetExtractor = new DirectorySnippetExtractor(
// all directories except bin and obj
directoryFilter: dirPath => !dirPath.EndsWith("bin") && !dirPath.EndsWith("obj"),
// all vm and cs files
fileFilter: filePath => filePath.EndsWith(".vm") || filePath.EndsWith(".cs"),
// package order is optional
packageOrder: PackageOrder,
// package translation is optional
translatePackage: TranslatePackage
);
var components = snippetExtractor.ReadComponents(@"C:\path");
var component1 = components.GetComponent("Component1");
var packagesForComponent1 = component1.Packages;
var snippetsForComponent1 = component1.Snippets;
var packages = snippetExtractor.ReadPackages(@"C:\path");
var package1 = components.GetComponent("Package1");
var snippetsForPackage1 = package1.Snippets;
// The below snippets could also be accessed via
// * packages.Snippets
// * components.AllSnippets
var snippets = snippetExtractor.ReadSnippets(@"C:\path");
#endregion
}
void Basic()
{
#region markdownProcessing
// setup version convention and extract snippets from files
var snippetExtractor = new DirectorySnippetExtractor(
directoryFilter: x => true,
fileFilter: s => s.EndsWith(".vm") || s.EndsWith(".cs"));
var snippets = snippetExtractor.ReadSnippets(@"C:\path");
// Merge with some markdown text
var markdownProcessor = new MarkdownProcessor(snippets, SimpleSnippetMarkdownHandling.AppendGroup);
using (var reader = File.OpenText(@"C:\path\inputMarkdownFile.md"))
using (var writer = File.CreateText(@"C:\path\outputMarkdownFile.md"))
{
var result = markdownProcessor.Apply(reader, writer);
// snippets that the markdown file expected but did not exist in the input snippets
var missingSnippets = result.MissingSnippets;
// snippets that the markdown file used
var usedSnippets = result.UsedSnippets;
}
#endregion
}
}