Skip to content

Commit 977de18

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 4945933 commit 977de18

File tree

2 files changed

+432
-9
lines changed

2 files changed

+432
-9
lines changed

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

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

395395
maybeInsertLocation(I.DefLoc, CDCtx, RecordValue);
396396

397-
StringRef BasePath = I.getRelativeFilePath("");
397+
SmallString<64> BasePath = I.getRelativeFilePath("");
398398
extractScopeChildren(I.Children, RecordValue, BasePath, CDCtx);
399399
json::Value PublicMembers = Array();
400400
json::Array &PubMemberRef = *PublicMembers.getAsArray();
@@ -428,8 +428,26 @@ static json::Value extractValue(const RecordInfo &I,
428428

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

435453
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -440,6 +458,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
440458
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
441459
if (auto Err = setupTemplateValue(CDCtx, V, I))
442460
return Err;
461+
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
443462
NamespaceTemplate->render(V, OS);
444463
break;
445464
}

0 commit comments

Comments
 (0)