1 /**
2  * D Documentation Generator
3  * Copyright: © 2014 Economic Modeling Specialists, Intl., © 2015 Ferdinand Majerech
4  * Authors: Brian Schott, Ferdinand Majerech
5  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt Boost License 1.0)
6  */
7 module item;
8 
9 import formatter;
10 import std.algorithm;
11 import std.array: appender, empty, array;
12 import dparse.ast;
13 import std.string: format;
14 
15 /// Information associated to a particular declaration.
16 struct Item
17 {
18 	/** */ string url;
19 	/** */ string name;
20 	/** */ string summary;
21 	/** */ string type;
22 
23 	/// AST node of the item. Only used for functions at the moment.
24 	const ASTNode node;
25 }
26 
27 /// Declarations of a module.
28 struct Members
29 {
30 	/** */ Item[] aliases;
31 	/** */ Item[] classes;
32 	/** */ Item[] enums;
33 	/** */ Item[] functions;
34 	/** */ Item[] interfaces;
35 	/** */ Item[] structs;
36 	/** */ Item[] templates;
37 	/** */ Item[] values;
38 	/** */ Item[] variables;
39 
40 	Item[] publicImports;
41 
42 	void writeImports(R, Writer)(ref R dst, Writer writer)
43 	{
44 		if (publicImports.empty)
45 			return;
46 		writer.writeSection(dst, 
47 		{
48 			writer.writeList(dst, "Public imports",
49 			{
50 				foreach (imp; publicImports) writer.writeListItem(dst,
51 				{
52 					if (imp.url.length)
53 					{
54 						dst.put(imp.name);
55 					}
56 					else writer.writeLink(dst, imp.url,
57 					{
58 						dst.put(imp.name);
59 					});
60 				});
61 			});
62 		}, "imports");
63 	}
64 
65 	/// Write the table of members for a class/struct/module/etc.
66 	void write(R, Writer)(ref R dst, Writer writer)
67 	{
68 		if ([aliases, classes, enums, functions, interfaces, structs, templates, values, variables].all!empty)
69 			return;
70 		writer.writeSection(dst,
71 		{
72 			if (enums.length)       writer.writeItems(dst, enums, "Enums");
73 			if (aliases.length)     writer.writeItems(dst, aliases, "Aliases");
74 			if (variables.length)   writer.writeItems(dst, variables, "Variables");
75 			if (functions.length)   writer.writeItems(dst, functions, "Functions");
76 			if (structs.length)     writer.writeItems(dst, structs, "Structs");
77 			if (interfaces.length)  writer.writeItems(dst, interfaces, "Interfaces");
78 			if (classes.length)     writer.writeItems(dst, classes, "Classes");
79 			if (templates.length)   writer.writeItems(dst, templates, "Templates");
80 			if (values.length)      writer.writeItems(dst, values, "Values");
81 		}, "members");
82 	}
83 }