clang-tools 22.0.0git
Utils.cpp
Go to the documentation of this file.
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
15using namespace llvm;
16
17SmallString<128> appendPathNative(StringRef Base, StringRef Path) {
18 SmallString<128> Default;
19 sys::path::native(Base, Default);
20 sys::path::append(Default, Path);
21 return Default;
22}
23
24SmallString<128> appendPathPosix(StringRef Base, StringRef Path) {
25 SmallString<128> Default;
26 sys::path::native(Base, Default, sys::path::Style::posix);
27 sys::path::append(Default, Path);
28 return Default;
29}
30
31void getHtmlFiles(StringRef AssetsPath, clang::doc::ClangDocContext &CDCtx) {
32 assert(!AssetsPath.empty());
33 assert(sys::fs::is_directory(AssetsPath));
34
35 // TODO: Allow users to override default templates with their own. We would
36 // similarly have to check if a template file already exists in CDCtx.
37 if (CDCtx.UserStylesheets.empty()) {
38 SmallString<128> DefaultStylesheet =
39 appendPathPosix(AssetsPath, "clang-doc-mustache.css");
40 CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
41 DefaultStylesheet.c_str());
42 }
43
44 if (CDCtx.JsScripts.empty()) {
45 SmallString<128> IndexJS = appendPathPosix(AssetsPath, "mustache-index.js");
46 CDCtx.JsScripts.insert(CDCtx.JsScripts.begin(), IndexJS.c_str());
47 }
48
49 SmallString<128> NamespaceTemplate =
50 appendPathPosix(AssetsPath, "namespace-template.mustache");
51 SmallString<128> ClassTemplate =
52 appendPathPosix(AssetsPath, "class-template.mustache");
53 SmallString<128> EnumTemplate =
54 appendPathPosix(AssetsPath, "enum-template.mustache");
55 SmallString<128> FunctionTemplate =
56 appendPathPosix(AssetsPath, "function-template.mustache");
57 SmallString<128> CommentTemplate =
58 appendPathPosix(AssetsPath, "comment-template.mustache");
59 SmallString<128> HeadTemplate =
60 appendPathPosix(AssetsPath, "head-template.mustache");
61 SmallString<128> NavbarTemplate =
62 appendPathPosix(AssetsPath, "navbar-template.mustache");
63 SmallString<128> IndexTemplate =
64 appendPathPosix(AssetsPath, "index-template.mustache");
65 SmallString<128> AliasTemplate =
66 appendPathPosix(AssetsPath, "alias-template.mustache");
67
68 CDCtx.MustacheTemplates.insert(
69 {"namespace-template", NamespaceTemplate.c_str()});
70 CDCtx.MustacheTemplates.insert({"class-template", ClassTemplate.c_str()});
71 CDCtx.MustacheTemplates.insert({"enum-template", EnumTemplate.c_str()});
72 CDCtx.MustacheTemplates.insert(
73 {"function-template", FunctionTemplate.c_str()});
74 CDCtx.MustacheTemplates.insert({"comment-template", CommentTemplate.c_str()});
75 CDCtx.MustacheTemplates.insert({"head-template", HeadTemplate.c_str()});
76 CDCtx.MustacheTemplates.insert({"navbar-template", NavbarTemplate.c_str()});
77 CDCtx.MustacheTemplates.insert({"index-template", IndexTemplate.c_str()});
78 CDCtx.MustacheTemplates.insert({"alias-template", AliasTemplate.c_str()});
79}
SmallString< 128 > appendPathNative(StringRef Base, StringRef Path)
Definition Utils.cpp:17
void getHtmlFiles(StringRef AssetsPath, clang::doc::ClangDocContext &CDCtx)
Definition Utils.cpp:31
SmallString< 128 > appendPathPosix(StringRef Base, StringRef Path)
Definition Utils.cpp:24
Some operations such as code completion produce a set of candidates.
Definition Generators.h:145
std::vector< std::string > UserStylesheets
llvm::StringMap< std::string > MustacheTemplates
std::vector< std::string > JsScripts