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 
16 struct Item {
17     string url;
18     string name;
19     string summary;
20     string type;
21 
22     /// AST node of the item. Only used for functions at the moment.
23     const ASTNode node;
24 }
25 
26 struct Members {
27     Item[] aliases;
28     Item[] classes;
29     Item[] enums;
30     Item[] functions;
31     Item[] interfaces;
32     Item[] structs;
33     Item[] templates;
34     Item[] values;
35     Item[] variables;
36 
37     Item[] publicImports;
38 
39     /// Write the list of public imports declared in a module.
40     void writePublicImports(R, Writer)(ref R dst, Writer writer) {
41         if(publicImports.empty) { return; }
42         writer.writeSection(dst, {
43             writer.writeList(dst, "Public imports",{
44                 foreach(imp; publicImports) {
45                     writer.writeListItem(dst, {
46                         if (imp.url is null) {
47                             dst.put(imp.name);
48                         } else writer.writeLink(dst, imp.url, {
49                             dst.put(imp.name);
50                         });
51                     });
52                 }
53             });
54         }, "imports");
55     }
56 
57     /// Write the table of members for a class/struct/module/etc.
58     void write(R, Writer)(ref R dst, Writer writer) {
59         if (aliases.empty && classes.empty && enums.empty && functions.empty
60             && interfaces.empty && structs.empty && templates.empty 
61             && values.empty && variables.empty) {
62             return;
63         }
64         writer.writeSection(dst, {
65             if(!enums.empty)      writer.writeItems(dst, enums, "Enums");
66             if(!aliases.empty)    writer.writeItems(dst, aliases, "Aliases");
67             if(!variables.empty)  writer.writeItems(dst, variables, "Variables");
68             if(!functions.empty)  writer.writeItems(dst, functions, "Functions");
69             if(!structs.empty)    writer.writeItems(dst, structs, "Structs");
70             if(!interfaces.empty) writer.writeItems(dst, interfaces, "Interfaces");
71             if(!classes.empty)    writer.writeItems(dst, classes, "Classes");
72             if(!templates.empty)  writer.writeItems(dst, templates, "Templates");
73             if(!values.empty)     writer.writeItems(dst, values, "Values");
74         }, "members");
75     }
76 }