18#include "llvm/Support/Error.h"
19#include "llvm/Support/Path.h"
22using namespace llvm::json;
23using namespace llvm::mustache;
41 StringRef RelativeRootPath)
override;
44 SmallString<128> RelativeRootPath);
46 StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
53 auto ConvertToNative = [](std::string &&Path) -> std::string {
54 SmallString<128> PathBuf(Path);
55 llvm::sys::path::native(PathBuf);
56 return PathBuf.str().str();
59 std::string NamespaceFilePath =
61 std::string ClassFilePath =
63 std::string CommentFilePath =
65 std::string FunctionFilePath =
67 std::string EnumFilePath =
69 std::string HeadFilePath =
71 std::string NavbarFilePath =
73 std::vector<std::pair<StringRef, StringRef>> Partials = {
74 {
"Comments", CommentFilePath},
75 {
"FunctionPartial", FunctionFilePath},
76 {
"EnumPartial", EnumFilePath},
77 {
"HeadPartial", HeadFilePath},
78 {
"NavbarPartial", NavbarFilePath}};
86 return Error::success();
91 SmallString<128> RelativeRootPath) {
92 V.getAsObject()->insert({
"ProjectName", CDCtx.
ProjectName});
93 json::Value StylesheetArr = Array();
94 sys::path::native(RelativeRootPath, sys::path::Style::posix);
96 auto *SSA = StylesheetArr.getAsArray();
99 SmallString<128> StylesheetPath = RelativeRootPath;
100 sys::path::append(StylesheetPath, sys::path::Style::posix,
101 sys::path::filename(FilePath));
102 SSA->emplace_back(StylesheetPath);
104 V.getAsObject()->insert({
"Stylesheets", StylesheetArr});
106 json::Value ScriptArr = Array();
107 auto *SCA = ScriptArr.getAsArray();
110 SmallString<128> JsPath = RelativeRootPath;
111 sys::path::append(JsPath, sys::path::Style::posix,
112 sys::path::filename(Script));
113 SCA->emplace_back(JsPath);
115 V.getAsObject()->insert({
"Scripts", ScriptArr});
116 return Error::success();
121 StringRef ObjTypeStr,
122 StringRef RelativeRootPath) {
123 if (ObjTypeStr ==
"namespace") {
128 }
else if (ObjTypeStr ==
"record") {
134 return Error::success();
150 return createStringError(inconvertibleErrorCode(),
"unexpected InfoType");
152 return Error::success();
158 if (Error Err =
copyFile(FilePath, ResourcePath))
160 for (
const auto &FilePath : CDCtx.
JsScripts)
161 if (Error Err =
copyFile(FilePath, ResourcePath))
163 return Error::success();
167 StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
175static 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.")
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.