@@ -70,18 +70,113 @@ 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
+ }
76
117
return Error::success ();
77
118
}
78
119
120
+ static json::Value extractValue (const NamespaceInfo &I,
121
+ const ClangDocContext &CDCtx) {
122
+ Object NamespaceValue = Object ();
123
+ return NamespaceValue;
124
+ }
125
+
126
+ static json::Value extractValue (const RecordInfo &I,
127
+ const ClangDocContext &CDCtx) {
128
+ Object RecordValue = Object ();
129
+ return RecordValue;
130
+ }
131
+
132
+ static Error setupTemplateValue (const ClangDocContext &CDCtx, json::Value &V,
133
+ Info *I) {
134
+ return createStringError (inconvertibleErrorCode (),
135
+ " setupTemplateValue is unimplemented" );
136
+ }
137
+
79
138
Error MustacheHTMLGenerator::generateDocForInfo (Info *I, raw_ostream &OS,
80
139
const ClangDocContext &CDCtx) {
140
+ switch (I->IT ) {
141
+ case InfoType::IT_namespace: {
142
+ json::Value V =
143
+ extractValue (*static_cast <clang::doc::NamespaceInfo *>(I), CDCtx);
144
+ if (auto Err = setupTemplateValue (CDCtx, V, I))
145
+ return Err;
146
+ NamespaceTemplate->render (V, OS);
147
+ break ;
148
+ }
149
+ case InfoType::IT_record: {
150
+ json::Value V =
151
+ extractValue (*static_cast <clang::doc::RecordInfo *>(I), CDCtx);
152
+ if (auto Err = setupTemplateValue (CDCtx, V, I))
153
+ return Err;
154
+ // Serialize the JSON value to the output stream in a readable format.
155
+ RecordTemplate->render (V, OS);
156
+ break ;
157
+ }
158
+ case InfoType::IT_enum:
159
+ OS << " IT_enum\n " ;
160
+ break ;
161
+ case InfoType::IT_function:
162
+ OS << " IT_Function\n " ;
163
+ break ;
164
+ case InfoType::IT_typedef:
165
+ OS << " IT_typedef\n " ;
166
+ break ;
167
+ case InfoType::IT_default:
168
+ return createStringError (inconvertibleErrorCode (), " unexpected InfoType" );
169
+ }
81
170
return Error::success ();
82
171
}
83
172
84
173
Error MustacheHTMLGenerator::createResources (ClangDocContext &CDCtx) {
174
+ for (const auto &FilePath : CDCtx.UserStylesheets )
175
+ if (Error Err = copyFile (FilePath, CDCtx.OutDirectory ))
176
+ return Err;
177
+ for (const auto &FilePath : CDCtx.JsScripts )
178
+ if (Error Err = copyFile (FilePath, CDCtx.OutDirectory ))
179
+ return Err;
85
180
return Error::success ();
86
181
}
87
182
0 commit comments