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