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 llvm::StringMap<doc::Info *> Infos,
50 std::string DirName)
override;
56 auto ConvertToNative = [](std::string &&Path) -> std::string {
57 SmallString<128> PathBuf(Path);
58 llvm::sys::path::native(PathBuf);
59 return PathBuf.str().str();
62 std::string NamespaceFilePath =
64 std::string ClassFilePath =
66 std::string IndexFilePath =
68 std::string CommentFilePath =
70 std::string FunctionFilePath =
72 std::string EnumFilePath =
74 std::string HeadFilePath =
76 std::string NavbarFilePath =
78 std::string AliasFilePath =
80 std::vector<std::pair<StringRef, StringRef>> Partials = {
81 {
"Comments", CommentFilePath}, {
"FunctionPartial", FunctionFilePath},
82 {
"EnumPartial", EnumFilePath}, {
"HeadPartial", HeadFilePath},
83 {
"NavbarPartial", NavbarFilePath}, {
"AliasPartial", AliasFilePath}};
94 return Error::success();
99 SmallString<128> RelativeRootPath) {
100 V.getAsObject()->insert({
"ProjectName", CDCtx.
ProjectName});
101 json::Value StylesheetArr = Array();
102 sys::path::native(RelativeRootPath, sys::path::Style::posix);
104 auto *SSA = StylesheetArr.getAsArray();
107 SmallString<128> StylesheetPath = RelativeRootPath;
108 sys::path::append(StylesheetPath, sys::path::Style::posix,
109 sys::path::filename(FilePath));
110 SSA->emplace_back(StylesheetPath);
112 V.getAsObject()->insert({
"Stylesheets", StylesheetArr});
114 json::Value ScriptArr = Array();
115 auto *SCA = ScriptArr.getAsArray();
118 SmallString<128> JsPath = RelativeRootPath;
119 sys::path::append(JsPath, sys::path::Style::posix,
120 sys::path::filename(Script));
121 SCA->emplace_back(JsPath);
123 V.getAsObject()->insert({
"Scripts", ScriptArr});
124 if (RelativeRootPath.empty()) {
125 RelativeRootPath =
"";
127 sys::path::append(RelativeRootPath,
"/index.html");
128 sys::path::native(RelativeRootPath, sys::path::Style::posix);
130 V.getAsObject()->insert({
"Homepage", RelativeRootPath});
131 return Error::success();
136 StringRef ObjTypeStr,
137 StringRef RelativeRootPath) {
138 if (ObjTypeStr ==
"namespace") {
143 }
else if (ObjTypeStr ==
"record") {
148 }
else if (ObjTypeStr ==
"index") {
154 return Error::success();
170 return createStringError(inconvertibleErrorCode(),
"unexpected InfoType");
172 return Error::success();
178 if (Error Err =
copyFile(FilePath, ResourcePath))
180 for (
const auto &FilePath : CDCtx.
JsScripts)
181 if (Error Err =
copyFile(FilePath, ResourcePath))
183 return Error::success();
187 llvm::StringMap<doc::Info *> Infos,
189 std::string DirName) {
196static GeneratorRegistry::Add<HTMLGenerator>
This file contains file I/O utility functions used in clang-doc, such as creating directories and wri...
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
llvm::Error generateDocumentation(StringRef RootDir, llvm::StringMap< doc::Info * > Infos, const ClangDocContext &CDCtx, std::string DirName) 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 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< 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.