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 	/**
24 	 * AST node associated to the item.
25 	 *
26 	 * Used in a case per case basis to format extra info that
27 	 * cant be put directly as string.
28 	 */
29 	const ASTNode node;
30 }
31 
32 /// Declarations of a module.
33 struct Members
34 {
35 	/** */ Item[] aliases;
36 	/** */ Item[] classes;
37 	/** */ Item[] enums;
38 	/** */ Item[] functions;
39 	/** */ Item[] interfaces;
40 	/** */ Item[] structs;
41 	/** */ Item[] templates;
42 	/** */ Item[] values;
43 	/** */ Item[] variables;
44 
45 	/** */ Item[] publicImports;
46 
47 	/// Write the list of public imports declared in a module.
48 	void writePublicImports(R, Writer)(ref R dst, Writer writer)
49 	{
50 		if (publicImports.empty)
51 			return;
52 		writer.writeSection(dst, 
53 		{
54 			writer.writeList(dst, "Public imports",
55 			{
56 				foreach (imp; publicImports) writer.writeListItem(dst,
57 				{
58 					if (imp.url.length)
59 					{
60 						dst.put(imp.name);
61 					}
62 					else writer.writeLink(dst, imp.url,
63 					{
64 						dst.put(imp.name);
65 					});
66 				});
67 			});
68 		}, "imports");
69 	}
70 
71 	/// Write the table of members for a class/struct/module/etc.
72 	void write(R, Writer)(ref R dst, Writer writer)
73 	{
74 		if ([aliases, classes, enums, functions, interfaces, structs, templates, values, variables].all!empty)
75 			return;
76 		writer.writeSection(dst,
77 		{
78 			if (enums.length)       writer.writeItems(dst, enums, "Enums");
79 			if (aliases.length)     writer.writeItems(dst, aliases, "Aliases");
80 			if (variables.length)   writer.writeItems(dst, variables, "Variables");
81 			if (functions.length)   writer.writeItems(dst, functions, "Functions");
82 			if (structs.length)     writer.writeItems(dst, structs, "Structs");
83 			if (interfaces.length)  writer.writeItems(dst, interfaces, "Interfaces");
84 			if (classes.length)     writer.writeItems(dst, classes, "Classes");
85 			if (templates.length)   writer.writeItems(dst, templates, "Templates");
86 			if (values.length)      writer.writeItems(dst, values, "Values");
87 		}, "members");
88 	}
89 }