[clang-tools-extra] [clang-doc] Add helpers for Template config (PR #138062)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Mon May 19 13:28:02 PDT 2025
================
@@ -74,7 +75,51 @@ 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 (Error Err = T.takeError())
+ return Err;
+ 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) {
+ // Template files need to use the native path when they're opened,
+ // but have to be used in Posix style when used in HTML.
+ auto ConvertToNative = [](std::string &&Path) -> std::string {
+ SmallString<128> PathBuf(Path);
+ llvm::sys::path::native(PathBuf);
+ return PathBuf.str().str();
+ };
+
+ std::string NamespaceFilePath =
+ ConvertToNative(CDCtx.MustacheTemplates.lookup("namespace-template"));
+ std::string ClassFilePath =
+ ConvertToNative(CDCtx.MustacheTemplates.lookup("class-template"));
+ std::string CommentFilePath =
----------------
ilovepi wrote:
No, that's a fair thing to point out. probably the template names should be spelled `comment-template` instead and everything made consistent with that. That's what we do for `function`, `class` and `namespace`. I can take a look at renaming those in the stack.
https://github.com/llvm/llvm-project/pull/138062
More information about the cfe-commits
mailing list