Skip to content

[clang-doc] add tags to Mustache namespace template #142045

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

Merged
merged 4 commits into from
Jun 4, 2025

Conversation

evelez7
Copy link
Member

@evelez7 evelez7 commented May 29, 2025

namespace-template.mustache only rendered placeholder text. Enum and record tags were added to the template. Now, we can render an index.html for the global namespace and other namespaces.

Added tests and deleted some of the disabled unit tests.

namespace-template.mustache only rendered placeholder text. Enum and
record tags were added to the template. Now, we can
render an index.html for the global namespace and other namespaces.

Added tests and deleted some of the disabled unit tests.
@evelez7 evelez7 requested review from ilovepi and petrhosek May 29, 2025 21:51
@evelez7
Copy link
Member Author

evelez7 commented May 29, 2025

I cannibalized the tags from class-template.mustache. By happy accident, I realized that there is an extractScopeChildren so enums can be generated, which means the placeholders in generateDocForInfo (the OS << "IT_enum\n" part) can be filled in if the logic is moved to their own functions. In fact, they might not be needed since everything is scoped. 🤯

I plan on adding things incrementally (global functions, etc) for the sake of smaller PRs.

// CHECK-NEXT: <tr>
// CHECK-NEXT: <th>Name</th>
// CHECK-NEXT: <th>Value</th>
// CHECK: </tr>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the tag not line up becacuse you deleted -NEXT or do we emit it with really strange indentation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I forgot to adjust the spacing after deleting -NEXT.

We do emit a lot of strange indentation though. I turned these into CHECKS because the RUN commands are emitted as comments for every enum value. The div and table tags for those comments are a bit jumbled. The enum Color above on line 37 is also my own indentation, it's way further back in source.

@ilovepi
Copy link
Contributor

ilovepi commented May 30, 2025

I cannibalized the tags from class-template.mustache. By happy accident, I realized that there is an extractScopeChildren so enums can be generated, which means the placeholders in generateDocForInfo (the OS << "IT_enum\n" part) can be filled in if the logic is moved to their own functions. In fact, they might not be needed since everything is scoped. 🤯

Well... that's a surprise. It'd be really great to get @PeterChou1's take on all this, but we haven't heard from him in a couple months now.

I plan on adding things incrementally (global functions, etc) for the sake of smaller PRs.

Sounds good!

Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We may want to tweak the template some more, but we should get the test in place now and follow up if we want to change the aesthetics later.

@evelez7 evelez7 marked this pull request as ready for review May 30, 2025 21:54
@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Erick Velez (evelez7)

Changes

namespace-template.mustache only rendered placeholder text. Enum and record tags were added to the template. Now, we can render an index.html for the global namespace and other namespaces.

Added tests and deleted some of the disabled unit tests.


Full diff: https://github.com/llvm/llvm-project/pull/142045.diff

4 Files Affected:

  • (modified) clang-tools-extra/clang-doc/assets/namespace-template.mustache (+66-10)
  • (added) clang-tools-extra/test/clang-doc/mustache-index.cpp (+75)
  • (added) clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp (+13)
  • (modified) clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp (-67)
diff --git a/clang-tools-extra/clang-doc/assets/namespace-template.mustache b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
index 12dc93069d1cf..1a44ed3c3cccd 100644
--- a/clang-tools-extra/clang-doc/assets/namespace-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
@@ -23,23 +23,79 @@
     </head>
     <body>
         <nav class="navbar">
-            Navbar
+            <div class="navbar__container">
+                {{#ProjectName}}
+                <div class="navbar__logo">
+                    {{ProjectName}}
+                </div>
+                {{/ProjectName}}
+                <div class="navbar__menu">
+                    <ul class="navbar__links">
+                        <li class="navbar__item">
+                            <a href="/" class="navbar__link">Namespace</a>
+                        </li>
+                        <li class="navbar__item">
+                            <a href="/" class="navbar__link">Class</a>
+                        </li>
+                    </ul>
+                </div>
+            </div>
         </nav>
         <main>
             <div class="container">
                 <div class="sidebar">
-                        Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
-                        sed do eiusmod tempor incididunt ut labore et dolore magna 
-                        aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco 
-                        laboris nisi ut aliquip ex ea commodo consequat. 
-                        Duis aute irure dolor in reprehenderit in voluptate velit esse 
-                        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat 
-                        cupidatat non proident, sunt in culpa qui officia deserunt mollit 
-                        anim id est laborum
+                    <h2>{{RecordType}} {{Name}}</h2>
+                    <ul>
+                        {{#Enums}}
+                        <li class="sidebar-section">
+                            <a class="sidebar-item" href="#Enums">Enums</a>
+                        </li>
+                        <ul>
+                            {{#Obj}}
+                            <li class="sidebar-item-container">
+                                <a class="sidebar-item" href="#{{ID}}">{{EnumName}}</a>
+                            </li>
+                            {{/Obj}}
+                        </ul>
+                        {{/Enums}}
+                        {{#Record}}
+                        <li class="sidebar-section">
+                            <a class="sidebar-item" href="#Classes">Inner Classes</a>
+                        </li>
+                        <ul>
+                            {{#Links}}
+                            <li class="sidebar-item-container">
+                                <a class="sidebar-item" href="#{{ID}}">{{Name}}</a>
+                            </li>
+                            {{/Links}}
+                        </ul>
+                        {{/Record}}
+                    </ul>
                 </div>
                 <div class="resizer" id="resizer"></div>
                 <div class="content">
-                    Content
+                    {{#Enums}}
+                    <section id="Enums" class="section-container">
+                        <h2>Enumerations</h2>
+                        <div>
+                            {{#Obj}}
+                            {{>EnumPartial}}
+                            {{/Obj}}
+                        </div>
+                    </section>
+                    {{/Enums}}
+                    {{#Record}}
+                    <section id="Classes" class="section-container">
+                        <h2>Inner Classes</h2>
+                        <ul class="class-container">
+                        {{#Links}}
+                            <li id="{{ID}}" style="max-height: 40px;">
+                                <a href="{{Link}}"><pre><code class="language-cpp code-clang-doc" >class {{Name}}</code></pre></a>
+                            </li>
+                        {{/Links}}
+                        </ul>
+                    </section>
+                    {{/Record}}
                 </div>
             </div>
         </main>
diff --git a/clang-tools-extra/test/clang-doc/mustache-index.cpp b/clang-tools-extra/test/clang-doc/mustache-index.cpp
new file mode 100644
index 0000000000000..cad4cc8b6931a
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/mustache-index.cpp
@@ -0,0 +1,75 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --format=mustache --output=%t --executor=standalone %s 
+// RUN: FileCheck %s < %t/GlobalNamespace/index.html
+
+enum Color {
+  RED,
+  BLUE,
+  GREEN
+};
+
+class Foo;
+
+// CHECK:       <li class="sidebar-section">
+// CHECK-NEXT:      <a class="sidebar-item" href="#Enums">Enums</a>
+// CHECK-NEXT:  </li>
+// CHECK-NEXT:  <ul>
+// CHECK-NEXT:      <li class="sidebar-item-container">
+// CHECK-NEXT:          <a class="sidebar-item" href="#{{[0-9A-F]*}}">enum Color</a>
+// CHECK-NEXT:      </li>
+// CHECK-NEXT:  </ul>
+// CHECK:           <li class="sidebar-section">
+// CHECK-NEXT:          <a class="sidebar-item" href="#Classes">Inner Classes</a>
+// CHECK-NEXT:      </li>
+// CHECK-NEXT:  <ul>
+// CHECK-NEXT:      <li class="sidebar-item-container">
+// CHECK-NEXT:          <a class="sidebar-item" href="#{{[0-9A-F]*}}">Foo</a>
+// CHECK-NEXT:      </li>
+// CHECK-NEXT:  </ul>
+
+// CHECK:       <section id="Enums" class="section-container">
+// CHECK-NEXT:      <h2>Enumerations</h2>
+// CHECK-NEXT:      <div>
+// CHECK-NEXT:          <div id="{{[0-9A-F]*}}" class="delimiter-container">
+// CHECK-NEXT:              <div>
+// CHECK-NEXT:                  <pre>
+// CHECK-NEXT:                      <code class="language-cpp code-clang-doc">
+// CHECK-NEXT:                          enum Color
+// CHECK-NEXT:                      </code>
+// CHECK-NEXT:                  </pre>
+// CHECK-NEXT:              </div>
+// CHECK-NEXT:              <table class="table-wrapper">
+// CHECK-NEXT:                  <tbody>
+// CHECK-NEXT:                  <tr>
+// CHECK-NEXT:                      <th>Name</th>
+// CHECK-NEXT:                      <th>Value</th>
+// CHECK:                       </tr>
+// CHECK-NEXT:                      <tr>
+// CHECK-NEXT:                          <td>RED</td>
+// CHECK-NEXT:                          <td>0</td>
+// CHECK:                           </tr>
+// CHECK-NEXT:                      <tr>
+// CHECK-NEXT:                          <td>BLUE</td>
+// CHECK-NEXT:                          <td>1</td>
+// CHECK:                           </tr>
+// CHECK-NEXT:                      <tr>
+// CHECK-NEXT:                          <td>GREEN</td>
+// CHECK-NEXT:                          <td>2</td>
+// CHECK:                           </tr>
+// CHECK-NEXT:                  </tbody>
+// CHECK-NEXT:              </table>
+// CHECK-NEXT:              <div>
+// CHECK-NEXT:                  Defined at line 5 of file {{.*}}mustache-index.cpp
+// CHECK-NEXT:              </div>
+// CHECK-NEXT:          </div>
+// CHECK-NEXT:      </div>
+// CHECK-NEXT:  </section>
+
+// CHECK:       <section id="Classes" class="section-container">
+// CHECK-NEXT:      <h2>Inner Classes</h2>
+// CHECK-NEXT:      <ul class="class-container">
+// CHECK-NEXT:          <li id="{{[0-9A-F]*}}" style="max-height: 40px;">
+// CHECK-NEXT:              <a href="Foo.html"><pre><code class="language-cpp code-clang-doc" >class Foo</code></pre></a>
+// CHECK-NEXT:          </li>
+// CHECK-NEXT:      </ul>
+// CHECK-NEXT:  </section>
diff --git a/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp b/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp
new file mode 100644
index 0000000000000..ec29b2449169b
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --format=mustache --output=%t --executor=standalone %s 
+// RUN: FileCheck %s < %t/MyNamespace/index.html
+
+namespace MyNamespace {
+  class Foo;
+}
+
+// CHECK:       <ul class="class-container">
+// CHECK-NEXT:    <li id="{{[0-9A-F]*}}" style="max-height: 40px;">
+// CHECK-NEXT:        <a href="Foo.html"><pre><code class="language-cpp code-clang-doc" >class Foo</code></pre></a>
+// CHECK-NEXT:    </li>
+// CHECK-NEXT: </ul>
diff --git a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
index 95acd363a958e..32b0846a02dba 100644
--- a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
@@ -87,29 +87,6 @@ TEST(HTMLMustacheGeneratorTest, createResources) {
   }
 }
 
-TEST(HTMLMustacheGeneratorTest, generateDocs) {
-  auto G = getHTMLMustacheGenerator();
-  assert(G && "Could not find HTMLMustacheGenerator");
-  ClangDocContext CDCtx = getClangDocContext();
-
-  unittest::TempDir RootTestDirectory("generateDocsTest", /*Unique=*/true);
-  CDCtx.OutDirectory = RootTestDirectory.path();
-
-#if ENABLE_LOCAL_TEST
-  // FIXME: We can't read files during unit tests. Migrate to lit once
-  // tool support lands.
-  getMustacheHtmlFiles(CLANG_DOC_TEST_ASSET_DIR, CDCtx);
-
-  EXPECT_THAT_ERROR(G->generateDocs(RootTestDirectory.path(), {}, CDCtx),
-                    Succeeded())
-      << "Failed to generate docs.";
-#else
-  EXPECT_THAT_ERROR(G->generateDocs(RootTestDirectory.path(), {}, CDCtx),
-                    Failed())
-      << "Failed to generate docs.";
-#endif
-}
-
 TEST(HTMLGeneratorTest, emitFunctionHTML) {
 #if ENABLE_LOCAL_TEST
   auto G = getHTMLMustacheGenerator();
@@ -160,50 +137,6 @@ TEST(HTMLGeneratorTest, emitFunctionHTML) {
 #endif
 }
 
-TEST(HTMLMustacheGeneratorTest, emitEnumHTML) {
-#if ENABLE_LOCAL_TEST
-  auto G = getHTMLMustacheGenerator();
-  assert(G && "Could not find HTMLMustacheGenerator");
-  ClangDocContext CDCtx = getClangDocContext();
-  std::string Buffer;
-  llvm::raw_string_ostream Actual(Buffer);
-
-  unittest::TempDir RootTestDirectory("emitEnumHTML",
-                                      /*Unique=*/true);
-  CDCtx.OutDirectory = RootTestDirectory.path();
-
-  getMustacheHtmlFiles(CLANG_DOC_TEST_ASSET_DIR, CDCtx);
-
-  // FIXME: This is a terrible hack, since we can't initialize the templates
-  // directly. We'll need to update the interfaces so that we can call
-  // SetupTemplateFiles() from outsize of HTMLMustacheGenerator.cpp
-  EXPECT_THAT_ERROR(G->generateDocs(RootTestDirectory.path(), {}, CDCtx),
-                    Succeeded())
-      << "Failed to generate docs.";
-
-  CDCtx.RepositoryUrl = "http://www.repository.com";
-
-  EnumInfo I;
-  I.Name = "e";
-  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
-
-  I.DefLoc = Location(10, 10, "test.cpp", true);
-  I.Loc.emplace_back(12, 12, "test.cpp");
-
-  I.Members.emplace_back("X");
-  I.Scoped = true;
-
-  auto Err = G->generateDocForInfo(&I, Actual, CDCtx);
-  assert(!Err);
-
-  std::string Expected = R"raw(IT_enum
-)raw";
-
-  // FIXME: Enums are not handled yet.
-  EXPECT_EQ(Expected, Actual.str());
-#endif
-}
-
 TEST(HTMLMustacheGeneratorTest, emitCommentHTML) {
 #if ENABLE_LOCAL_TEST
   auto G = getHTMLMustacheGenerator();

@PeterChou1
Copy link
Contributor

PeterChou1 commented May 31, 2025

I cannibalized the tags from class-template.mustache. By happy accident, I realized that there is an extractScopeChildren so enums can be generated, which means the placeholders in generateDocForInfo (the OS << "IT_enum\n" part) can be filled in if the logic is moved to their own functions. In fact, they might not be needed since everything is scoped. 🤯

Well... that's a surprise. It'd be really great to get @PeterChou1's take on all this, but we haven't heard from him in a couple months now.

I plan on adding things incrementally (global functions, etc) for the sake of smaller PRs.

Sounds good!

Hi, sorry for the lack response. Unfortunately my father passed away recently so I was dealing with the logistics. I'm more than happy to deal with any issues that arises from my previous code

@ilovepi
Copy link
Contributor

ilovepi commented Jun 3, 2025

Hi, sorry for the lack response. Unfortunately my father passed away recently so I was dealing with the logistics. I'm more than happy to deal with any issues that arises from my previous code

@PeterChou1 I'm sorry to hear about your circumstances. That's truly a hard thing. LLVM is a volunteer project, though and there is no onus or expectation for you to contribute. If you have the time and want to, we'll welcome your help, but don't feel obligated to do anything.

@evelez7 evelez7 merged commit 8a905ba into llvm:main Jun 4, 2025
14 checks passed
@evelez7 evelez7 deleted the clang-doc-mustache-index branch June 7, 2025 02:10
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
namespace-template.mustache only rendered placeholder text. Enum and
record tags were added to the template. Now, we can render an index.html
for the global namespace and other namespaces.

Added tests and deleted some of the disabled unit tests.
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
namespace-template.mustache only rendered placeholder text. Enum and
record tags were added to the template. Now, we can render an index.html
for the global namespace and other namespaces.

Added tests and deleted some of the disabled unit tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants