Skip to content

Commit b1022c3

Browse files
committed
[clang-doc] Create a partial for HTML <head> sections
The <head> sections of the existing partials are already identical, so creating a partial will help reduce lines in the templates. Now changes to <head> sections can easily propogate and can easily be added to future HTML pages.
1 parent d785463 commit b1022c3

File tree

6 files changed

+24
-29
lines changed

6 files changed

+24
-29
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ Error HTMLGenerator::setupTemplateFiles(const ClangDocContext &CDCtx) {
6666
ConvertToNative(CDCtx.MustacheTemplates.lookup("function-template"));
6767
std::string EnumFilePath =
6868
ConvertToNative(CDCtx.MustacheTemplates.lookup("enum-template"));
69+
std::string HeadFilePath =
70+
ConvertToNative(CDCtx.MustacheTemplates.lookup("head-template"));
6971
std::vector<std::pair<StringRef, StringRef>> Partials = {
7072
{"Comments", CommentFilePath},
7173
{"FunctionPartial", FunctionFilePath},
72-
{"EnumPartial", EnumFilePath}};
74+
{"EnumPartial", EnumFilePath},
75+
{"HeadPartial", HeadFilePath}};
7376

7477
if (Error Err = setupTemplate(NamespaceTemplate, NamespaceFilePath, Partials))
7578
return Err;

clang-tools-extra/clang-doc/assets/class-template.mustache

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,7 @@
77
}}
88
<!DOCTYPE html>
99
<html lang="en-US">
10-
<head>
11-
<meta charset="utf-8"/>
12-
<title>{{Name}}</title>
13-
{{#Stylesheets}}
14-
<link rel="stylesheet" type="text/css" href="{{.}}"/>
15-
{{/Stylesheets}}
16-
{{#Scripts}}
17-
<script src="{{.}}"></script>
18-
{{/Scripts}}
19-
{{! Highlight.js dependency for syntax highlighting }}
20-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
21-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
22-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/cpp.min.js"></script>
23-
</head>
10+
{{>HeadPartial}}
2411
<body>
2512
<nav class="navbar">
2613
<div class="navbar__container">
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<head>
2+
<meta charset="utf-8"/>
3+
<title>{{Name}}</title>
4+
{{#Stylesheets}}
5+
<link rel="stylesheet" type="text/css" href="{{.}}"/>
6+
{{/Stylesheets}}
7+
{{#Scripts}}
8+
<script src="{{.}}"></script>
9+
{{/Scripts}}
10+
{{! Highlight.js dependency for syntax highlighting }}
11+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
12+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
13+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/cpp.min.js"></script>
14+
</head>

clang-tools-extra/clang-doc/assets/namespace-template.mustache

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,7 @@
77
}}
88
<!DOCTYPE html>
99
<html lang="en-US">
10-
<head>
11-
<meta charset="utf-8"/>
12-
<title>{{NamespaceTitle}}</title>
13-
{{#Stylesheets}}
14-
<link rel="stylesheet" type="text/css" href="{{.}}"/>
15-
{{/Stylesheets}}
16-
{{#Scripts}}
17-
<script src="{{.}}"></script>
18-
{{/Scripts}}
19-
{{! Highlight.js dependency for syntax highlighting }}
20-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
21-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
22-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/cpp.min.js"></script>
23-
</head>
10+
{{>HeadPartial}}
2411
<body>
2512
<nav class="navbar">
2613
<div class="navbar__container">

clang-tools-extra/clang-doc/support/Utils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ void getHtmlFiles(StringRef AssetsPath, clang::doc::ClangDocContext &CDCtx) {
5656
appendPathPosix(AssetsPath, "function-template.mustache");
5757
SmallString<128> CommentTemplate =
5858
appendPathPosix(AssetsPath, "comment-template.mustache");
59+
SmallString<128> HeadTemplate =
60+
appendPathPosix(AssetsPath, "head-template.mustache");
5961

6062
CDCtx.MustacheTemplates.insert(
6163
{"namespace-template", NamespaceTemplate.c_str()});
@@ -64,4 +66,5 @@ void getHtmlFiles(StringRef AssetsPath, clang::doc::ClangDocContext &CDCtx) {
6466
CDCtx.MustacheTemplates.insert(
6567
{"function-template", FunctionTemplate.c_str()});
6668
CDCtx.MustacheTemplates.insert({"comment-template", CommentTemplate.c_str()});
69+
CDCtx.MustacheTemplates.insert({"head-template", HeadTemplate.c_str()});
6770
}

clang-tools-extra/clang-doc/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set(assets
3131
function-template.mustache
3232
namespace-template.mustache
3333
template.mustache
34+
head-template.mustache
3435
)
3536

3637
set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")

0 commit comments

Comments
 (0)