Skip to content

Commit 5e56a52

Browse files
ilovepiPeterChou1
andcommitted
[clang-doc] Implement setupTemplateValue for HTMLMustacheGenerator
This patch implements the business logic for setupTemplateValue, which was split from #133161. The implementation configures the relative path relationships between the various HTML components, and prepares them prior to their use in the generator. Co-authored-by: Peter Chou <[email protected]>
1 parent 6880c2f commit 5e56a52

File tree

2 files changed

+434
-9
lines changed

2 files changed

+434
-9
lines changed

clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static json::Value extractValue(const RecordInfo &I,
397397

398398
maybeInsertLocation(I.DefLoc, CDCtx, RecordValue);
399399

400-
StringRef BasePath = I.getRelativeFilePath("");
400+
SmallString<64> BasePath = I.getRelativeFilePath("");
401401
extractScopeChildren(I.Children, RecordValue, BasePath, CDCtx);
402402
json::Value PublicMembers = Array();
403403
json::Array &PubMemberRef = *PublicMembers.getAsArray();
@@ -431,8 +431,28 @@ static json::Value extractValue(const RecordInfo &I,
431431

432432
static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
433433
Info *I) {
434-
return createStringError(inconvertibleErrorCode(),
435-
"setupTemplateValue is unimplemented");
434+
V.getAsObject()->insert({"ProjectName", CDCtx.ProjectName});
435+
json::Value StylesheetArr = Array();
436+
auto InfoPath = I->getRelativeFilePath("");
437+
SmallString<128> RelativePath = computeRelativePath("", InfoPath);
438+
sys::path::native(RelativePath, sys::path::Style::posix);
439+
for (const auto &FilePath : CDCtx.UserStylesheets) {
440+
SmallString<128> StylesheetPath = RelativePath;
441+
sys::path::append(StylesheetPath, sys::path::Style::posix,
442+
sys::path::filename(FilePath));
443+
StylesheetArr.getAsArray()->emplace_back(StylesheetPath);
444+
}
445+
V.getAsObject()->insert({"Stylesheets", StylesheetArr});
446+
447+
json::Value ScriptArr = Array();
448+
for (auto Script : CDCtx.JsScripts) {
449+
SmallString<128> JsPath = RelativePath;
450+
sys::path::append(JsPath, sys::path::Style::posix,
451+
sys::path::filename(Script));
452+
ScriptArr.getAsArray()->emplace_back(JsPath);
453+
}
454+
V.getAsObject()->insert({"Scripts", ScriptArr});
455+
return Error::success();
436456
}
437457

438458
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -443,6 +463,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
443463
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
444464
if (auto Err = setupTemplateValue(CDCtx, V, I))
445465
return Err;
466+
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
446467
NamespaceTemplate->render(V, OS);
447468
break;
448469
}

0 commit comments

Comments
 (0)