Skip to content

Commit

Permalink
rustdoc: Start rendering variants (redirect to enum)
Browse files Browse the repository at this point in the history
This allows reasonable behavior when an enum is clicked in an import.
  • Loading branch information
alexcrichton committed Sep 25, 2013
1 parent 5c6f8a9 commit 5636ca6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ impl<'self> fmt::Default for Item<'self> {
clean::StructItem(ref s) => item_struct(fmt.buf, it.item, s),
clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e),
clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t),
clean::VariantItem(*) => item_variant(fmt.buf, it.cx, it.item),
_ => {}
}
}
Expand Down Expand Up @@ -930,7 +931,8 @@ fn item_enum(w: &mut io::Writer, it: &clean::Item, e: &clean::Enum) {
} else {
write!(w, " \\{\n");
for v in e.variants.iter() {
let name = v.name.get_ref().as_slice();
let name = format!("<a name='variant.{0}'>{0}</a>",
v.name.get_ref().as_slice());
match v.inner {
clean::VariantItem(ref var) => {
match var.kind {
Expand Down Expand Up @@ -1159,3 +1161,12 @@ fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> {
}
return map;
}

fn item_variant(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
write!(w, "<DOCTYPE html><html><head>\
<meta http-equiv='refresh' content='0; \
url=../enum.{}.html\\#variant.{}'>\
</head><body></body></html>",
*cx.current.last(),
it.name.get_ref().as_slice());
}

0 comments on commit 5636ca6

Please sign in to comment.