-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPrinter.cs
71 lines (58 loc) · 2.13 KB
/
Printer.cs
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
using System;
using System.IO;
namespace SimpleDocs
{
public class Printer
{
public Printer ()
{
}
public static void PrintDocs(Container[] containers, Member[] members, Function[] functions, string docName, string format)
{
string cdocs = "";
string mdocs = "";
string fdocs = "";
if (format == "JSON")
{
foreach (Container c in containers)
cdocs += (cdocs != "" ? ",\n" : "") + "\t\t" + c.ToString();
foreach (Member m in members)
mdocs += (mdocs != "" ? ",\n" : "") + "\t\t" + m.ToString();
foreach (Function f in functions)
fdocs += (fdocs != "" ? ",\n" : "") + "\t\t" + f.ToString();
TextWriter tw = new StreamWriter(docName);
tw.WriteLine("{");
tw.WriteLine("\t\"Containers\":\n\t[\n" + cdocs + "\n\t],");
tw.WriteLine("\t\"Members\":\n\t[\n" + mdocs + "\n\t],");
tw.WriteLine("\t\"Functions\":\n\t[\n" + fdocs + "\n\t]");
tw.WriteLine("}");
tw.Close();
}
else // HTML
{
foreach (Container c in containers)
cdocs += (cdocs != "" ? ", " : "") + c.ToString();
foreach (Member m in members)
mdocs += (mdocs != "" ? ", " : "") + m.ToString();
foreach (Function f in functions)
fdocs += (fdocs != "" ? ", " : "") + f.ToString();
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
path = path.Substring(0, path.LastIndexOf("/") + 1);
TextReader reader = new StreamReader(path + "DocsTemplate.html");
string content = reader.ReadToEnd();
reader.Close();
// OLD INSERTION MODE (requires eval(..)) - DEPRECATED, does not support the use of quotes
content = content.Replace("{[JSONContainers]}", "[" + cdocs + "]");
content = content.Replace("{[JSONMembers]}", "[" + mdocs + "]");
content = content.Replace("{[JSONFunctions]}", "[" + fdocs + "]");
// NEW INSERTION MODE (does not require eval(..))
content = content.Replace("/*** Containers ***/", cdocs);
content = content.Replace("/*** Members ***/", mdocs);
content = content.Replace("/*** Functions ***/", fdocs);
TextWriter writer = new StreamWriter(docName);
writer.Write(content);
writer.Close();
}
}
}
}