-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[clang-doc] Add helpers for Template config #138062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: users/ilovepi/clang-doc-mustache-generators
Are you sure you want to change the base?
[clang-doc] Add helpers for Template config #138062
Conversation
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 <[email protected]>
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-clang-tools-extra Author: Paul Kirth (ilovepi) ChangesThis patch adds or fills in some helper functions related to template Co-authored-by: Peter Chou <[email protected]> Full diff: https://github.com/llvm/llvm-project/pull/138062.diff 1 Files Affected:
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();
}
|
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 [email protected]