| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "Utils.h" |
| 10 | #include "llvm/ADT/SmallString.h" |
| 11 | #include "llvm/ADT/StringRef.h" |
| 12 | #include "llvm/Support/FileSystem.h" |
| 13 | #include "llvm/Support/Path.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | |
| 17 | SmallString<128> appendPathNative(StringRef Base, StringRef Path) { |
| 18 | SmallString<128> Default; |
| 19 | sys::path::native(path: Base, result&: Default); |
| 20 | sys::path::append(path&: Default, a: Path); |
| 21 | return Default; |
| 22 | } |
| 23 | |
| 24 | SmallString<128> appendPathPosix(StringRef Base, StringRef Path) { |
| 25 | SmallString<128> Default; |
| 26 | sys::path::native(path: Base, result&: Default, style: sys::path::Style::posix); |
| 27 | sys::path::append(path&: Default, a: Path); |
| 28 | return Default; |
| 29 | } |
| 30 | |
| 31 | void getMustacheHtmlFiles(StringRef AssetsPath, |
| 32 | clang::doc::ClangDocContext &CDCtx) { |
| 33 | assert(!AssetsPath.empty()); |
| 34 | assert(sys::fs::is_directory(AssetsPath)); |
| 35 | |
| 36 | SmallString<128> DefaultStylesheet = |
| 37 | appendPathPosix(Base: AssetsPath, Path: "clang-doc-mustache.css" ); |
| 38 | SmallString<128> NamespaceTemplate = |
| 39 | appendPathPosix(Base: AssetsPath, Path: "namespace-template.mustache" ); |
| 40 | SmallString<128> ClassTemplate = |
| 41 | appendPathPosix(Base: AssetsPath, Path: "class-template.mustache" ); |
| 42 | SmallString<128> EnumTemplate = |
| 43 | appendPathPosix(Base: AssetsPath, Path: "enum-template.mustache" ); |
| 44 | SmallString<128> FunctionTemplate = |
| 45 | appendPathPosix(Base: AssetsPath, Path: "function-template.mustache" ); |
| 46 | SmallString<128> = |
| 47 | appendPathPosix(Base: AssetsPath, Path: "comment-template.mustache" ); |
| 48 | SmallString<128> IndexJS = appendPathPosix(Base: AssetsPath, Path: "mustache-index.js" ); |
| 49 | |
| 50 | CDCtx.JsScripts.insert(position: CDCtx.JsScripts.begin(), x: IndexJS.c_str()); |
| 51 | CDCtx.UserStylesheets.insert(position: CDCtx.UserStylesheets.begin(), |
| 52 | x: DefaultStylesheet.c_str()); |
| 53 | CDCtx.MustacheTemplates.insert( |
| 54 | KV: {"namespace-template" , NamespaceTemplate.c_str()}); |
| 55 | CDCtx.MustacheTemplates.insert(KV: {"class-template" , ClassTemplate.c_str()}); |
| 56 | CDCtx.MustacheTemplates.insert(KV: {"enum-template" , EnumTemplate.c_str()}); |
| 57 | CDCtx.MustacheTemplates.insert( |
| 58 | KV: {"function-template" , FunctionTemplate.c_str()}); |
| 59 | CDCtx.MustacheTemplates.insert(KV: {"comment-template" , CommentTemplate.c_str()}); |
| 60 | } |
| 61 | |