Skip to content

Commit

Permalink
rustdoc: Render stability attributes
Browse files Browse the repository at this point in the history
Closes #8965
  • Loading branch information
alexcrichton committed Sep 26, 2013
1 parent 6a277dc commit 42bcf63
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/librustdoc/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use its = syntax::parse::token::ident_to_str;
use syntax;
use syntax::ast;
use syntax::ast_util;
use syntax::attr;
use syntax::attr::AttributeMethods;

use std;
Expand Down Expand Up @@ -206,6 +207,25 @@ impl Clean<Attribute> for ast::Attribute {
}
}

// This is a rough approximation that gets us what we want.
impl<'self> attr::AttrMetaMethods for &'self Attribute {
fn name(&self) -> @str {
match **self {
Word(ref n) | List(ref n, _) | NameValue(ref n, _) =>
n.to_managed()
}
}

fn value_str(&self) -> Option<@str> {
match **self {
NameValue(_, ref v) => Some(v.to_managed()),
_ => None,
}
}
fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
fn name_str_pair(&self) -> Option<(@str, @str)> { None }
}

#[deriving(Clone, Encodable, Decodable)]
pub struct TyParam {
name: ~str,
Expand Down
13 changes: 13 additions & 0 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use extra::json::ToJson;
use extra::sort;

use syntax::ast;
use syntax::attr;

use clean;
use doctree;
Expand Down Expand Up @@ -568,6 +569,18 @@ impl<'self> Item<'self> {

impl<'self> fmt::Default for Item<'self> {
fn fmt(it: &Item<'self>, fmt: &mut fmt::Formatter) {
match attr::find_stability(it.item.attrs.iter()) {
Some(stability) => {
write!(fmt.buf,
"<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
lvl = stability.level.to_str(),
reason = match stability.text {
Some(s) => s, None => @"",
});
}
None => {}
}

// Write the breadcrumb trail header for the top
write!(fmt.buf, "<h1 class='fqn'>");
match it.item.inner {
Expand Down
15 changes: 15 additions & 0 deletions src/librustdoc/html/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,18 @@ a {
float: left;
padding: 20px;
}

.stability {
border-left: 5px solid #000;
border-radius: 3px;
padding: 0 3px;
float: right;
background: #fff;
text-transform: lowercase;
}
.stability.Deprecated { border-color: #D60027; color: #880017; }
.stability.Experimental { border-color: #EC5315; color: #a53c0e; }
.stability.Unstable { border-color: #FFD700; color: #b39800; }
.stability.Stable { border-color: #AEC516; color: #7c8b10; }
.stability.Frozen { border-color: #009431; color: #007726; }
.stability.Locked { border-color: #0084B6; color: #00668c; }
2 changes: 1 addition & 1 deletion src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ pub struct Stability {
}

/// The available stability levels.
#[deriving(Eq,Ord,Clone)]
#[deriving(Eq,Ord,Clone,ToStr)]
pub enum StabilityLevel {
Deprecated,
Experimental,
Expand Down

5 comments on commit 42bcf63

@bors
Copy link
Contributor

@bors bors commented on 42bcf63 Sep 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@42bcf63

@bors
Copy link
Contributor

@bors bors commented on 42bcf63 Sep 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/more-rustdoc-improvements = 42bcf63 into auto

@bors
Copy link
Contributor

@bors bors commented on 42bcf63 Sep 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/more-rustdoc-improvements = 42bcf63 merged ok, testing candidate = 74dfd93

@bors
Copy link
Contributor

@bors bors commented on 42bcf63 Sep 27, 2013

@bors
Copy link
Contributor

@bors bors commented on 42bcf63 Sep 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 74dfd93

Please sign in to comment.