1 /**
2 	Central import for all DDOX functionality.
3 
4 	Copyright: © 2012 RejectedSoftware e.K.
5 	License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
6 	Authors: Sönke Ludwig
7 */
8 module ddox.ddox;
9 
10 public import ddox.ddox;
11 public import ddox.entities;
12 public import ddox.htmlgenerator;
13 public import ddox.htmlserver;
14 public import ddox.settings;
15 
16 import std.algorithm;
17 import std.string;
18 
19 /**
20 	Applies settings such as sorting and documentation inheritance.
21 */
22 void processDocs(Package root, DdoxSettings settings)
23 {
24 	import ddox.processors.eptemplates;
25 	import ddox.processors.inherit;
26 	import ddox.processors.sort;
27 	import ddox.processors.split;
28 
29 	if (settings.mergeEponymousTemplates) {
30 		mergeEponymousTemplates(root);
31 	}
32 	if (settings.inheritDocumentation) {
33 		inheritDocs(root);
34 	}
35 
36 	splitDocGroups(root, true, false, false);
37 
38 	if (settings.moduleSort != SortMode.none) {
39 		auto mpred = sortPred(settings.moduleSort);
40 		sortModules!((a, b)  => mpred(a, b))(root);
41 		
42 		import std.algorithm;
43 		bool package_order(Package a, Package b){
44 			auto ia = settings.packageOrder.countUntil(a.name);
45 			auto ib = settings.packageOrder.countUntil(b.name);
46 			if( ia >= 0 && ib >= 0 ) return ia < ib;
47 			if( ia >= 0 ) return true;
48 			return false;
49 		}
50 		sort!(package_order, SwapStrategy.stable)(root.packages);
51 	}
52 	if( settings.declSort != SortMode.none ){
53 		auto dpred = sortPred(settings.declSort);
54 		sortDecls!((a, b)  => dpred(a, b))(root);
55 	}
56 }
57 
58 /// private
59 private bool function(Entity, Entity) sortPred(SortMode mode)
60 {
61 	final switch (mode) {
62 		case SortMode.none:
63 			assert(false);
64 		case SortMode.name:
65 			return (a, b) {
66 				assert(a !is null && b !is null);
67 				return icmp(a.name, b.name) < 0;
68 			};
69 		case SortMode.protectionName:
70 			return (a, b) {
71 				assert(a !is null && b !is null);
72 				auto pa = Protection.Public;
73 				auto pb = Protection.Public;
74 				if (auto da = cast(Declaration)a) pa = da.protection;
75 				if (auto db = cast(Declaration)b) pb = db.protection;
76 				if (pa != pb) return pa > pb;
77 				return icmp(a.name, b.name) < 0;
78 			};
79 		case SortMode.protectionInheritanceName:
80 			return (a, b) {
81 				assert(a !is null && b !is null);
82 				auto pa = Protection.Public;
83 				auto pb = Protection.Public;
84 				bool ia, ib;
85 				if (auto da = cast(Declaration)a) pa = da.protection, ia = da.inheritingDecl !is null;
86 				if (auto db = cast(Declaration)b) pb = db.protection, ib = db.inheritingDecl !is null;
87 				if (pa != pb) return pa > pb;
88 				if (ia != ib) return ib;
89 				return icmp(a.name, b.name) < 0;
90 			};
91 	}
92 }
93