Skip to content

Commit

Permalink
chore: adoc multipage visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Jun 18, 2023
1 parent f7aaad9 commit 118c1b7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion addons/generator/asciidoc/layouts/namespace.adoc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
|===
|Name |Description
{{#each page.members}}
|xref:{{id}}[`{{name}}`] |{{doc.brief}}
|xref:{{id}}.adoc[`{{name}}`] |{{doc.brief}}
{{/each}}
|===
2 changes: 1 addition & 1 deletion addons/generator/asciidoc/partials/type-name.adoc.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{!-- render TypeInfo --}}
{{#if symbol}}
xref:{{id}}[{{name}}]{{else~}}
xref:{{id}}.adoc[{{name}}]{{else~}}
{{name~}}
{{/if~}}
45 changes: 36 additions & 9 deletions source/-adoc/MultiPageVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,74 @@
//

#include "MultiPageVisitor.hpp"
#include <mrdox/Support/Path.hpp>
#include <fstream>

namespace clang {
namespace mrdox {
namespace adoc {

// Launch a task to render the page
template<std::derived_from<Info> Ty>
void
MultiPageVisitor::
renderPage(
auto const& I)
render(
Ty const& I,
Builder& builder)
{
auto pageText = builder(I);
if(! pageText)
throw pageText.getError();

std::string fileName = files::appendPath(
outputPath_, toBase16(I.id) + ".adoc");
std::ofstream os;
try
{
os.open(fileName,
std::ios_base::binary |
std::ios_base::out |
std::ios_base::trunc // | std::ios_base::noreplace
);
os.write(pageText->data(), pageText->size());
}
catch(std::exception const& ex)
{
throw Error("std::ofstream(\"{}\") threw \"{}\"", fileName, ex.what());
}
}

void
MultiPageVisitor::
renderAsync(auto const& I)
{
ex_.async(
[this, &I](Builder& builder)
{
auto pageText = builder(I);
if(! pageText)
throw pageText.getError();
render(I, builder);
});
}

void
MultiPageVisitor::
operator()(NamespaceInfo const& I)
{
renderPage(I);
renderAsync(I);
corpus_.traverse(I, *this);
}

void
MultiPageVisitor::
operator()(RecordInfo const& I)
{
renderPage(I);
renderAsync(I);
corpus_.traverse(I, *this);
}

void
MultiPageVisitor::
operator()(FunctionInfo const& I)
{
renderPage(I);
renderAsync(I);
}

} // adoc
Expand Down
7 changes: 5 additions & 2 deletions source/-adoc/MultiPageVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ class MultiPageVisitor
{
}

template<std::derived_from<Info> Ty>
void render(Ty const& I, Builder&);

void renderAsync(auto const& I);

void operator()(NamespaceInfo const& I);
void operator()(RecordInfo const& I);
void operator()(FunctionInfo const& I);
void operator()(Info const&) {}

void renderPage(auto const& I);
};

} // adoc
Expand Down

0 comments on commit 118c1b7

Please sign in to comment.