[llvm-branch-commits] [clang-tools-extra] [clang-doc] Add helpers for Template config (PR #138062)
Paul Kirth via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Apr 30 17:58:02 PDT 2025
https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/138062
This patch adds or fills in some helper functions related to template
setup when initializing the mustache backend. It was split from #133161.
Co-authored-by: Peter Chou <peter.chou at mail.utoronto.ca>
>From 77bb241f4c6d69e934296a54040e233f990755f1 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Wed, 30 Apr 2025 08:10:20 -0700
Subject: [PATCH] [clang-doc] Add helpers for Template config
This patch adds or fills in some helper functions related to template
setup when initializing the mustache backend. It was split from #133161.
Co-authored-by: Peter Chou <peter.chou at mail.utoronto.ca>
---
.../clang-doc/HTMLMustacheGenerator.cpp | 34 +++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 1288e4fbbc983..593d5d1221f44 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -61,7 +61,41 @@ static std::unique_ptr<MustacheTemplateFile> NamespaceTemplate = nullptr;
static std::unique_ptr<MustacheTemplateFile> RecordTemplate = nullptr;
+static Error
+setupTemplate(std::unique_ptr<MustacheTemplateFile> &Template,
+ StringRef TemplatePath,
+ std::vector<std::pair<StringRef, StringRef>> Partials) {
+ auto T = MustacheTemplateFile::createMustacheFile(TemplatePath);
+ if (auto EC = T.getError())
+ return createFileError("cannot open file", EC);
+ Template = std::move(T.get());
+ for (const auto [Name, FileName] : Partials) {
+ if (auto Err = Template->registerPartialFile(Name, FileName))
+ return Err;
+ }
+ return Error::success();
+}
+
static Error setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) {
+ std::string NamespaceFilePath =
+ CDCtx.MustacheTemplates.lookup("namespace-template");
+ std::string ClassFilePath = CDCtx.MustacheTemplates.lookup("class-template");
+ std::string CommentFilePath =
+ CDCtx.MustacheTemplates.lookup("comments-template");
+ std::string FunctionFilePath =
+ CDCtx.MustacheTemplates.lookup("function-template");
+ std::string EnumFilePath = CDCtx.MustacheTemplates.lookup("enum-template");
+ std::vector<std::pair<StringRef, StringRef>> Partials = {
+ {"Comments", CommentFilePath},
+ {"FunctionPartial", FunctionFilePath},
+ {"EnumPartial", EnumFilePath}};
+
+ if (Error Err = setupTemplate(NamespaceTemplate, NamespaceFilePath, Partials))
+ return Err;
+
+ if (Error Err = setupTemplate(RecordTemplate, ClassFilePath, Partials))
+ return Err;
+
return Error::success();
}
More information about the llvm-branch-commits
mailing list