Skip to content

Commit 603c1b6

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 c97f7af commit 603c1b6

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
@@ -398,7 +398,7 @@ static json::Value extractValue(const RecordInfo &I,
398398

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

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

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

439459
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -444,6 +464,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
444464
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
445465
if (auto Err = setupTemplateValue(CDCtx, V, I))
446466
return Err;
467+
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
447468
NamespaceTemplate->render(V, OS);
448469
break;
449470
}

0 commit comments

Comments
 (0)