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