Skip to content

Commit 123ef0d

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 2d4c5cc commit 123ef0d

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

388388
maybeInsertLocation(I.DefLoc, CDCtx, RecordValue);
389389

390-
StringRef BasePath = I.getRelativeFilePath("");
390+
SmallString<64> BasePath = I.getRelativeFilePath("");
391391
extractScopeChildren(I.Children, RecordValue, BasePath, CDCtx);
392392
json::Value PublicMembers = Array();
393393
json::Array &PubMemberRef = *PublicMembers.getAsArray();
@@ -421,8 +421,26 @@ static json::Value extractValue(const RecordInfo &I,
421421

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

428446
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -433,6 +451,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
433451
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
434452
if (auto Err = setupTemplateValue(CDCtx, V, I))
435453
return Err;
454+
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
436455
NamespaceTemplate->render(V, OS);
437456
break;
438457
}

0 commit comments

Comments
 (0)