diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-09-26 12:53:06 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-09-26 13:39:06 -0700 |
| commit | 42bcf638b0213747e01af87353413755b9ebc270 (patch) | |
| tree | a71816a69eeedaf70dd94466b384c178e14fb809 | |
| parent | 6a277dc4ba7f29e5a429e763f6faba3041b90c94 (diff) | |
| download | rust-42bcf638b0213747e01af87353413755b9ebc270.tar.gz rust-42bcf638b0213747e01af87353413755b9ebc270.zip | |
rustdoc: Render stability attributes
Closes #8965
| -rw-r--r-- | src/librustdoc/clean.rs | 20 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 13 | ||||
| -rw-r--r-- | src/librustdoc/html/static/main.css | 15 | ||||
| -rw-r--r-- | src/libsyntax/attr.rs | 2 |
4 files changed, 49 insertions, 1 deletions
diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index bfd71345c15..623ac82486d 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -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; @@ -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, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 70f433ff2a3..3320842c046 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -28,6 +28,7 @@ use extra::json::ToJson; use extra::sort; use syntax::ast; +use syntax::attr; use clean; use doctree; @@ -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 { diff --git a/src/librustdoc/html/static/main.css b/src/librustdoc/html/static/main.css index 97f59798240..11ca7a09311 100644 --- a/src/librustdoc/html/static/main.css +++ b/src/librustdoc/html/static/main.css @@ -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; } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 295485d6f6e..47a7d0fbf9e 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -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, |
