Skip to content

Commit 174283d

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 1566219 commit 174283d

File tree

2 files changed

+433
-9
lines changed

2 files changed

+433
-9
lines changed

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

Lines changed: 23 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,27 @@ 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::Style::posix,
439+
sys::path::filename(FilePath));
440+
StylesheetArr.getAsArray()->emplace_back(StylesheetPath);
441+
}
442+
V.getAsObject()->insert({"Stylesheets", StylesheetArr});
443+
444+
json::Value ScriptArr = Array();
445+
for (auto Script : CDCtx.JsScripts) {
446+
SmallString<128> JsPath = RelativePath;
447+
sys::path::append(JsPath, sys::path::filename(Script));
448+
ScriptArr.getAsArray()->emplace_back(JsPath);
449+
}
450+
V.getAsObject()->insert({"Scripts", ScriptArr});
451+
return Error::success();
433452
}
434453

435454
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -440,6 +459,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
440459
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
441460
if (auto Err = setupTemplateValue(CDCtx, V, I))
442461
return Err;
462+
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
443463
NamespaceTemplate->render(V, OS);
444464
break;
445465
}

0 commit comments

Comments
 (0)