Skip to content

Commit 5c5d241

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 d832772 commit 5c5d241

File tree

2 files changed

+428
-8
lines changed

2 files changed

+428
-8
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,26 @@ static json::Value extractValue(const RecordInfo &I,
406406

407407
static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
408408
Info *I) {
409-
return createStringError(inconvertibleErrorCode(),
410-
"setupTemplateValue is unimplemented");
409+
V.getAsObject()->insert({"ProjectName", CDCtx.ProjectName});
410+
json::Value StylesheetArr = Array();
411+
auto InfoPath = I->getRelativeFilePath("");
412+
SmallString<128> RelativePath = computeRelativePath("", InfoPath);
413+
for (const auto &FilePath : CDCtx.UserStylesheets) {
414+
SmallString<128> StylesheetPath = RelativePath;
415+
sys::path::append(StylesheetPath, sys::path::filename(FilePath));
416+
sys::path::native(StylesheetPath, sys::path::Style::posix);
417+
StylesheetArr.getAsArray()->emplace_back(StylesheetPath);
418+
}
419+
V.getAsObject()->insert({"Stylesheets", StylesheetArr});
420+
421+
json::Value ScriptArr = Array();
422+
for (auto Script : CDCtx.JsScripts) {
423+
SmallString<128> JsPath = RelativePath;
424+
sys::path::append(JsPath, sys::path::filename(Script));
425+
ScriptArr.getAsArray()->emplace_back(JsPath);
426+
}
427+
V.getAsObject()->insert({"Scripts", ScriptArr});
428+
return Error::success();
411429
}
412430

413431
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
@@ -418,6 +436,7 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
418436
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
419437
if (auto Err = setupTemplateValue(CDCtx, V, I))
420438
return Err;
439+
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
421440
NamespaceTemplate->render(V, OS);
422441
break;
423442
}

0 commit comments

Comments
 (0)