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

Commit

Permalink
Add filesFilter config option to specify a list of allowed file exten…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
matusnovak committed Dec 1, 2020
1 parent c1d3a38 commit 5c1824c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ The following is a list of config properties, their default value, and descripti
| `baseUrl` | `""` | A prefix to put in front of all markdown links (only links to other markdown files). See `linkLowercase` and `linkSuffix` as well. Note hat MkDocs and Hugo will need explicit baseUrl while GitBook uses no base url. VuePress needs this set to `/`. |
| `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. |
| `fileExt` | `"md"` | The file extension to use when generating markdown files. |
| `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! |
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.
Expand Down
3 changes: 3 additions & 0 deletions include/Doxybook/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ namespace Doxybook2 {
std::string indexFilesTitle{"Files"};
std::string indexRelatedPagesTitle{"Pages"};
std::string indexExamplesTitle{"Examples"};

// Which source files are allowed to be included in the output? (empty => all)
std::vector<std::string> filesFilter{};
};

void loadConfig(Config& config, const std::string& path);
Expand Down
1 change: 1 addition & 0 deletions include/Doxybook/Generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace Doxybook2 {
const Node& node,
const Filter& filter,
const Filter& skip);
bool shouldInclude(const Node& node);

const Config& config;
const JsonConverter& jsonConverter;
Expand Down
1 change: 1 addition & 0 deletions src/Doxybook/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static const std::vector<ConfigArg> CONFIG_ARGS = {
ConfigArg(&Doxybook2::Config::indexRelatedPagesTitle, "indexRelatedPagesTitle"),
ConfigArg(&Doxybook2::Config::indexFilesTitle, "indexFilesTitle"),
ConfigArg(&Doxybook2::Config::indexExamplesTitle, "indexExamplesTitle"),
ConfigArg(&Doxybook2::Config::filesFilter, "filesFilter"),
};

void Doxybook2::loadConfig(Config& config, const std::string& path) {
Expand Down
31 changes: 27 additions & 4 deletions src/Doxybook/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Doxybook/Path.hpp>
#include <Doxybook/Renderer.hpp>
#include <Doxybook/Utils.hpp>
#include <filesystem>
#include <fstream>

std::string Doxybook2::Generator::kindToTemplateName(const Kind kind) {
Expand Down Expand Up @@ -110,7 +111,7 @@ void Doxybook2::Generator::summaryRecursive(std::stringstream& ss,
continue;
}
if (filter.find(child->getKind()) != filter.end()) {
if (skip.find(child->getKind()) == skip.end()) {
if (skip.find(child->getKind()) == skip.end() && shouldInclude(*child)) {
ss << std::string(indent, ' ') << "* [" << child->getName() << "](" << folderName << "/"
<< child->getRefid() << ".md)\n";
}
Expand All @@ -122,7 +123,7 @@ void Doxybook2::Generator::summaryRecursive(std::stringstream& ss,
void Doxybook2::Generator::printRecursively(const Node& parent, const Filter& filter, const Filter& skip) {
for (const auto& child : parent.getChildren()) {
if (filter.find(child->getKind()) != filter.end()) {
if (skip.find(child->getKind()) == skip.end()) {
if (skip.find(child->getKind()) == skip.end() && shouldInclude(*child)) {
nlohmann::json data = jsonConverter.getAsJson(*child);

std::string path;
Expand All @@ -145,7 +146,7 @@ void Doxybook2::Generator::printRecursively(const Node& parent, const Filter& fi
void Doxybook2::Generator::jsonRecursively(const Node& parent, const Filter& filter, const Filter& skip) {
for (const auto& child : parent.getChildren()) {
if (filter.find(child->getKind()) != filter.end()) {
if (skip.find(child->getKind()) == skip.end()) {
if (skip.find(child->getKind()) == skip.end() && shouldInclude(*child)) {
nlohmann::json data = jsonConverter.getAsJson(*child);

const auto path = Path::join(config.outputDir, child->getRefid() + ".json");
Expand Down Expand Up @@ -185,6 +186,10 @@ void Doxybook2::Generator::manifest(const Doxygen& doxygen) {
nlohmann::json Doxybook2::Generator::manifestRecursively(const Node& node) {
auto ret = nlohmann::json::array();
for (const auto& child : node.getChildren()) {
if (!shouldInclude(*child)) {
continue;
}

nlohmann::json data;
data["kind"] = toStr(child->getKind());
data["name"] = child->getName();
Expand Down Expand Up @@ -221,7 +226,7 @@ nlohmann::json Doxybook2::Generator::buildIndexRecursively(const Node& node, con
sorted.reserve(node.getChildren().size());

for (const auto& child : node.getChildren()) {
if (filter.find(child->getKind()) != filter.end()) {
if (filter.find(child->getKind()) != filter.end() && shouldInclude(*child)) {
sorted.push_back(child.get());
}
}
Expand All @@ -242,3 +247,21 @@ nlohmann::json Doxybook2::Generator::buildIndexRecursively(const Node& node, con

return json;
}

bool Doxybook2::Generator::shouldInclude(const Node& node) {
switch (node.getKind()) {
case Kind::FILE: {
if (config.filesFilter.empty()) {
return true;
}

const auto ext = std::filesystem::path(node.getName()).extension().string();
const auto found = std::find(config.filesFilter.begin(), config.filesFilter.end(), ext);

return found != config.filesFilter.end();
}
default: {
return true;
}
}
}

0 comments on commit 5c1824c

Please # to comment.