rustdoc: Write page titles
This commit is contained in:
parent
78d539927a
commit
4bbe33c8eb
@ -91,12 +91,15 @@ fn write_markdown(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_page(ctxt: ctxt, page: doc::page) {
|
fn write_page(ctxt: ctxt, page: doc::page) {
|
||||||
|
write_title(ctxt, page);
|
||||||
alt page {
|
alt page {
|
||||||
doc::cratepage(doc) {
|
doc::cratepage(doc) {
|
||||||
write_crate(ctxt, doc);
|
write_crate(ctxt, doc);
|
||||||
}
|
}
|
||||||
doc::itempage(doc) {
|
doc::itempage(doc) {
|
||||||
write_item(ctxt, doc);
|
// We don't write a header for item's pages because their
|
||||||
|
// header in the html output is created by the page title
|
||||||
|
write_item_no_header(ctxt, doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctxt.w.write_done();
|
ctxt.w.write_done();
|
||||||
@ -117,6 +120,45 @@ fn should_request_new_writer_for_each_page() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_title(ctxt: ctxt, page: doc::page) {
|
||||||
|
ctxt.w.write_line(#fmt("%% %s", make_title(page)));
|
||||||
|
ctxt.w.write_line("");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_title(page: doc::page) -> str {
|
||||||
|
let item = alt page {
|
||||||
|
doc::cratepage(cratedoc) {
|
||||||
|
doc::modtag(cratedoc.topmod)
|
||||||
|
}
|
||||||
|
doc::itempage(itemtag) {
|
||||||
|
itemtag
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let title = markdown_pass::header_text(item);
|
||||||
|
let title = str::replace(title, "`", "");
|
||||||
|
ret title;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_write_title_for_each_page() {
|
||||||
|
let (writer_factory, po) = markdown_writer::future_writer_factory();
|
||||||
|
let (srv, doc) = test::create_doc_srv(
|
||||||
|
"#[link(name = \"core\")]; mod a { }");
|
||||||
|
let doc = page_pass::mk_pass(config::doc_per_mod).f(srv, doc);
|
||||||
|
write_markdown(doc, writer_factory);
|
||||||
|
iter::repeat(2u) {||
|
||||||
|
let (page, markdown) = comm::recv(po);
|
||||||
|
alt page {
|
||||||
|
doc::cratepage(_) {
|
||||||
|
assert str::contains(markdown, "% Crate core");
|
||||||
|
}
|
||||||
|
doc::itempage(_) {
|
||||||
|
assert str::contains(markdown, "% Module a");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum hlvl {
|
enum hlvl {
|
||||||
h1 = 1,
|
h1 = 1,
|
||||||
h2 = 2,
|
h2 = 2,
|
||||||
@ -210,7 +252,6 @@ fn write_crate(
|
|||||||
ctxt: ctxt,
|
ctxt: ctxt,
|
||||||
doc: doc::cratedoc
|
doc: doc::cratedoc
|
||||||
) {
|
) {
|
||||||
write_header(ctxt, h1, doc::modtag(doc.topmod));
|
|
||||||
write_top_module(ctxt, doc.topmod);
|
write_top_module(ctxt, doc.topmod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +266,6 @@ fn write_mod(
|
|||||||
ctxt: ctxt,
|
ctxt: ctxt,
|
||||||
moddoc: doc::moddoc
|
moddoc: doc::moddoc
|
||||||
) {
|
) {
|
||||||
write_header(ctxt, h1, doc::modtag(moddoc));
|
|
||||||
write_mod_contents(ctxt, moddoc);
|
write_mod_contents(ctxt, moddoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,6 +334,18 @@ fn write_mod_contents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_item(ctxt: ctxt, doc: doc::itemtag) {
|
fn write_item(ctxt: ctxt, doc: doc::itemtag) {
|
||||||
|
write_item_(ctxt, doc, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_item_no_header(ctxt: ctxt, doc: doc::itemtag) {
|
||||||
|
write_item_(ctxt, doc, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_item_(ctxt: ctxt, doc: doc::itemtag, write_header: bool) {
|
||||||
|
if write_header {
|
||||||
|
write_item_header(ctxt, doc);
|
||||||
|
}
|
||||||
|
|
||||||
alt doc {
|
alt doc {
|
||||||
doc::modtag(moddoc) { write_mod(ctxt, moddoc) }
|
doc::modtag(moddoc) { write_mod(ctxt, moddoc) }
|
||||||
doc::nmodtag(nmoddoc) { write_nmod(ctxt, nmoddoc) }
|
doc::nmodtag(nmoddoc) { write_nmod(ctxt, nmoddoc) }
|
||||||
@ -307,6 +359,17 @@ fn write_item(ctxt: ctxt, doc: doc::itemtag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_item_header(ctxt: ctxt, doc: doc::itemtag) {
|
||||||
|
write_header(ctxt, item_header_lvl(doc), doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn item_header_lvl(doc: doc::itemtag) -> hlvl {
|
||||||
|
alt doc {
|
||||||
|
doc::modtag(_) | doc::nmodtag(_) { h1 }
|
||||||
|
_ { h2 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_write_crate_description() {
|
fn should_write_crate_description() {
|
||||||
let markdown = test::render("#[doc = \"this is the crate\"];");
|
let markdown = test::render("#[doc = \"this is the crate\"];");
|
||||||
@ -354,7 +417,6 @@ fn should_not_write_index_if_no_entries() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_nmod(ctxt: ctxt, doc: doc::nmoddoc) {
|
fn write_nmod(ctxt: ctxt, doc: doc::nmoddoc) {
|
||||||
write_header(ctxt, h1, doc::nmodtag(doc));
|
|
||||||
write_common(ctxt, doc.desc(), doc.sections());
|
write_common(ctxt, doc.desc(), doc.sections());
|
||||||
|
|
||||||
for fndoc in doc.fns {
|
for fndoc in doc.fns {
|
||||||
@ -379,7 +441,6 @@ fn write_fn(
|
|||||||
ctxt: ctxt,
|
ctxt: ctxt,
|
||||||
doc: doc::fndoc
|
doc: doc::fndoc
|
||||||
) {
|
) {
|
||||||
write_header(ctxt, h2, doc::fntag(doc));
|
|
||||||
write_fnlike(
|
write_fnlike(
|
||||||
ctxt,
|
ctxt,
|
||||||
doc.sig,
|
doc.sig,
|
||||||
@ -463,7 +524,6 @@ fn write_const(
|
|||||||
ctxt: ctxt,
|
ctxt: ctxt,
|
||||||
doc: doc::constdoc
|
doc: doc::constdoc
|
||||||
) {
|
) {
|
||||||
write_header(ctxt, h2, doc::consttag(doc));
|
|
||||||
write_sig(ctxt, doc.sig);
|
write_sig(ctxt, doc.sig);
|
||||||
write_common(ctxt, doc.desc(), doc.sections());
|
write_common(ctxt, doc.desc(), doc.sections());
|
||||||
}
|
}
|
||||||
@ -486,7 +546,6 @@ fn write_enum(
|
|||||||
ctxt: ctxt,
|
ctxt: ctxt,
|
||||||
doc: doc::enumdoc
|
doc: doc::enumdoc
|
||||||
) {
|
) {
|
||||||
write_header(ctxt, h2, doc::enumtag(doc));
|
|
||||||
write_common(ctxt, doc.desc(), doc.sections());
|
write_common(ctxt, doc.desc(), doc.sections());
|
||||||
write_variants(ctxt, doc.variants);
|
write_variants(ctxt, doc.variants);
|
||||||
}
|
}
|
||||||
@ -566,7 +625,6 @@ fn should_write_variant_list_with_signatures() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_res(ctxt: ctxt, doc: doc::resdoc) {
|
fn write_res(ctxt: ctxt, doc: doc::resdoc) {
|
||||||
write_header(ctxt, h2, doc::restag(doc));
|
|
||||||
write_sig(ctxt, doc.sig);
|
write_sig(ctxt, doc.sig);
|
||||||
write_common(ctxt, doc.desc(), doc.sections());
|
write_common(ctxt, doc.desc(), doc.sections());
|
||||||
}
|
}
|
||||||
@ -584,7 +642,6 @@ fn should_write_resource_signature() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_iface(ctxt: ctxt, doc: doc::ifacedoc) {
|
fn write_iface(ctxt: ctxt, doc: doc::ifacedoc) {
|
||||||
write_header(ctxt, h2, doc::ifacetag(doc));
|
|
||||||
write_common(ctxt, doc.desc(), doc.sections());
|
write_common(ctxt, doc.desc(), doc.sections());
|
||||||
write_methods(ctxt, doc.methods);
|
write_methods(ctxt, doc.methods);
|
||||||
}
|
}
|
||||||
@ -631,7 +688,6 @@ fn should_write_iface_method_signature() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_impl(ctxt: ctxt, doc: doc::impldoc) {
|
fn write_impl(ctxt: ctxt, doc: doc::impldoc) {
|
||||||
write_header(ctxt, h2, doc::impltag(doc));
|
|
||||||
write_common(ctxt, doc.desc(), doc.sections());
|
write_common(ctxt, doc.desc(), doc.sections());
|
||||||
write_methods(ctxt, doc.methods);
|
write_methods(ctxt, doc.methods);
|
||||||
}
|
}
|
||||||
@ -673,7 +729,6 @@ fn write_type(
|
|||||||
ctxt: ctxt,
|
ctxt: ctxt,
|
||||||
doc: doc::tydoc
|
doc: doc::tydoc
|
||||||
) {
|
) {
|
||||||
write_header(ctxt, h2, doc::tytag(doc));
|
|
||||||
write_sig(ctxt, doc.sig);
|
write_sig(ctxt, doc.sig);
|
||||||
write_common(ctxt, doc.desc(), doc.sections());
|
write_common(ctxt, doc.desc(), doc.sections());
|
||||||
}
|
}
|
||||||
@ -759,16 +814,6 @@ mod test {
|
|||||||
ret tuple::second(comm::recv(po));
|
ret tuple::second(comm::recv(po));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn write_markdown_should_write_crate_header() {
|
|
||||||
astsrv::from_str("") {|srv|
|
|
||||||
let doc = extract::from_srv(srv, "belch");
|
|
||||||
let doc = attr_pass::mk_pass().f(srv, doc);
|
|
||||||
let markdown = write_markdown_str(doc);
|
|
||||||
assert str::contains(markdown, "# Crate `belch`");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn write_markdown_should_write_mod_headers() {
|
fn write_markdown_should_write_mod_headers() {
|
||||||
let markdown = render("mod moo { }");
|
let markdown = render("mod moo { }");
|
||||||
|
Loading…
Reference in New Issue
Block a user