From a5368fb6d841a244ddd6fb7f983b90ac1ce0c9ef Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 10 Mar 2012 16:44:48 -0800 Subject: [PATCH] rustdoc: Put native mods on their own pages. Closes #1959 --- src/rustdoc/markdown_index_pass.rs | 17 ++++++++++++++++- src/rustdoc/page_pass.rs | 26 +++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/rustdoc/markdown_index_pass.rs b/src/rustdoc/markdown_index_pass.rs index c97c8f7a575..7b4336f7386 100644 --- a/src/rustdoc/markdown_index_pass.rs +++ b/src/rustdoc/markdown_index_pass.rs @@ -52,7 +52,8 @@ fn item_to_entry( config: config::config ) -> doc::index_entry { let link = alt doc { - doc::modtag(_) if config.output_style == config::doc_per_mod { + doc::modtag(_) | doc::nmodtag(_) + if config.output_style == config::doc_per_mod { markdown_writer::make_filename(config, doc::itempage(doc)) } _ { @@ -148,6 +149,20 @@ fn should_index_mod_contents_multi_page() { }; } +#[test] +fn should_index_native_mod_pages() { + let doc = test::mk_doc( + config::doc_per_mod, + "native mod a { }" + ); + assert option::get(doc.cratemod().index).entries[0] == { + kind: "Native module", + name: "a", + brief: none, + link: "a.html" + }; +} + #[test] fn should_add_brief_desc_to_index() { let doc = test::mk_doc( diff --git a/src/rustdoc/page_pass.rs b/src/rustdoc/page_pass.rs index d86eecc9699..257f59699ea 100644 --- a/src/rustdoc/page_pass.rs +++ b/src/rustdoc/page_pass.rs @@ -59,7 +59,8 @@ fn make_doc_from_pages(page_port: page_port) -> doc::doc { fn find_pages(doc: doc::doc, page_chan: page_chan) { let fold = fold::fold({ fold_crate: fold_crate, - fold_mod: fold_mod + fold_mod: fold_mod, + fold_nmod: fold_nmod with *fold::default_any_fold(page_chan) }); fold.fold_doc(fold, doc); @@ -106,6 +107,7 @@ fn strip_mod(doc: doc::moddoc) -> doc::moddoc { items: vec::filter(doc.items) {|item| alt item { doc::modtag(_) { false } + doc::nmodtag(_) { false } _ { true } } } @@ -113,6 +115,16 @@ fn strip_mod(doc: doc::moddoc) -> doc::moddoc { } } +fn fold_nmod( + fold: fold::fold, + doc: doc::nmoddoc +) -> doc::nmoddoc { + let doc = fold::default_seq_fold_nmod(fold, doc); + let page = doc::itempage(doc::nmodtag(doc)); + comm::send(fold.ctxt, some(page)); + ret doc; +} + #[test] fn should_not_split_the_doc_into_pages_for_doc_per_crate() { let doc = test::mk_doc_( @@ -134,6 +146,18 @@ fn should_remove_mods_from_containing_mods() { assert vec::is_empty(doc.cratemod().mods()); } +#[test] +fn should_make_a_page_for_every_native_mod() { + let doc = test::mk_doc("native mod a { }"); + assert doc.pages.nmods()[0].name() == "a"; +} + +#[test] +fn should_remove_native_mods_from_containing_mods() { + let doc = test::mk_doc("native mod a { }"); + assert vec::is_empty(doc.cratemod().nmods()); +} + #[cfg(test)] mod test { fn mk_doc_(