about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-09-27 10:40:41 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-09-27 10:40:41 -0700
commitc5e03bec4d1e7655fc0fd13922fbebb3001f6bac (patch)
tree9f86089aa268315fc1b8ce6aae820e465808678b
parent10e7f12dafc2e24c9f072d68ff6c4929a28b5c8c (diff)
downloadrust-c5e03bec4d1e7655fc0fd13922fbebb3001f6bac.tar.gz
rust-c5e03bec4d1e7655fc0fd13922fbebb3001f6bac.zip
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.
-rw-r--r--src/librustdoc/html/render.rs60
-rw-r--r--src/librustdoc/html/static/main.js41
2 files changed, 45 insertions, 56 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 3320842c046..717aeaa1fd3 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -248,7 +248,9 @@ impl<'self> DocFolder for Cache {
         match item.name {
             Some(ref s) => {
                 let parent = match item.inner {
-                    clean::TyMethodItem(*) | clean::VariantItem(*) => {
+                    clean::TyMethodItem(*) |
+                    clean::StructFieldItem(*) |
+                    clean::VariantItem(*) => {
                         Some((Some(*self.parent_stack.last()),
                               self.stack.slice_to(self.stack.len() - 1)))
 
@@ -299,7 +301,7 @@ impl<'self> DocFolder for Cache {
 
         // Maintain the parent stack
         let parent_pushed = match item.inner {
-            clean::TraitItem(*) | clean::EnumItem(*) => {
+            clean::TraitItem(*) | clean::EnumItem(*) | clean::StructItem(*) => {
                 self.parent_stack.push(item.id); true
             }
             clean::ImplItem(ref i) => {
@@ -510,28 +512,6 @@ impl Context {
                 let dst = self.dst.push(item_path(&item));
                 let writer = dst.open_writer(io::CreateOrTruncate);
                 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::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),
-            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);
 
     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());
         render_method(w, m.item(), false);
         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,
            withlink: bool) {
         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>}
                         }{generics}{decl}",
                match purity {
                    ast::unsafe_fn => "unsafe ",
                    _ => "",
                },
+               ty = shortty(it),
                name = it.name.get_ref().as_slice(),
                generics = *g,
                decl = Method(selfty, d),
@@ -1014,7 +994,7 @@ fn render_struct(w: &mut io::Writer, it: &clean::Item,
             for field in fields.iter() {
                 match field.inner {
                     clean::StructFieldItem(ref ty) => {
-                        write!(w, "    {}<a name='field.{name}'>{name}</a>: \
+                        write!(w, "    {}<a name='structfield.{name}'>{name}</a>: \
                                    {},\n{}",
                                VisSpace(field.visibility),
                                ty.type_,
@@ -1089,7 +1069,7 @@ fn render_impl(w: &mut io::Writer, i: &clean::Impl) {
     write!(w, "{}</code></h3>", i.for_);
     write!(w, "<div class='methods'>");
     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());
         render_method(w, meth, false);
         write!(w, "</code></h4>\n");
@@ -1196,21 +1176,3 @@ 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());
-}
-
-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());
-}
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index b5ae3dadd77..881149b0dd2 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -265,25 +265,52 @@
                     output += '<tr class="' + type + ' result"><td>';
 
                     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') {
-                        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) {
+                        console.log(item);
                         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 {
-                        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 {
-                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>";
             $('.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();
         }