Skip to content

Commit bda0fff

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 0e6ab7d commit bda0fff

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

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

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

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

433453
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -438,6 +458,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
438458
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
439459
if (auto Err = setupTemplateValue(CDCtx, V, I))
440460
return Err;
461+
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
441462
NamespaceTemplate->render(V, OS);
442463
break;
443464
}

0 commit comments

Comments
 (0)