Skip to content

Commit aecb686

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 505a3ec commit aecb686

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

384384
maybeInsertLocation(I.DefLoc, CDCtx, RecordValue);
385385

386-
StringRef BasePath = I.getRelativeFilePath("");
386+
SmallString<64> BasePath = I.getRelativeFilePath("");
387387
extractScopeChildren(I.Children, RecordValue, BasePath, CDCtx);
388388
json::Value PublicMembers = Array();
389389
json::Array &PubMemberRef = *PublicMembers.getAsArray();
@@ -417,8 +417,26 @@ static json::Value extractValue(const RecordInfo &I,
417417

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

424442
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -429,6 +447,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
429447
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
430448
if (auto Err = setupTemplateValue(CDCtx, V, I))
431449
return Err;
450+
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
432451
NamespaceTemplate->render(V, OS);
433452
break;
434453
}

0 commit comments

Comments
 (0)