@@ -9,6 +9,7 @@ const Package = @import("Package.zig");
9
9
const Zir = @import ("Zir.zig" );
10
10
const Ref = Zir .Inst .Ref ;
11
11
const log = std .log .scoped (.autodoc );
12
+ const Docgen = @import ("Docgen.zig" );
12
13
13
14
module : * Module ,
14
15
doc_location : Compilation.EmitLoc ,
@@ -266,13 +267,54 @@ pub fn generateZirData(self: *Autodoc) !void {
266
267
try buffer .flush ();
267
268
}
268
269
270
+ output_dir .makeDir ("src-viewer" ) catch | e | switch (e ) {
271
+ error .PathAlreadyExists = > {},
272
+ else = > | err | return err ,
273
+ };
274
+ const html_dir = try output_dir .openDir ("src-viewer" , .{});
275
+
276
+ var files_iterator = self .files .iterator ();
277
+
278
+ while (files_iterator .next ()) | entry | {
279
+ const new_html_path = entry .key_ptr .* .sub_file_path ;
280
+
281
+ const html_file = try createFromPath (html_dir , new_html_path );
282
+ defer html_file .close ();
283
+ var buffer = std .io .bufferedWriter (html_file .writer ());
284
+
285
+ const out = buffer .writer ();
286
+
287
+ try Docgen .genHtml (self .module .gpa , entry .key_ptr .* , out );
288
+ try buffer .flush ();
289
+ }
290
+
269
291
// copy main.js, index.html
270
292
var docs_dir = try self .module .comp .zig_lib_directory .handle .openDir ("docs" , .{});
271
293
defer docs_dir .close ();
272
294
try docs_dir .copyFile ("main.js" , output_dir , "main.js" , .{});
273
295
try docs_dir .copyFile ("index.html" , output_dir , "index.html" , .{});
274
296
}
275
297
298
+ fn createFromPath (base_dir : std.fs.Dir , path : []const u8 ) ! std.fs.File {
299
+ var path_tokens = std .mem .tokenize (u8 , path , std .fs .path .sep_str );
300
+ var dir = base_dir ;
301
+ while (path_tokens .next ()) | toc | {
302
+ if (path_tokens .peek () != null ) {
303
+ dir .makeDir (toc ) catch | e | switch (e ) {
304
+ error .PathAlreadyExists = > {},
305
+ else = > | err | return err ,
306
+ };
307
+ dir = try dir .openDir (toc , .{});
308
+ } else {
309
+ return dir .createFile (toc , .{}) catch | e | switch (e ) {
310
+ error .PathAlreadyExists = > try dir .openFile (toc , .{}),
311
+ else = > | e | return e ,
312
+ };
313
+ }
314
+ }
315
+ return error .EmptyPath ;
316
+ }
317
+
276
318
/// Represents a chain of scopes, used to resolve decl references to the
277
319
/// corresponding entry in `self.decls`.
278
320
const Scope = struct {
0 commit comments