Skip to content

Commit

Permalink
Auto merge of #35236 - nrc:rustdoc-redirects, r=@alexcrichton
Browse files Browse the repository at this point in the history
rustdoc: redirect URLs

cc #35020 which does this properly

r? @alexcrichton
  • Loading branch information
bors authored Aug 17, 2016
2 parents d6d0590 + 879637f commit 6c0d66a
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 136 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
url.push_str("/index.html");
}
_ => {
url.push_str(shortty.to_static_str());
url.push_str(shortty.css_class());
url.push_str(".");
url.push_str(fqp.last().unwrap());
url.push_str(".html");
Expand Down
56 changes: 55 additions & 1 deletion src/librustdoc/html/item_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ pub enum ItemType {
AssociatedConst = 18,
}


#[derive(Copy, Eq, PartialEq, Clone)]
pub enum NameSpace {
Type,
Value,
Macro,
}

impl ItemType {
pub fn from_item(item: &clean::Item) -> ItemType {
let inner = match item.inner {
Expand Down Expand Up @@ -90,7 +98,7 @@ impl ItemType {
}
}

pub fn to_static_str(&self) -> &'static str {
pub fn css_class(&self) -> &'static str {
match *self {
ItemType::Module => "mod",
ItemType::ExternCrate => "externcrate",
Expand All @@ -113,9 +121,55 @@ impl ItemType {
ItemType::AssociatedConst => "associatedconstant",
}
}

pub fn name_space(&self) -> NameSpace {
match *self {
ItemType::Struct |
ItemType::Enum |
ItemType::Module |
ItemType::Typedef |
ItemType::Trait |
ItemType::Primitive |
ItemType::AssociatedType => NameSpace::Type,

ItemType::ExternCrate |
ItemType::Import |
ItemType::Function |
ItemType::Static |
ItemType::Impl |
ItemType::TyMethod |
ItemType::Method |
ItemType::StructField |
ItemType::Variant |
ItemType::Constant |
ItemType::AssociatedConst => NameSpace::Value,

ItemType::Macro => NameSpace::Macro,
}
}
}

impl fmt::Display for ItemType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.css_class().fmt(f)
}
}

pub const NAMESPACE_TYPE: &'static str = "t";
pub const NAMESPACE_VALUE: &'static str = "v";
pub const NAMESPACE_MACRO: &'static str = "m";

impl NameSpace {
pub fn to_static_str(&self) -> &'static str {
match *self {
NameSpace::Type => NAMESPACE_TYPE,
NameSpace::Value => NAMESPACE_VALUE,
NameSpace::Macro => NAMESPACE_MACRO,
}
}
}

impl fmt::Display for NameSpace {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.to_static_str().fmt(f)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Layout {

pub struct Page<'a> {
pub title: &'a str,
pub ty: &'a str,
pub css_class: &'a str,
pub root_path: &'a str,
pub description: &'a str,
pub keywords: &'a str,
Expand Down Expand Up @@ -80,7 +80,7 @@ r##"<!DOCTYPE html>
</form>
</nav>
<section id='main' class="content {ty}">{content}</section>
<section id='main' class="content {css_class}">{content}</section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
Expand Down Expand Up @@ -152,7 +152,7 @@ r##"<!DOCTYPE html>
},
content = *t,
root_path = page.root_path,
ty = page.ty,
css_class = page.css_class,
logo = if layout.logo.is_empty() {
"".to_string()
} else {
Expand Down
Loading

0 comments on commit 6c0d66a

Please sign in to comment.