diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 26723482595cd..002aaff25e83e 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -58,6 +58,26 @@ use html::markdown; use html::markdown::Markdown; use html::highlight; +/// A pair of name and its optional document. +#[deriving(Clone, Eq, TotalEq)] +pub struct NameDoc(~str, Option<~str>); + +impl Ord for NameDoc { + fn lt(&self, other: &NameDoc) -> bool { + let &NameDoc(ref name1, _) = self; + let &NameDoc(ref name2, _) = other; + name1.lt(name2) + } +} + +impl TotalOrd for NameDoc { + fn cmp(&self, other: &NameDoc) -> Ordering { + let &NameDoc(ref name1, _) = self; + let &NameDoc(ref name2, _) = other; + name1.cmp(name2) + } +} + /// Major driving force in all rustdoc rendering. This contains information /// about where in the tree-like hierarchy rendering is occurring and controls /// how the current page is being rendered. @@ -84,7 +104,7 @@ pub struct Context { /// functions), and the value is the list of containers belonging to this /// header. This map will change depending on the surrounding context of the /// page. - sidebar: HashMap<~str, ~[~str]>, + sidebar: HashMap<~str, ~[NameDoc]>, /// This flag indicates whether [src] links should be generated or not. If /// the source files are present in the html rendering, then this will be /// `true`. @@ -207,11 +227,18 @@ local_data_key!(pub current_location_key: ~[~str]) /// Generates the documentation for `crate` into the directory `dst` pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { + if krate.module.is_none() { + println!("No docs need to generate for empty crate."); + return Ok(()); + } let mut cx = Context { dst: dst, current: ~[], root_path: ~"", - sidebar: HashMap::new(), + sidebar: match krate.module.get_ref().inner { + clean::ModuleItem(ref m) => { build_sidebar(m) } + _ => { HashMap::new() } + }, layout: layout::Layout { logo: ~"", favicon: ~"", @@ -1012,6 +1039,11 @@ fn shorter<'a>(s: Option<&'a str>) -> &'a str { } } +#[inline] +fn shorter_line(s: Option<&str>) -> ~str { + shorter(s).replace("\n", " ") +} + fn document(w: &mut Writer, item: &clean::Item) -> fmt::Result { match item.doc_value() { Some(s) => { @@ -1651,21 +1683,23 @@ impl<'a> fmt::Show for Sidebar<'a> { None => return Ok(()) }; try!(write!(w, "