Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit 6692d62

Browse files
committed
Add folders to generate config value to allow specifying which folders should be generated with markdown files or excluded based on category such as classes, namespaces, files, etc
1 parent 24a226d commit 6692d62

File tree

6 files changed

+186
-79
lines changed

6 files changed

+186
-79
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ The following is a list of config properties, their default value, and descripti
303303
| `linkSuffix` | `".md"` | The suffix to put after all of the markdown links (only links to other markdown files). If using GitBook, leave this to `".md"`, but MkDocs and Hugo needs `"/"` instead. |
304304
| `fileExt` | `"md"` | The file extension to use when generating markdown files. |
305305
| `filesFilter` | `[]` | This will filter which files are allowed to be in the output. For example, an array of `[".hpp", ".h"]` will allow only the files that have file extensions `.hpp` or `.h`. When this is empty (by default) then all files are allowed in the output. This also affects `--json` type of output. This does not filter which classes/functions/etc should be extracted from the source files! (For that, use Doxygen's [FILE_PATTERNS](https://www.doxygen.nl/manual/config.html#cfg_file_patterns)) This only affects listing of those files in the output! |
306+
| `foldersToGenerate` | `["modules", "classes", "files", "pages", "namespaces", "examples"]` | List of folders to create. You can use this to skip generation of some folders, for example you don't want `examples` then remove it from the array. Note, this does not change the name of the folders that will be generated, this only enables them. This is an enum and must be lower case. If you do not set this value in your JSON config file then all of the folders are created. An empty array will not generate anything at all.' |
306307
307308
The following are a list of config properties that specify the names of the folders. Each folder holds specific group of C++ stuff. Note that the `Classes` folder also holds interfaces, structs, and unions.
308309

include/Doxybook/Config.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ namespace Doxybook2 {
9191

9292
// Which source files are allowed to be included in the output? (empty => all)
9393
std::vector<std::string> filesFilter{};
94+
95+
// Folder to generate.
96+
std::vector<FolderCategory> foldersToGenerate{
97+
FolderCategory::MODULES,
98+
FolderCategory::CLASSES,
99+
FolderCategory::FILES,
100+
FolderCategory::PAGES,
101+
FolderCategory::NAMESPACES,
102+
FolderCategory::EXAMPLES,
103+
};
94104
};
95105

96106
void loadConfig(Config& config, const std::string& path);

include/Doxybook/Enums.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,18 @@ namespace Doxybook2 {
6161
extern Type toEnumType(const std::string& str);
6262
extern Visibility toEnumVisibility(const std::string& str);
6363
extern Virtual toEnumVirtual(const std::string& str);
64+
extern FolderCategory toEnumFolderCategory(const std::string& str);
6465

6566
extern std::string toStr(Kind value);
6667
extern std::string toStr(Type value);
6768
extern std::string toStr(Visibility value);
6869
extern std::string toStr(Virtual value);
70+
extern std::string toStr(FolderCategory value);
6971

7072
extern bool isKindLanguage(Kind kind);
7173
extern bool isKindStructured(Kind kind);
7274
extern bool isKindFile(Kind kind);
75+
extern std::string typeFolderCategoryToFolderName(const Config& config, FolderCategory type);
7376
extern std::string typeToFolderName(const Config& config, Type type);
7477
extern std::string typeToIndexName(const Config& config, FolderCategory type);
7578
extern std::string typeToIndexTemplate(const Config& config, FolderCategory type);
@@ -82,4 +85,12 @@ namespace Doxybook2 {
8285
inline void from_json(const nlohmann::json& j, Visibility& p) {
8386
p = toEnumVisibility(j.get<std::string>());
8487
}
88+
89+
inline void to_json(nlohmann::json& j, const FolderCategory& p) {
90+
j = toStr(p);
91+
}
92+
93+
inline void from_json(const nlohmann::json& j, FolderCategory& p) {
94+
p = toEnumFolderCategory(j.get<std::string>());
95+
}
8596
} // namespace Doxybook2

src/Doxybook/Config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static const std::vector<ConfigArg> CONFIG_ARGS = {
7272
ConfigArg(&Doxybook2::Config::indexFilesTitle, "indexFilesTitle"),
7373
ConfigArg(&Doxybook2::Config::indexExamplesTitle, "indexExamplesTitle"),
7474
ConfigArg(&Doxybook2::Config::filesFilter, "filesFilter"),
75+
ConfigArg(&Doxybook2::Config::foldersToGenerate, "foldersToGenerate"),
7576
};
7677

7778
void Doxybook2::loadConfig(Config& config, const std::string& path) {

src/Doxybook/Enums.cpp

Lines changed: 79 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using KindStrPair = std::pair<std::string, Doxybook2::Kind>;
77
using TypeStrPair = std::pair<std::string, Doxybook2::Type>;
88
using VirtualStrPair = std::pair<std::string, Doxybook2::Virtual>;
99
using VisibilityStrPair = std::pair<std::string, Doxybook2::Visibility>;
10+
using FolderCategoryStrPair = std::pair<std::string, Doxybook2::FolderCategory>;
1011

1112
// clang-format off
1213
static const std::vector<KindStrPair> KIND_STRS = {
@@ -66,96 +67,88 @@ static const std::vector<VisibilityStrPair> VISIBILITY_STRS = {
6667
{"private", Doxybook2::Visibility::PRIVATE},
6768
{"package", Doxybook2::Visibility::PACKAGE}
6869
};
70+
71+
static const std::vector<FolderCategoryStrPair> FOLDER_CATEGORY_STRS = {
72+
{"modules", Doxybook2::FolderCategory::MODULES},
73+
{"namespaces", Doxybook2::FolderCategory::NAMESPACES},
74+
{"files", Doxybook2::FolderCategory::FILES},
75+
{"examples", Doxybook2::FolderCategory::EXAMPLES},
76+
{"classes", Doxybook2::FolderCategory::CLASSES},
77+
{"pages", Doxybook2::FolderCategory::PAGES}
78+
};
6979
// clang-format on
7080

71-
Doxybook2::Kind Doxybook2::toEnumKind(const std::string& str) {
72-
const auto it =
73-
std::find_if(KIND_STRS.begin(), KIND_STRS.end(), [&](const KindStrPair& pair) { return pair.first == str; });
81+
template <typename Enum> struct EnumName { static inline const auto name = "unknown"; };
82+
83+
template <> struct EnumName<Doxybook2::Kind> { static inline const auto name = "Kind"; };
84+
template <> struct EnumName<Doxybook2::Type> { static inline const auto name = "Type"; };
85+
template <> struct EnumName<Doxybook2::Virtual> { static inline const auto name = "Virtual"; };
86+
template <> struct EnumName<Doxybook2::Visibility> { static inline const auto name = "Visibility"; };
87+
template <> struct EnumName<Doxybook2::FolderCategory> { static inline const auto name = "FolderCategory"; };
7488

75-
if (it == KIND_STRS.end()) {
76-
throw EXCEPTION("Kind {} not recognised please contact the author", str);
89+
template <typename Enum>
90+
static Enum toEnum(const std::vector<std::pair<std::string, Enum>>& pairs, const std::string& str) {
91+
const auto it = std::find_if(
92+
pairs.begin(), pairs.end(), [&](const std::pair<std::string, Enum>& pair) { return pair.first == str; });
93+
94+
if (it == pairs.end()) {
95+
throw EXCEPTION("String '{}' not recognised as a valid enum of '{}'", str, EnumName<Enum>::name);
7796
}
7897

7998
return it->second;
8099
}
81100

82-
std::string Doxybook2::toStr(const Doxybook2::Kind value) {
83-
const auto it =
84-
std::find_if(KIND_STRS.begin(), KIND_STRS.end(), [&](const KindStrPair& pair) { return pair.second == value; });
101+
template <typename Enum>
102+
static std::string fromEnum(const std::vector<std::pair<std::string, Enum>>& pairs, const Enum value) {
103+
const auto it = std::find_if(
104+
pairs.begin(), pairs.end(), [&](const std::pair<std::string, Enum>& pair) { return pair.second == value; });
85105

86-
if (it == KIND_STRS.end()) {
87-
throw EXCEPTION("Kind {} not recognised please contact the author", int(value));
106+
if (it == pairs.end()) {
107+
throw EXCEPTION(
108+
"Enum '{}' of value '{}' not recognised please contact the author", EnumName<Enum>::name, int(value));
88109
}
89110

90111
return it->first;
91112
}
92113

93-
Doxybook2::Virtual Doxybook2::toEnumVirtual(const std::string& str) {
94-
const auto it = std::find_if(
95-
VIRTUAL_STRS.begin(), VIRTUAL_STRS.end(), [&](const VirtualStrPair& pair) { return pair.first == str; });
114+
Doxybook2::Kind Doxybook2::toEnumKind(const std::string& str) {
115+
return toEnum<Kind>(KIND_STRS, str);
116+
}
96117

97-
if (it == VIRTUAL_STRS.end()) {
98-
throw EXCEPTION("Virtual {} not recognised please contact the author", str);
99-
}
118+
std::string Doxybook2::toStr(const Kind value) {
119+
return fromEnum<Kind>(KIND_STRS, value);
120+
}
100121

101-
return it->second;
122+
Doxybook2::Virtual Doxybook2::toEnumVirtual(const std::string& str) {
123+
return toEnum<Virtual>(VIRTUAL_STRS, str);
102124
}
103125

104126
std::string Doxybook2::toStr(const Virtual value) {
105-
const auto it = std::find_if(
106-
VIRTUAL_STRS.begin(), VIRTUAL_STRS.end(), [&](const VirtualStrPair& pair) { return pair.second == value; });
107-
108-
if (it == VIRTUAL_STRS.end()) {
109-
throw EXCEPTION("Virtual {} not recognised please contact the author", int(value));
110-
}
111-
112-
return it->first;
127+
return fromEnum<Virtual>(VIRTUAL_STRS, value);
113128
}
114129

115130
Doxybook2::Visibility Doxybook2::toEnumVisibility(const std::string& str) {
116-
const auto it = std::find_if(VISIBILITY_STRS.begin(), VISIBILITY_STRS.end(), [&](const VisibilityStrPair& pair) {
117-
return pair.first == str;
118-
});
119-
120-
if (it == VISIBILITY_STRS.end()) {
121-
throw EXCEPTION("Visibility {} not recognised please contact the author", str);
122-
}
123-
124-
return it->second;
131+
return toEnum<Visibility>(VISIBILITY_STRS, str);
125132
}
126133

127134
std::string Doxybook2::toStr(const Visibility value) {
128-
const auto it = std::find_if(VISIBILITY_STRS.begin(), VISIBILITY_STRS.end(), [&](const VisibilityStrPair& pair) {
129-
return pair.second == value;
130-
});
131-
132-
if (it == VISIBILITY_STRS.end()) {
133-
throw EXCEPTION("Visibility {} not recognised please contact the author", int(value));
134-
}
135-
136-
return it->first;
135+
return fromEnum<Visibility>(VISIBILITY_STRS, value);
137136
}
138137

139138
Doxybook2::Type Doxybook2::toEnumType(const std::string& str) {
140-
const auto it =
141-
std::find_if(TYPE_STRS.begin(), TYPE_STRS.end(), [&](const TypeStrPair& pair) { return pair.first == str; });
142-
143-
if (it == TYPE_STRS.end()) {
144-
throw EXCEPTION("Type {} not recognised please contact the author", str);
145-
}
146-
147-
return it->second;
139+
return toEnum<Type>(TYPE_STRS, str);
148140
}
149141

150142
std::string Doxybook2::toStr(const Type value) {
151-
const auto it =
152-
std::find_if(TYPE_STRS.begin(), TYPE_STRS.end(), [&](const TypeStrPair& pair) { return pair.second == value; });
143+
return fromEnum<Type>(TYPE_STRS, value);
144+
}
153145

154-
if (it == TYPE_STRS.end()) {
155-
throw EXCEPTION("Type {} not recognised please contact the author", int(value));
156-
}
146+
Doxybook2::FolderCategory Doxybook2::toEnumFolderCategory(const std::string& str) {
147+
return toEnum<FolderCategory>(FOLDER_CATEGORY_STRS, str);
148+
}
157149

158-
return it->first;
150+
std::string Doxybook2::toStr(const FolderCategory value) {
151+
return fromEnum<FolderCategory>(FOLDER_CATEGORY_STRS, value);
159152
}
160153

161154
bool Doxybook2::isKindStructured(const Kind kind) {
@@ -211,6 +204,35 @@ bool Doxybook2::isKindFile(const Kind kind) {
211204
}
212205
}
213206

207+
std::string Doxybook2::typeFolderCategoryToFolderName(const Config& config, FolderCategory type) {
208+
if (!config.useFolders)
209+
return "";
210+
211+
switch (type) {
212+
case FolderCategory::MODULES: {
213+
return config.folderGroupsName;
214+
}
215+
case FolderCategory::CLASSES: {
216+
return config.folderClassesName;
217+
}
218+
case FolderCategory::NAMESPACES: {
219+
return config.folderNamespacesName;
220+
}
221+
case FolderCategory::FILES: {
222+
return config.folderFilesName;
223+
}
224+
case FolderCategory::PAGES: {
225+
return config.folderRelatedPagesName;
226+
}
227+
case FolderCategory::EXAMPLES: {
228+
return config.folderExamplesName;
229+
}
230+
default: {
231+
throw EXCEPTION("FolderCategory {} not recognised please contant the author!", int(type));
232+
}
233+
}
234+
}
235+
214236
std::string Doxybook2::typeToFolderName(const Config& config, const Type type) {
215237
if (!config.useFolders)
216238
return "";

src/DoxybookCli/main.cpp

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,24 @@ int main(const int argc, char* argv[]) {
149149

150150
Generator generator(config, jsonConverter, templatesPath);
151151

152+
const auto shouldGenerate = [&](const FolderCategory category) {
153+
return std::find(config.foldersToGenerate.begin(), config.foldersToGenerate.end(), category) !=
154+
config.foldersToGenerate.end();
155+
};
156+
152157
if (config.useFolders) {
153-
static const std::array<Type, 6> ALL_GROUPS = {
154-
Type::CLASSES, Type::NAMESPACES, Type::FILES, Type::MODULES, Type::PAGES, Type::EXAMPLES};
158+
static const std::array<FolderCategory, 6> ALL_GROUPS = {
159+
FolderCategory::CLASSES,
160+
FolderCategory::NAMESPACES,
161+
FolderCategory::FILES,
162+
FolderCategory::MODULES,
163+
FolderCategory::PAGES,
164+
FolderCategory::EXAMPLES,
165+
};
155166
for (const auto& g : ALL_GROUPS) {
156-
Utils::createDirectory(Path::join(config.outputDir, typeToFolderName(config, g)));
167+
if (shouldGenerate(g)) {
168+
Utils::createDirectory(Path::join(config.outputDir, typeFolderCategoryToFolderName(config, g)));
169+
}
157170
}
158171
if (!config.imagesFolder.empty()) {
159172
Utils::createDirectory(Path::join(config.outputDir, config.imagesFolder));
@@ -174,28 +187,77 @@ int main(const int argc, char* argv[]) {
174187
generator.manifest(doxygen);
175188
} else {
176189
if (args["summary-input"] && args["summary-output"]) {
190+
std::vector<Generator::SummarySection> sections;
191+
if (shouldGenerate(FolderCategory::CLASSES)) {
192+
sections.push_back({FolderCategory::CLASSES, INDEX_CLASS_FILTER, INDEX_CLASS_FILTER_SKIP});
193+
}
194+
if (shouldGenerate(FolderCategory::NAMESPACES)) {
195+
sections.push_back({FolderCategory::NAMESPACES, INDEX_NAMESPACES_FILTER, {}});
196+
}
197+
if (shouldGenerate(FolderCategory::MODULES)) {
198+
sections.push_back({FolderCategory::MODULES, INDEX_MODULES_FILTER, {}});
199+
}
200+
if (shouldGenerate(FolderCategory::FILES)) {
201+
sections.push_back({FolderCategory::FILES, INDEX_FILES_FILTER, {}});
202+
}
203+
if (shouldGenerate(FolderCategory::PAGES)) {
204+
sections.push_back({FolderCategory::PAGES, INDEX_PAGES_FILTER, {}});
205+
}
206+
if (shouldGenerate(FolderCategory::EXAMPLES)) {
207+
sections.push_back({FolderCategory::EXAMPLES, INDEX_EXAMPLES_FILTER, {}});
208+
}
209+
177210
generator.summary(doxygen,
178211
args["summary-input"].as<std::string>(),
179212
args["summary-output"].as<std::string>(),
180-
{{FolderCategory::CLASSES, INDEX_CLASS_FILTER, INDEX_CLASS_FILTER_SKIP},
181-
{FolderCategory::NAMESPACES, INDEX_NAMESPACES_FILTER, {}},
182-
{FolderCategory::MODULES, INDEX_MODULES_FILTER, {}},
183-
{FolderCategory::FILES, INDEX_FILES_FILTER, {}},
184-
{FolderCategory::PAGES, INDEX_PAGES_FILTER, {}},
185-
{FolderCategory::EXAMPLES, INDEX_EXAMPLES_FILTER, {}}});
186-
}
187-
188-
generator.print(doxygen, LANGUAGE_FILTER, {});
189-
generator.print(doxygen, INDEX_FILES_FILTER, {});
190-
generator.print(doxygen, INDEX_PAGES_FILTER, {});
191-
generator.print(doxygen, INDEX_EXAMPLES_FILTER, {});
192-
193-
generator.printIndex(doxygen, FolderCategory::CLASSES, INDEX_CLASS_FILTER, {});
194-
generator.printIndex(doxygen, FolderCategory::NAMESPACES, INDEX_NAMESPACES_FILTER, {});
195-
generator.printIndex(doxygen, FolderCategory::MODULES, INDEX_MODULES_FILTER, {});
196-
generator.printIndex(doxygen, FolderCategory::FILES, INDEX_FILES_FILTER, {});
197-
generator.printIndex(doxygen, FolderCategory::PAGES, INDEX_PAGES_FILTER, {});
198-
generator.printIndex(doxygen, FolderCategory::EXAMPLES, INDEX_EXAMPLES_FILTER, {});
213+
sections);
214+
}
215+
216+
Generator::Filter languageFilder;
217+
if (shouldGenerate(FolderCategory::CLASSES)) {
218+
languageFilder.insert(Kind::CLASS);
219+
languageFilder.insert(Kind::STRUCT);
220+
languageFilder.insert(Kind::UNION);
221+
languageFilder.insert(Kind::INTERFACE);
222+
}
223+
if (shouldGenerate(FolderCategory::NAMESPACES)) {
224+
languageFilder.insert(Kind::NAMESPACE);
225+
}
226+
if (shouldGenerate(FolderCategory::MODULES)) {
227+
languageFilder.insert(Kind::MODULE);
228+
}
229+
if (!languageFilder.empty()) {
230+
generator.print(doxygen, languageFilder, {});
231+
}
232+
233+
if (shouldGenerate(FolderCategory::FILES)) {
234+
generator.print(doxygen, INDEX_FILES_FILTER, {});
235+
}
236+
if (shouldGenerate(FolderCategory::PAGES)) {
237+
generator.print(doxygen, INDEX_PAGES_FILTER, {});
238+
}
239+
if (shouldGenerate(FolderCategory::EXAMPLES)) {
240+
generator.print(doxygen, INDEX_EXAMPLES_FILTER, {});
241+
}
242+
243+
if (shouldGenerate(FolderCategory::CLASSES)) {
244+
generator.printIndex(doxygen, FolderCategory::CLASSES, INDEX_CLASS_FILTER, {});
245+
}
246+
if (shouldGenerate(FolderCategory::NAMESPACES)) {
247+
generator.printIndex(doxygen, FolderCategory::NAMESPACES, INDEX_NAMESPACES_FILTER, {});
248+
}
249+
if (shouldGenerate(FolderCategory::MODULES)) {
250+
generator.printIndex(doxygen, FolderCategory::MODULES, INDEX_MODULES_FILTER, {});
251+
}
252+
if (shouldGenerate(FolderCategory::FILES)) {
253+
generator.printIndex(doxygen, FolderCategory::FILES, INDEX_FILES_FILTER, {});
254+
}
255+
if (shouldGenerate(FolderCategory::PAGES)) {
256+
generator.printIndex(doxygen, FolderCategory::PAGES, INDEX_PAGES_FILTER, {});
257+
}
258+
if (shouldGenerate(FolderCategory::EXAMPLES)) {
259+
generator.printIndex(doxygen, FolderCategory::EXAMPLES, INDEX_EXAMPLES_FILTER, {});
260+
}
199261
}
200262
} else {
201263
help();

0 commit comments

Comments
 (0)