Skip to content

Commit e8840f3

Browse files
authored
feat: overload folding on a single page
fix #647
1 parent 999ea4f commit e8840f3

File tree

2 files changed

+197
-5
lines changed

2 files changed

+197
-5
lines changed

share/mrdocs/addons/generator/asciidoc/layouts/overload-set.adoc.hbs

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,91 @@
33

44
= {{#if symbol.name}}{{>nested-name-specifier symbol=symbol.parent includeNamespace=true}}{{symbol.name}}{{else}}Unnamed overload set{{/if}}
55

6-
== Members
6+
{{#if symbol.members.[0]}}
7+
8+
{{#if symbol.members.[0].doc.brief}}
79

8-
{{#each symbol.members as | member |}}
10+
{{symbol.members.[0].doc.brief}}
11+
12+
{{/if}}
913

10-
{{member.doc.brief}}
14+
== Synopsis
15+
16+
{{#each symbol.members as | member |}}
1117

1218
[source,cpp,subs="verbatim,macros,-callouts"]
1319
----
1420
{{> (concat 'signature' '/' (lookup member 'kind')) symbol=member link=member}};
15-
xref:{{ref}}[pass:c,q,m[*_» more..._*]]
1621
----
22+
{{/each}}
23+
24+
{{#if symbol.members.[0].doc.description}}
25+
== Description
26+
27+
{{symbol.members.[0].doc.description}}
28+
{{/if}}
29+
30+
{{#with (flattenUnique symbol.members "doc.exceptions" "exception") as |allExceptions|}}
31+
{{#if (ne (len allExceptions) 0)}}
32+
== Exceptions
33+
34+
|===
35+
| Name | Thrown on
36+
37+
{{#each allExceptions as |exception|}}
38+
| `{{exception.exception}}`
39+
| {{exception.description}}
40+
{{/each}}
41+
|===
42+
{{/if}}
43+
{{/with}}
44+
45+
{{#if symbol.members.[0].doc.returns}}
46+
== Return Value
47+
48+
{{symbol.members.[0].doc.returns}}
49+
50+
{{/if}}
51+
52+
{{#with (flattenUnique symbol.members "doc.params" "name") as |allParams|}}
53+
{{#if (ne (len allParams) 0)}}
54+
== Parameters
55+
56+
|===
57+
| Name | Description {{! TODO: | Type? }}
58+
59+
{{#each allParams as |param|}}
60+
| *{{param.name}}*
61+
| {{param.description}}
62+
{{/each}}
63+
|===
64+
{{/if}}
65+
{{/with}}
66+
67+
{{#if symbol.members.[0].doc.preconditions}}
68+
== Preconditions
69+
70+
{{#each symbol.members.[0].doc.preconditions}}
71+
{{.}}
72+
{{/each}}
73+
74+
{{/if}}
75+
76+
{{#if symbol.members.[0].doc.postconditions}}
77+
== Postconditions
78+
79+
{{#each symbol.members.[0].doc.postconditions}}
80+
{{.}}
81+
{{/each}}
82+
83+
{{/if}}
84+
85+
{{#if symbol.members.[0].doc.see}}
86+
== See Also
87+
88+
{{#each symbol.members.[0].doc.see}}
89+
{{.}}
90+
{{/each}}
91+
{{/if}}
1792
18-
{{/each}}
93+
{{/if}}

src/lib/Support/Handlebars.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5695,6 +5695,39 @@ registerStringHelpers(Handlebars& hbs)
56955695
}));
56965696
}
56975697

5698+
std::vector<std::string>
5699+
parseKeyPath(std::string const& keyPath)
5700+
{
5701+
std::vector<std::string> keys;
5702+
std::istringstream iss(keyPath);
5703+
std::string token;
5704+
5705+
while (std::getline(iss, token, '.'))
5706+
{
5707+
keys.push_back(token);
5708+
}
5709+
5710+
return keys;
5711+
}
5712+
5713+
dom::Value
5714+
getNestedValue(dom::Value const& obj, std::vector<std::string> const& keys)
5715+
{
5716+
dom::Value current = obj;
5717+
for (auto const& key : keys)
5718+
{
5719+
if (current.isObject() && current.getObject().exists(key))
5720+
{
5721+
current = current.getObject().get(key);
5722+
}
5723+
else
5724+
{
5725+
return dom::Value();
5726+
}
5727+
}
5728+
return current;
5729+
}
5730+
56985731
void
56995732
registerContainerHelpers(Handlebars& hbs)
57005733
{
@@ -6405,6 +6438,90 @@ registerContainerHelpers(Handlebars& hbs)
64056438
}));
64066439

64076440
hbs.registerHelper("concat", dom::makeInvocable(concat_fn));
6441+
6442+
static auto flatten_fn = dom::makeInvocable([](dom::Value const& collection, dom::Value const& key) -> dom::Value
6443+
{
6444+
dom::Array result;
6445+
6446+
if (!collection.isArray())
6447+
{
6448+
return result;
6449+
}
6450+
6451+
std::string const keyPath(key.getString());
6452+
auto const keys = parseKeyPath(keyPath);
6453+
6454+
auto const& arr = collection.getArray();
6455+
for (auto const& item : arr)
6456+
{
6457+
dom::Value const innerCollection = getNestedValue(item, keys);
6458+
if (innerCollection.isArray())
6459+
{
6460+
auto const& innerArray = innerCollection.getArray();
6461+
for (auto const& innerItem : innerArray)
6462+
{
6463+
result.emplace_back(innerItem);
6464+
}
6465+
}
6466+
}
6467+
6468+
return result;
6469+
});
6470+
6471+
hbs.registerHelper("flatten", flatten_fn);
6472+
6473+
static auto flattenUnique_fn = dom::makeInvocable([](dom::Value const& collection, dom::Value const& key, dom::Value const& uniqueKey) -> dom::Value
6474+
{
6475+
dom::Array result;
6476+
std::unordered_set<std::string> seen;
6477+
6478+
if (!collection.isArray())
6479+
{
6480+
return result;
6481+
}
6482+
6483+
if (key.empty() || uniqueKey.empty())
6484+
{
6485+
return result;
6486+
}
6487+
6488+
if (!key.isString() || !uniqueKey.isString())
6489+
{
6490+
return result;
6491+
}
6492+
6493+
std::string const keyPath(key.getString());
6494+
auto const keys = parseKeyPath(keyPath);
6495+
std::string const uniqueKeyPath(uniqueKey.getString());
6496+
auto const uniqueKeys = parseKeyPath(uniqueKeyPath);
6497+
6498+
auto const& arr = collection.getArray();
6499+
for (auto const& item : arr)
6500+
{
6501+
dom::Value const innerCollection = getNestedValue(item, keys);
6502+
if (innerCollection.isArray())
6503+
{
6504+
auto const& innerArray = innerCollection.getArray();
6505+
for (auto const& innerItem : innerArray)
6506+
{
6507+
dom::Value const uniqueValue = getNestedValue(innerItem, uniqueKeys);
6508+
if (uniqueValue.isString())
6509+
{
6510+
std::string uniqueStr(uniqueValue.getString());
6511+
if (seen.find(uniqueStr) == seen.end())
6512+
{
6513+
seen.insert(uniqueStr);
6514+
result.emplace_back(innerItem);
6515+
}
6516+
}
6517+
}
6518+
}
6519+
}
6520+
6521+
return result;
6522+
});
6523+
6524+
hbs.registerHelper("flattenUnique", flattenUnique_fn);
64086525
}
64096526

64106527
} // helpers

0 commit comments

Comments
 (0)