@@ -56,17 +56,119 @@ class MustacheTemplateFile : public Template {
56
56
57
57
MustacheTemplateFile (StringRef TemplateStr) : Template(TemplateStr) {}
58
58
};
59
+
60
+ static std::unique_ptr<MustacheTemplateFile> NamespaceTemplate = nullptr ;
61
+
62
+ static std::unique_ptr<MustacheTemplateFile> RecordTemplate = nullptr ;
63
+
64
+ static Error setupTemplateFiles (const clang::doc::ClangDocContext &CDCtx) {
65
+ return Error::success ();
66
+ }
67
+
59
68
Error MustacheHTMLGenerator::generateDocs (
60
69
StringRef RootDir, StringMap<std::unique_ptr<doc::Info>> Infos,
61
70
const clang::doc::ClangDocContext &CDCtx) {
71
+ if (auto Err = setupTemplateFiles (CDCtx))
72
+ return Err;
73
+ // Track which directories we already tried to create.
74
+ StringSet<> CreatedDirs;
75
+ // Collect all output by file name and create the necessary directories.
76
+ StringMap<std::vector<doc::Info *>> FileToInfos;
77
+ for (const auto &Group : Infos) {
78
+ doc::Info *Info = Group.getValue ().get ();
79
+
80
+ SmallString<128 > Path;
81
+ sys::path::native (RootDir, Path);
82
+ sys::path::append (Path, Info->getRelativeFilePath (" " ));
83
+ if (!CreatedDirs.contains (Path)) {
84
+ if (std::error_code Err = sys::fs::create_directories (Path);
85
+ Err != std::error_code ())
86
+ return createStringError (Err, " Failed to create directory '%s'." ,
87
+ Path.c_str ());
88
+ CreatedDirs.insert (Path);
89
+ }
90
+
91
+ sys::path::append (Path, Info->getFileBaseName () + " .html" );
92
+ FileToInfos[Path].push_back (Info);
93
+ }
94
+
95
+ for (const auto &Group : FileToInfos) {
96
+ std::error_code FileErr;
97
+ raw_fd_ostream InfoOS (Group.getKey (), FileErr, sys::fs::OF_None);
98
+ if (FileErr)
99
+ return createStringError (FileErr, " Error opening file '%s'" ,
100
+ Group.getKey ().data ());
101
+
102
+ for (const auto &Info : Group.getValue ()) {
103
+ if (Error Err = generateDocForInfo (Info, InfoOS, CDCtx))
104
+ return Err;
105
+ }
106
+ }
62
107
return Error::success ();
63
108
}
109
+
110
+ static json::Value extractValue (const NamespaceInfo &I,
111
+ const ClangDocContext &CDCtx) {
112
+ Object NamespaceValue = Object ();
113
+ return NamespaceValue;
114
+ }
115
+
116
+ static json::Value extractValue (const RecordInfo &I,
117
+ const ClangDocContext &CDCtx) {
118
+ Object RecordValue = Object ();
119
+ return RecordValue;
120
+ }
121
+
122
+ static void setupTemplateValue (const ClangDocContext &CDCtx, json::Value &V,
123
+ Info *I) {}
124
+
64
125
Error MustacheHTMLGenerator::generateDocForInfo (Info *I, raw_ostream &OS,
65
126
const ClangDocContext &CDCtx) {
127
+ switch (I->IT ) {
128
+ case InfoType::IT_namespace: {
129
+ json::Value V =
130
+ extractValue (*static_cast <clang::doc::NamespaceInfo *>(I), CDCtx);
131
+ setupTemplateValue (CDCtx, V, I);
132
+ NamespaceTemplate->render (V, OS);
133
+ break ;
134
+ }
135
+ case InfoType::IT_record: {
136
+ json::Value V =
137
+ extractValue (*static_cast <clang::doc::RecordInfo *>(I), CDCtx);
138
+ setupTemplateValue (CDCtx, V, I);
139
+ // Serialize the JSON value to the output stream in a readable format.
140
+ outs () << " Visit: " << I->Name << " \n " ;
141
+ // outs() << formatv("{0:2}", V) << "\n";
142
+ RecordTemplate->render (V, outs ());
143
+ break ;
144
+ }
145
+ case InfoType::IT_enum:
146
+ outs () << " IT_enum\n " ;
147
+ break ;
148
+ case InfoType::IT_function:
149
+ outs () << " IT_Function\n " ;
150
+ break ;
151
+ case InfoType::IT_typedef:
152
+ outs () << " IT_typedef\n " ;
153
+ break ;
154
+ case InfoType::IT_default:
155
+ return createStringError (inconvertibleErrorCode (), " unexpected InfoType" );
156
+ }
66
157
return Error::success ();
67
158
}
159
+
68
160
Error MustacheHTMLGenerator::createResources (ClangDocContext &CDCtx) {
69
161
Error Err = Error::success ();
162
+ for (const auto &FilePath : CDCtx.UserStylesheets ) {
163
+ Err = copyFile (FilePath, CDCtx.OutDirectory );
164
+ if (Err)
165
+ return Err;
166
+ }
167
+ for (const auto &FilePath : CDCtx.JsScripts ) {
168
+ Err = copyFile (FilePath, CDCtx.OutDirectory );
169
+ if (Err)
170
+ return Err;
171
+ }
70
172
return Error::success ();
71
173
}
72
174
0 commit comments