From a8428a896e2df8ca58b944f1e4532546ef9248a1 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 16 Jan 2012 00:59:18 -0800 Subject: [PATCH] rustdoc: Write fn docs --- src/rustdoc/gen.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/rustdoc/gen.rs b/src/rustdoc/gen.rs index 2a66bfe8d4c..e7abf6a4339 100644 --- a/src/rustdoc/gen.rs +++ b/src/rustdoc/gen.rs @@ -5,7 +5,7 @@ fn write_markdown( doc: doc::cratedoc, - _crate: @ast::crate, + crate: @ast::crate, writer: io::writer ) { let ctxt = { @@ -14,6 +14,54 @@ fn write_markdown( }; write_header(ctxt, doc.topmod.name); + write_top_module(ctxt, crate, doc.topmod); +} + +fn write_top_module( + ctxt: ctxt, + crate: @ast::crate, + moddoc: doc::moddoc +) { + write_mod_contents(ctxt, crate, moddoc); +} + +fn write_mod( + ctxt: ctxt, + crate: @ast::crate, + moddoc: doc::moddoc +) { + write_mod_contents(ctxt, crate, moddoc); +} + +fn write_mod_contents( + ctxt: ctxt, + crate: @ast::crate, + moddoc: doc::moddoc +) { + for fndoc in *moddoc.fns { + write_fn(ctxt, crate, fndoc); + } + + for moddoc in *moddoc.mods { + write_mod(ctxt, crate, moddoc); + } +} + +fn write_fn( + ctxt: ctxt, + crate: @ast::crate, + fndoc: doc::fndoc +) { + import rustc::middle::ast_map; + + let map = ast_map::map_crate(*crate); + let decl = alt map.get(fndoc.id) { + ast_map::node_item(@{ + node: ast::item_fn(decl, _, _), _ + }) { decl } + }; + + write_fndoc(ctxt, fndoc.name, fndoc, decl); } #[doc( @@ -80,4 +128,13 @@ fn write_markdown_should_write_crate_header() { let markdown = write_markdown_str(doc, ast); assert str::contains(markdown, "# Crate belch\n"); } + + #[test] + fn write_markdown_should_write_function_header() { + let source = "fn func() { }"; + let ast = parse::from_str(source); + let doc = extract::extract(ast, ""); + let markdown = write_markdown_str(doc, ast); + assert str::contains(markdown, "## Function `func`"); + } } \ No newline at end of file