rustdoc: Don't emit redirect pages for variants/fields

It's just a waste of disk space and it can be done just as well in JS.
This commit is contained in:
Alex Crichton 2013-09-27 10:40:41 -07:00
parent 10e7f12daf
commit c5e03bec4d
2 changed files with 45 additions and 56 deletions

View File

@ -248,7 +248,9 @@ impl<'self> DocFolder for Cache {
match item.name { match item.name {
Some(ref s) => { Some(ref s) => {
let parent = match item.inner { let parent = match item.inner {
clean::TyMethodItem(*) | clean::VariantItem(*) => { clean::TyMethodItem(*) |
clean::StructFieldItem(*) |
clean::VariantItem(*) => {
Some((Some(*self.parent_stack.last()), Some((Some(*self.parent_stack.last()),
self.stack.slice_to(self.stack.len() - 1))) self.stack.slice_to(self.stack.len() - 1)))
@ -299,7 +301,7 @@ impl<'self> DocFolder for Cache {
// Maintain the parent stack // Maintain the parent stack
let parent_pushed = match item.inner { let parent_pushed = match item.inner {
clean::TraitItem(*) | clean::EnumItem(*) => { clean::TraitItem(*) | clean::EnumItem(*) | clean::StructItem(*) => {
self.parent_stack.push(item.id); true self.parent_stack.push(item.id); true
} }
clean::ImplItem(ref i) => { clean::ImplItem(ref i) => {
@ -510,28 +512,6 @@ impl Context {
let dst = self.dst.push(item_path(&item)); let dst = self.dst.push(item_path(&item));
let writer = dst.open_writer(io::CreateOrTruncate); let writer = dst.open_writer(io::CreateOrTruncate);
render(writer.unwrap(), self, &item, true); render(writer.unwrap(), self, &item, true);
// recurse if necessary
let name = item.name.get_ref().clone();
match item.inner {
clean::EnumItem(e) => {
let mut it = e.variants.move_iter();
do self.recurse(name) |this| {
for item in it {
f(this, item);
}
}
}
clean::StructItem(s) => {
let mut it = s.fields.move_iter();
do self.recurse(name) |this| {
for item in it {
f(this, item);
}
}
}
_ => {}
}
} }
_ => {} _ => {}
@ -613,9 +593,6 @@ impl<'self> fmt::Default for Item<'self> {
clean::StructItem(ref s) => item_struct(fmt.buf, it.item, s), clean::StructItem(ref s) => item_struct(fmt.buf, it.item, s),
clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e), clean::EnumItem(ref e) => item_enum(fmt.buf, it.item, e),
clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t), clean::TypedefItem(ref t) => item_typedef(fmt.buf, it.item, t),
clean::VariantItem(*) => item_variant(fmt.buf, it.cx, it.item),
clean::StructFieldItem(*) => item_struct_field(fmt.buf, it.cx,
it.item),
_ => {} _ => {}
} }
} }
@ -862,7 +839,8 @@ fn item_trait(w: &mut io::Writer, it: &clean::Item, t: &clean::Trait) {
document(w, it); document(w, it);
fn meth(w: &mut io::Writer, m: &clean::TraitMethod) { fn meth(w: &mut io::Writer, m: &clean::TraitMethod) {
write!(w, "<h3 id='fn.{}' class='method'><code>", write!(w, "<h3 id='{}.{}' class='method'><code>",
shortty(m.item()),
*m.item().name.get_ref()); *m.item().name.get_ref());
render_method(w, m.item(), false); render_method(w, m.item(), false);
write!(w, "</code></h3>"); write!(w, "</code></h3>");
@ -923,13 +901,15 @@ fn render_method(w: &mut io::Writer, meth: &clean::Item, withlink: bool) {
g: &clean::Generics, selfty: &clean::SelfTy, d: &clean::FnDecl, g: &clean::Generics, selfty: &clean::SelfTy, d: &clean::FnDecl,
withlink: bool) { withlink: bool) {
write!(w, "{}fn {withlink, select, write!(w, "{}fn {withlink, select,
true{<a href='\\#fn.{name}' class='fnname'>{name}</a>} true{<a href='\\#{ty}.{name}'
class='fnname'>{name}</a>}
other{<span class='fnname'>{name}</span>} other{<span class='fnname'>{name}</span>}
}{generics}{decl}", }{generics}{decl}",
match purity { match purity {
ast::unsafe_fn => "unsafe ", ast::unsafe_fn => "unsafe ",
_ => "", _ => "",
}, },
ty = shortty(it),
name = it.name.get_ref().as_slice(), name = it.name.get_ref().as_slice(),
generics = *g, generics = *g,
decl = Method(selfty, d), decl = Method(selfty, d),
@ -1014,7 +994,7 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
for field in fields.iter() { for field in fields.iter() {
match field.inner { match field.inner {
clean::StructFieldItem(ref ty) => { clean::StructFieldItem(ref ty) => {
write!(w, " {}<a name='field.{name}'>{name}</a>: \ write!(w, " {}<a name='structfield.{name}'>{name}</a>: \
{},\n{}", {},\n{}",
VisSpace(field.visibility), VisSpace(field.visibility),
ty.type_, ty.type_,
@ -1089,7 +1069,7 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl) {
write!(w, "{}</code></h3>", i.for_); write!(w, "{}</code></h3>", i.for_);
write!(w, "<div class='methods'>"); write!(w, "<div class='methods'>");
for meth in i.methods.iter() { for meth in i.methods.iter() {
write!(w, "<h4 id='fn.{}' class='method'><code>", write!(w, "<h4 id='method.{}' class='method'><code>",
*meth.name.get_ref()); *meth.name.get_ref());
render_method(w, meth, false); render_method(w, meth, false);
write!(w, "</code></h4>\n"); write!(w, "</code></h4>\n");
@ -1196,21 +1176,3 @@ fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> {
} }
return map; 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());
}
fn item_struct_field(w: &mut io::Writer, cx: &Context, it: &clean::Item) {
write!(w, "<DOCTYPE html><html><head>\
<meta http-equiv='refresh' content='0; \
url=../struct.{}.html\\#field.{}'>\
</head><body></body></html>",
*cx.current.last(),
it.name.get_ref().as_slice());
}

View File

@ -265,25 +265,52 @@
output += '<tr class="' + type + ' result"><td>'; output += '<tr class="' + type + ' result"><td>';
if (type === 'mod') { if (type === 'mod') {
output += item.path + '::<a href="' + rootPath + item.path.replace(/::/g, '/') + '/' + name + '/index.html" class="' + type + '">' + name + '</a>'; output += item.path +
'::<a href="' + rootPath +
item.path.replace(/::/g, '/') + '/' +
name + '/index.html" class="' +
type + '">' + name + '</a>';
} else if (type === 'static' || type === 'reexport') { } else if (type === 'static' || type === 'reexport') {
output += item.path + '::<a href="' + rootPath + item.path.replace(/::/g, '/') + '/index.html" class="' + type + '">' + name + '</a>'; output += item.path +
'::<a href="' + rootPath +
item.path.replace(/::/g, '/') +
'/index.html" class="' + type +
'">' + name + '</a>';
} else if (item.parent !== undefined) { } else if (item.parent !== undefined) {
console.log(item);
var myparent = allPaths[item.parent]; var myparent = allPaths[item.parent];
output += item.path + '::' + myparent.name + '::<a href="' + rootPath + item.path.replace(/::/g, '/') + '/' + myparent.type + '.' + myparent.name + '.html" class="' + type + '">' + name + '</a>'; var anchor = '#' + type + '.' + name;
output += item.path + '::' + myparent.name +
'::<a href="' + rootPath +
item.path.replace(/::/g, '/') +
'/' + myparent.type +
'.' + myparent.name +
'.html' + anchor +
'" class="' + type +
'">' + name + '</a>';
} else { } else {
output += item.path + '::<a href="' + rootPath + item.path.replace(/::/g, '/') + '/' + type + '.' + name + '.html" class="' + type + '">' + name + '</a>'; output += item.path +
'::<a href="' + rootPath +
item.path.replace(/::/g, '/') +
'/' + type +
'.' + name +
'.html" class="' + type +
'">' + name + '</a>';
} }
output += '</td><td><span class="desc">' + item.desc + '</span></td></tr>'; output += '</td><td><span class="desc">' + item.desc +
'</span></td></tr>';
}); });
} else { } else {
output += 'No results :( <a href="https://duckduckgo.com/?q=' + encodeURIComponent('rust ' + query.query) + '">Try on DuckDuckGo?</a>'; output += 'No results :( <a href="https://duckduckgo.com/?q=' +
encodeURIComponent('rust ' + query.query) +
'">Try on DuckDuckGo?</a>';
} }
output += "</p>"; output += "</p>";
$('.content').html(output); $('.content').html(output);
$('.search-results .desc').width($('.content').width() - 40 - $('.content td:first-child').first().width()); $('.search-results .desc').width($('.content').width() - 40 -
$('.content td:first-child').first().width());
initSearchNav(); initSearchNav();
} }