Skip to content

Commit fa0b1fb

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 c7f6fb8 commit fa0b1fb

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

392392
maybeInsertLocation(I.DefLoc, CDCtx, RecordValue);
393393

394-
StringRef BasePath = I.getRelativeFilePath("");
394+
SmallString<64> BasePath = I.getRelativeFilePath("");
395395
extractScopeChildren(I.Children, RecordValue, BasePath, CDCtx);
396396
json::Value PublicMembers = Array();
397397
json::Array &PubMemberRef = *PublicMembers.getAsArray();
@@ -425,8 +425,28 @@ static json::Value extractValue(const RecordInfo &I,
425425

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

432452
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -437,6 +457,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
437457
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
438458
if (auto Err = setupTemplateValue(CDCtx, V, I))
439459
return Err;
460+
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
440461
NamespaceTemplate->render(V, OS);
441462
break;
442463
}

0 commit comments

Comments
 (0)