Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions clang-tools-extra/clang-doc/support/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,20 @@ void getMustacheHtmlFiles(StringRef AssetsPath,
assert(!AssetsPath.empty());
assert(sys::fs::is_directory(AssetsPath));

SmallString<128> DefaultStylesheet =
appendPathPosix(AssetsPath, "clang-doc-mustache.css");
// TODO: Allow users to override default templates with their own. We would
// similarly have to check if a template file already exists in CDCtx.
if (CDCtx.UserStylesheets.empty()) {
SmallString<128> DefaultStylesheet =
appendPathPosix(AssetsPath, "clang-doc-mustache.css");
CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
DefaultStylesheet.c_str());
}

if (CDCtx.JsScripts.empty()) {
SmallString<128> IndexJS = appendPathPosix(AssetsPath, "mustache-index.js");
CDCtx.JsScripts.insert(CDCtx.JsScripts.begin(), IndexJS.c_str());
}

SmallString<128> NamespaceTemplate =
appendPathPosix(AssetsPath, "namespace-template.mustache");
SmallString<128> ClassTemplate =
Expand All @@ -45,11 +57,7 @@ void getMustacheHtmlFiles(StringRef AssetsPath,
appendPathPosix(AssetsPath, "function-template.mustache");
SmallString<128> CommentTemplate =
appendPathPosix(AssetsPath, "comment-template.mustache");
SmallString<128> IndexJS = appendPathPosix(AssetsPath, "mustache-index.js");

CDCtx.JsScripts.insert(CDCtx.JsScripts.begin(), IndexJS.c_str());
CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
DefaultStylesheet.c_str());
CDCtx.MustacheTemplates.insert(
{"namespace-template", NamespaceTemplate.c_str()});
CDCtx.MustacheTemplates.insert({"class-template", ClassTemplate.c_str()});
Expand Down
5 changes: 3 additions & 2 deletions clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ static std::string getExecutablePath(const char *Argv0, void *MainAddr) {
return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
}

// TODO: Rename this, since it only gets custom CSS/JS
static llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
using DirIt = llvm::sys::fs::directory_iterator;
std::error_code FileErr;
Expand Down Expand Up @@ -221,8 +222,8 @@ static llvm::Error getMustacheHtmlFiles(const char *Argv0,
llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath
<< " falling back to default\n";
if (IsDir) {
getMustacheHtmlFiles(UserAssetPath, CDCtx);
return llvm::Error::success();
if (auto Err = getAssetFiles(CDCtx))
return Err;
}
void *MainAddr = (void *)(intptr_t)getExecutablePath;
std::string ClangDocPath = getExecutablePath(Argv0, MainAddr);
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/test/clang-doc/assets.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// RUN: rm -rf %t && mkdir %t
// RUN: clang-doc --format=html --output=%t --asset=%S/Inputs/test-assets --executor=standalone %s --base base_dir
// RUN: clang-doc --format=mustache --output=%t --asset=%S/Inputs/test-assets --executor=standalone %s --base base_dir
// RUN: FileCheck %s -input-file=%t/index.html -check-prefix=INDEX
// RUN: FileCheck %s -input-file=%t/test.css -check-prefix=CSS
// RUN: FileCheck %s -input-file=%t/test.js -check-prefix=JS

// RUN: FileCheck %s -input-file=%t/html/test.css -check-prefix=CSS
// RUN: FileCheck %s -input-file=%t/html/test.js -check-prefix=JS

// INDEX: <!DOCTYPE html>
// INDEX-NEXT: <meta charset="utf-8"/>
// INDEX-NEXT: <title>Index</title>
Expand Down
Loading