Skip to content

Allow a custom postprocessor for FilterDocs #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions source/ddox/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ int ddoxMain(string[] args)
return 1;
}

int cmdGenerateHtml(string[] args)
int cmdGenerateHtml(string[] args, GeneratorSettings gensettings = new GeneratorSettings())
{
GeneratorSettings gensettings;
Package pack;
if( auto ret = setupGeneratorInput(args, gensettings, pack) )
return ret;
Expand All @@ -57,14 +56,13 @@ int cmdGenerateHtml(string[] args)
return 0;
}

int cmdServeHtml(string[] args)
int cmdServeHtml(string[] args, GeneratorSettings gensettings = new GeneratorSettings())
{
string[] webfiledirs;
getopt(args,
config.passThrough,
"web-file-dir", &webfiledirs);

GeneratorSettings gensettings;
Package pack;
if( auto ret = setupGeneratorInput(args, gensettings, pack) )
return ret;
Expand All @@ -84,11 +82,9 @@ int cmdServeHtml(string[] args)
return runEventLoop();
}

int cmdServeTest(string[] args)
int cmdServeTest(string[] args, GeneratorSettings gensettings = new GeneratorSettings(), DdoxSettings docsettings = new DdoxSettings())
{
string[] webfiledirs;
auto docsettings = new DdoxSettings;
auto gensettings = new GeneratorSettings;

auto pack = parseD(args[2 .. $]);

Expand All @@ -111,7 +107,9 @@ int cmdServeTest(string[] args)

int setupGeneratorInput(ref string[] args, out GeneratorSettings gensettings, out Package pack)
{
gensettings = new GeneratorSettings;
if (gensettings is null)
gensettings = new GeneratorSettings;

auto docsettings = new DdoxSettings;

string[] macrofiles;
Expand Down Expand Up @@ -153,7 +151,7 @@ int setupGeneratorInput(ref string[] args, out GeneratorSettings gensettings, ou
return 0;
}

int cmdFilterDocs(string[] args)
int cmdFilterDocs(string[] args, GeneratorSettings generatorSettings = new GeneratorSettings())
{
string[] excluded, included;
Protection minprot = Protection.Private;
Expand Down Expand Up @@ -225,6 +223,8 @@ int cmdFilterDocs(string[] args)
if (last_decl["comment"].opt!string.empty) {
writefln("Warning: Cannot add documented unit test %s to %s, which is not documented.", name, last_decl["name"].opt!string);
} else {
if (generatorSettings.postUnittestSourceCode !is null)
source = generatorSettings.postUnittestSourceCode(source);
last_decl["comment"] ~= format("Example:\n%s$(DDOX_UNITTEST_HEADER %s)\n---\n%s\n---\n$(DDOX_UNITTEST_FOOTER %s)\n", comment.strip, name, source, name);
}
} catch (Exception e) {
Expand Down
6 changes: 6 additions & 0 deletions source/ddox/settings.d
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ class GeneratorSettings {
@property bool lowerCase() const { return fileNameStyle == MethodStyle.lowerCase; }
deprecated("Use fileNameStyle = MethodStyle.lowerCase instead.")
@property void lowerCase(bool v) { fileNameStyle = MethodStyle.lowerCase; }

/**
Custom delegate that is called after the unittest source code has been parsed
Can be used to inject custom logic like an assert/writeln transformation.
*/
string delegate(string) postUnittestSourceCode;
}