rustdoc: Put brief descriptions in the indexes
This commit is contained in:
parent
a4ff220133
commit
29ac3c811d
3 changed files with 29 additions and 1 deletions
|
@ -131,12 +131,14 @@ Fields:
|
||||||
|
|
||||||
* kind - The type of thing being indexed, e.g. 'Module'
|
* kind - The type of thing being indexed, e.g. 'Module'
|
||||||
* name - The name of the thing
|
* name - The name of the thing
|
||||||
|
* brief - The brief description
|
||||||
* link - A format-specific string representing the link target
|
* link - A format-specific string representing the link target
|
||||||
|
|
||||||
"]
|
"]
|
||||||
type index_entry = {
|
type index_entry = {
|
||||||
kind: str,
|
kind: str,
|
||||||
name: str,
|
name: str,
|
||||||
|
brief: option<str>,
|
||||||
link: str
|
link: str
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ fn item_to_entry(
|
||||||
{
|
{
|
||||||
kind: markdown_pass::header_kind(doc),
|
kind: markdown_pass::header_kind(doc),
|
||||||
name: markdown_pass::header_name(doc),
|
name: markdown_pass::header_name(doc),
|
||||||
|
brief: doc.brief(),
|
||||||
link: link
|
link: link
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,11 +101,13 @@ fn should_index_mod_contents() {
|
||||||
assert option::get(doc.cratemod().index).entries[0] == {
|
assert option::get(doc.cratemod().index).entries[0] == {
|
||||||
kind: "Module",
|
kind: "Module",
|
||||||
name: "a",
|
name: "a",
|
||||||
|
brief: none,
|
||||||
link: "#module-a"
|
link: "#module-a"
|
||||||
};
|
};
|
||||||
assert option::get(doc.cratemod().index).entries[1] == {
|
assert option::get(doc.cratemod().index).entries[1] == {
|
||||||
kind: "Function",
|
kind: "Function",
|
||||||
name: "b",
|
name: "b",
|
||||||
|
brief: none,
|
||||||
link: "#function-b"
|
link: "#function-b"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -118,15 +121,26 @@ fn should_index_mod_contents_multi_page() {
|
||||||
assert option::get(doc.cratemod().index).entries[0] == {
|
assert option::get(doc.cratemod().index).entries[0] == {
|
||||||
kind: "Module",
|
kind: "Module",
|
||||||
name: "a",
|
name: "a",
|
||||||
|
brief: none,
|
||||||
link: "a.html"
|
link: "a.html"
|
||||||
};
|
};
|
||||||
assert option::get(doc.cratemod().index).entries[1] == {
|
assert option::get(doc.cratemod().index).entries[1] == {
|
||||||
kind: "Function",
|
kind: "Function",
|
||||||
name: "b",
|
name: "b",
|
||||||
|
brief: none,
|
||||||
link: "#function-b"
|
link: "#function-b"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_add_brief_desc_to_index() {
|
||||||
|
let doc = test::mk_doc(
|
||||||
|
config::doc_per_mod,
|
||||||
|
"#[doc(brief = \"test\")] mod a { }"
|
||||||
|
);
|
||||||
|
assert option::get(doc.cratemod().index).entries[0].brief == some("test");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
fn mk_doc(output_style: config::output_style, source: str) -> doc::doc {
|
fn mk_doc(output_style: config::output_style, source: str) -> doc::doc {
|
||||||
|
@ -136,6 +150,7 @@ mod test {
|
||||||
with config::default_config("whatever")
|
with config::default_config("whatever")
|
||||||
};
|
};
|
||||||
let doc = extract::from_srv(srv, "");
|
let doc = extract::from_srv(srv, "");
|
||||||
|
let doc = attr_pass::mk_pass().f(srv, doc);
|
||||||
let doc = path_pass::mk_pass().f(srv, doc);
|
let doc = path_pass::mk_pass().f(srv, doc);
|
||||||
run(srv, doc, config)
|
run(srv, doc, config)
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,12 @@ fn write_index(ctxt: ctxt, index: doc::index) {
|
||||||
for entry in index.entries {
|
for entry in index.entries {
|
||||||
let header = header_text_(entry.kind, entry.name);
|
let header = header_text_(entry.kind, entry.name);
|
||||||
let id = entry.link;
|
let id = entry.link;
|
||||||
ctxt.w.write_line(#fmt("* [%s](%s)", header, id));
|
if option::is_some(entry.brief) {
|
||||||
|
ctxt.w.write_line(#fmt("* [%s](%s) - %s",
|
||||||
|
header, id, option::get(entry.brief)));
|
||||||
|
} else {
|
||||||
|
ctxt.w.write_line(#fmt("* [%s](%s)", header, id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ctxt.w.write_line("");
|
ctxt.w.write_line("");
|
||||||
}
|
}
|
||||||
|
@ -298,6 +303,12 @@ fn should_write_index() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_write_index_brief() {
|
||||||
|
let markdown = test::render("#[doc(brief = \"test\")] mod a { }");
|
||||||
|
assert str::contains(markdown, "(#module-a) - test\n");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_not_write_index_if_no_entries() {
|
fn should_not_write_index_if_no_entries() {
|
||||||
let markdown = test::render("");
|
let markdown = test::render("");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue