18#include "llvm/Support/Error.h"
19#include "llvm/Support/Path.h"
22using namespace llvm::json;
23using namespace llvm::mustache;
43 StringRef RelativeRootPath)
override;
46 SmallString<128> RelativeRootPath);
48 StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
55 auto ConvertToNative = [](std::string &&Path) -> std::string {
56 SmallString<128> PathBuf(Path);
57 llvm::sys::path::native(PathBuf);
58 return PathBuf.str().str();
61 std::string NamespaceFilePath =
63 std::string ClassFilePath =
65 std::string IndexFilePath =
67 std::string CommentFilePath =
69 std::string FunctionFilePath =
71 std::string EnumFilePath =
73 std::string HeadFilePath =
75 std::string NavbarFilePath =
77 std::vector<std::pair<StringRef, StringRef>> Partials = {
78 {
"Comments", CommentFilePath},
79 {
"FunctionPartial", FunctionFilePath},
80 {
"EnumPartial", EnumFilePath},
81 {
"HeadPartial", HeadFilePath},
82 {
"NavbarPartial", NavbarFilePath}};
93 return Error::success();
98 SmallString<128> RelativeRootPath) {
99 V.getAsObject()->insert({
"ProjectName", CDCtx.
ProjectName});
100 json::Value StylesheetArr = Array();
101 sys::path::native(RelativeRootPath, sys::path::Style::posix);
103 auto *SSA = StylesheetArr.getAsArray();
106 SmallString<128> StylesheetPath = RelativeRootPath;
107 sys::path::append(StylesheetPath, sys::path::Style::posix,
108 sys::path::filename(FilePath));
109 SSA->emplace_back(StylesheetPath);
111 V.getAsObject()->insert({
"Stylesheets", StylesheetArr});
113 json::Value ScriptArr = Array();
114 auto *SCA = ScriptArr.getAsArray();
117 SmallString<128> JsPath = RelativeRootPath;
118 sys::path::append(JsPath, sys::path::Style::posix,
119 sys::path::filename(Script));
120 SCA->emplace_back(JsPath);
122 V.getAsObject()->insert({
"Scripts", ScriptArr});
123 if (RelativeRootPath.empty()) {
124 RelativeRootPath =
"";
126 sys::path::append(RelativeRootPath,
"/index.html");
127 sys::path::native(RelativeRootPath, sys::path::Style::posix);
129 V.getAsObject()->insert({
"Homepage", RelativeRootPath});
130 return Error::success();
135 StringRef ObjTypeStr,
136 StringRef RelativeRootPath) {
137 if (ObjTypeStr ==
"namespace") {
142 }
else if (ObjTypeStr ==
"record") {
147 }
else if (ObjTypeStr ==
"index") {
153 return Error::success();
169 return createStringError(inconvertibleErrorCode(),
"unexpected InfoType");
171 return Error::success();
177 if (Error Err =
copyFile(FilePath, ResourcePath))
179 for (
const auto &FilePath : CDCtx.
JsScripts)
180 if (Error Err =
copyFile(FilePath, ResourcePath))
182 return Error::success();
186 StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
194static GeneratorRegistry::Add<HTMLGenerator>
Error generateDocForJSON(json::Value &JSON, raw_fd_ostream &OS, const ClangDocContext &CDCtx, StringRef ObjTypeStr, StringRef RelativeRootPath) override
static const char * Format
Error createResources(ClangDocContext &CDCtx) override
Error generateDocForInfo(Info *I, raw_ostream &OS, const ClangDocContext &CDCtx) override
Error setupTemplateFiles(const ClangDocContext &CDCtx) override
Initializes the template files from disk and calls setupTemplate to register partials.
Error setupTemplateResources(const ClangDocContext &CDCtx, json::Value &V, SmallString< 128 > RelativeRootPath)
llvm::Error generateDocumentation(StringRef RootDir, llvm::StringMap< std::unique_ptr< doc::Info > > Infos, const ClangDocContext &CDCtx, std::string DirName) override
llvm::Error copyFile(llvm::StringRef FilePath, llvm::StringRef OutDirectory)
static std::unique_ptr< MustacheTemplateFile > RecordTemplate
static GeneratorRegistry::Add< JSONGenerator > JSON(JSONGenerator::Format, "Generator for JSON output.")
static std::unique_ptr< MustacheTemplateFile > IndexTemplate
volatile int HTMLGeneratorAnchorSource
static std::unique_ptr< MustacheTemplateFile > NamespaceTemplate
static GeneratorRegistry::Add< HTMLGenerator > HTML(HTMLGenerator::Format, "Generator for mustache HTML output.")
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
std::vector< std::string > UserStylesheets
llvm::StringMap< std::string > MustacheTemplates
std::vector< std::string > JsScripts
llvm::Error generateDocumentation(StringRef RootDir, llvm::StringMap< std::unique_ptr< doc::Info > > Infos, const clang::doc::ClangDocContext &CDCtx, std::string DirName) override
The main orchestrator for Mustache-based documentation.
llvm::Error setupTemplate(std::unique_ptr< MustacheTemplateFile > &Template, StringRef TemplatePath, std::vector< std::pair< StringRef, StringRef > > Partials)
Registers partials to templates.