Skip to content

Commit 8607c3a

Browse files
committed
feat(HandlebarsGenerator): overloads partial
1 parent b11bdd6 commit 8607c3a

File tree

96 files changed

+147
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+147
-62
lines changed

share/mrdocs/addons/generator/adoc/layouts/wrapper.adoc.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
= Reference
44
:mrdocs:
55
{{/unless}}
6+
67
{{! Content generated with index.hbs }}
78
{{{contents}}}
89

share/mrdocs/addons/generator/adoc/layouts/index-overload-set.adoc.hbs renamed to share/mrdocs/addons/generator/adoc/partials/symbols/overloads.adoc.hbs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{{! A page when the symbol type is "overloads" }}
2-
[#{{symbol.anchor}}]
2+
[#{{{symbol.anchor}}}]
33
={{#unless @root.config.multipage}}={{/unless}} {{#if symbol.name}}{{>types/nested-name-specifier symbol=symbol.parent includeNamespace=true}}{{symbol.name}}{{else}}Unnamed overload set{{/if}}
44

5-
{{#if symbol.members.[0]}}
5+
{{#if symbol}}
66

7-
{{#if symbol.members.[0].doc.brief}}
7+
{{#if symbol.doc.brief}}
88

9-
{{{symbol.members.[0].doc.brief}}}
9+
{{{symbol.doc.brief}}}
1010

1111
{{/if}}
1212

@@ -20,10 +20,10 @@
2020
----
2121
{{/each}}
2222
23-
{{#if symbol.members.[0].doc.description}}
23+
{{#if symbol.doc.description}}
2424
=={{#unless @root.config.multipage}}={{/unless}} Description
2525
26-
{{{symbol.members.[0].doc.description}}}
26+
{{{symbol.doc.description}}}
2727
{{/if}}
2828
2929
{{#with (flattenUnique symbol.members "doc.exceptions" "exception") as |allExceptions|}}
@@ -41,10 +41,10 @@
4141
{{/if}}
4242
{{/with}}
4343
44-
{{#if symbol.members.[0].doc.returns}}
44+
{{#if symbol.doc.returns}}
4545
=={{#unless @root.config.multipage}}={{/unless}} Return Value
4646
47-
{{{symbol.members.[0].doc.returns}}}
47+
{{{symbol.doc.returns}}}
4848
4949
{{/if}}
5050
@@ -63,28 +63,28 @@
6363
{{/if}}
6464
{{/with}}
6565
66-
{{#if symbol.members.[0].doc.preconditions}}
66+
{{#if symbol.doc.preconditions}}
6767
=={{#unless @root.config.multipage}}={{/unless}} Preconditions
6868
69-
{{#each symbol.members.[0].doc.preconditions}}
69+
{{#each symbol.doc.preconditions}}
7070
{{{.}}}
7171
{{/each}}
7272
7373
{{/if}}
7474
75-
{{#if symbol.members.[0].doc.postconditions}}
75+
{{#if symbol.doc.postconditions}}
7676
=={{#unless @root.config.multipage}}={{/unless}} Postconditions
7777
78-
{{#each symbol.members.[0].doc.postconditions}}
78+
{{#each symbol.doc.postconditions}}
7979
{{{.}}}
8080
{{/each}}
8181
8282
{{/if}}
8383
84-
{{#if symbol.members.[0].doc.see}}
84+
{{#if symbol.doc.see}}
8585
=={{#unless @root.config.multipage}}={{/unless}} See Also
8686
87-
{{#each symbol.members.[0].doc.see}}
87+
{{#each symbol.doc.see}}
8888
{{{.}}}
8989
{{/each}}
9090
{{/if}}

share/mrdocs/addons/generator/common/partials/types/info-member.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{#>markup/a href=(relativize url)}}{{#>markup/code}}{{>types/declarator-id . nolink=true}}{{/markup/code}}{{/markup/a}} {{>types/special-name-suffix .}}
55
{{~/markup/td}}
66
{{#>markup/td~}}
7-
{{#if (ne kind "overload")~}}
7+
{{#if (ne kind "overloads")~}}
88
{{{~doc.brief}}}
99
{{else~}}
1010
{{#each (unique (pluck (pluck members "doc") "brief"))~}}

share/mrdocs/addons/generator/common/partials/types/special-name-suffix.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
the symbol is a special member (e.g., constructor,
44
destructor, overload, variant member)
55
}}
6-
{{#if (eq kind "overload")~}}
6+
{{#if (eq kind "overloads")~}}
77
{{>types/special-name-suffix (front members)}}
88
{{~else if (eq kind "function")~}}
99
{{#if (eq class "constructor")}}

src/lib/Gen/adoc/AdocGenerator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ escape(OutputRef& os, std::string_view str) const
4141
if (needsEscape)
4242
{
4343
os << "pass:[";
44+
// Using passthroughs to pass content (without substitutions) can couple
45+
// your content to a specific output format, such as HTML.
46+
// In these cases, you should use conditional preprocessor directives
47+
// to route passthrough content for different output formats based on
48+
// the current backend.
49+
// If we would like to couple passthrough content to an HTML format,
50+
// then we'd use `HTMLEscape(os, str)` instead of `os << str`.
4451
os << str;
4552
os << "]";
4653
}

src/lib/Gen/hbs/Builder.cpp

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,11 @@ relativize_fn(dom::Value to0, dom::Value from0, dom::Value options)
148148
}
149149
if (!relativePath.starts_with("../") && !relativePath.starts_with("./"))
150150
{
151+
// relative hrefs needs to explicitly include "./" so that
152+
// they are always treated as relative to the current page
151153
relativePath = "./" + relativePath;
152154
}
153155
relativePath += hash;
154-
155-
if (relativePath == "/boost.adoc")
156-
{
157-
relativePath = "." + relativePath;
158-
}
159156
return relativePath;
160157
}
161158

@@ -239,27 +236,18 @@ Builder(
239236
helpers::registerContainerHelpers(hbs_);
240237
hbs_.registerHelper("relativize", dom::makeInvocable(relativize_fn));
241238

242-
// load templates
243-
exp = forEachFile(layoutDir(), false,
244-
[&](std::string_view pathName) -> Expected<void>
245-
{
246-
// Get template relative path
247-
std::filesystem::path relPath = pathName;
248-
relPath = relPath.lexically_relative(layoutDir());
249-
250-
// Skip non-handlebars files
251-
MRDOCS_CHECK_OR(relPath.extension() == ".hbs", {});
252-
253-
// Load template contents
254-
MRDOCS_TRY(std::string text, files::getFileText(pathName));
255-
256-
// Register template
257-
this->templates_.emplace(relPath.generic_string(), text);
258-
return {};
259-
});
260-
if (!exp)
239+
// Load layout templates
240+
std::string indexTemplateFilename = fmt::format("index.{}.hbs", domCorpus.fileExtension);
241+
std::string wrapperTemplateFilename = fmt::format("wrapper.{}.hbs", domCorpus.fileExtension);
242+
for (std::string const& filename : {indexTemplateFilename, wrapperTemplateFilename})
261243
{
262-
exp.error().Throw();
244+
std::string pathName = files::appendPath(layoutDir(), filename);
245+
Expected<std::string> text = files::getFileText(pathName);
246+
if (!text)
247+
{
248+
text.error().Throw();
249+
}
250+
templates_.emplace(filename, text.value());
263251
}
264252
}
265253

@@ -334,10 +322,7 @@ Expected<void>
334322
Builder::
335323
operator()(std::ostream& os, T const& I)
336324
{
337-
std::string const templateFile =
338-
std::derived_from<T, Info> ?
339-
fmt::format("index.{}.hbs", domCorpus.fileExtension) :
340-
fmt::format("index-overload-set.{}.hbs", domCorpus.fileExtension);
325+
std::string const templateFile = fmt::format("index.{}.hbs", domCorpus.fileExtension);
341326
dom::Object ctx = createContext(I);
342327

343328
auto& config = domCorpus->config;

src/lib/Metadata/Overloads.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@ tag_invoke(
3434
* The `overloads` value is a temporary reference created
3535
* by the `Info` tag_invoke.
3636
*/
37-
v = dom::Object({
38-
// KRYSTIAN FIXME: need a better way to generate IDs
39-
{ "id", fmt::format("{}-{}", toBase16(overloads.Parent), overloads.Name) },
40-
{ "kind", "overload"},
41-
{ "name", overloads.Name },
42-
{ "members", dom::LazyArray(overloads.Members, domCorpus) },
43-
{ "namespace", dom::LazyArray(overloads.Namespace, domCorpus) },
44-
{ "parent", domCorpus->get(overloads.Parent) }
45-
});
37+
dom::Object res;
38+
res.set("id", fmt::format("{}-{}", toBase16(overloads.Parent), overloads.Name));
39+
res.set("kind", "overloads");
40+
res.set("name", overloads.Name);
41+
res.set("members", dom::LazyArray(overloads.Members, domCorpus));
42+
res.set("namespace", dom::LazyArray(overloads.Namespace, domCorpus));
43+
res.set("parent", domCorpus->get(overloads.Parent));
44+
dom::Value firstM = domCorpus->get(overloads.Members.front());
45+
if (firstM.isObject() && firstM.get("doc").isObject())
46+
{
47+
res.set("doc", firstM.get("doc"));
48+
}
49+
v = res;
4650
}
4751

4852
} // mrdocs

test-files/golden-tests/alias-template.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
= Reference
22
:mrdocs:
3+
34
[#index]
45
== Global namespace
56

test-files/golden-tests/attributes_1.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
= Reference
22
:mrdocs:
3+
34
[#index]
45
== Global namespace
56

0 commit comments

Comments
 (0)