Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CSS for future rustdoc merge #33431

Merged
merged 3 commits into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 64 additions & 41 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,19 @@ pub struct Implementor {
/// Metadata about implementations for a type.
#[derive(Clone)]
pub struct Impl {
pub impl_: clean::Impl,
pub dox: Option<String>,
pub stability: Option<clean::Stability>,
pub impl_item: clean::Item,
}

impl Impl {
fn inner_impl(&self) -> &clean::Impl {
match self.impl_item.inner {
clean::ImplItem(ref impl_) => impl_,
_ => panic!("non-impl item found in impl")
}
}

fn trait_did(&self) -> Option<DefId> {
self.impl_.trait_.def_id()
self.inner_impl().trait_.def_id()
}
}

Expand Down Expand Up @@ -1189,31 +1194,34 @@ impl DocFolder for Cache {
// Once we've recursively found all the generics, then hoard off all the
// implementations elsewhere
let ret = self.fold_item_recur(item).and_then(|item| {
if let clean::Item { attrs, inner: clean::ImplItem(i), .. } = item {
if let clean::Item { inner: clean::ImplItem(_), .. } = item {
// Figure out the id of this impl. This may map to a
// primitive rather than always to a struct/enum.
let did = match i.for_ {
clean::ResolvedPath { did, .. } |
clean::BorrowedRef {
type_: box clean::ResolvedPath { did, .. }, ..
} => {
Some(did)
}
ref t => {
t.primitive_type().and_then(|t| {
self.primitive_locations.get(&t).map(|n| {
let id = t.to_def_index();
DefId { krate: *n, index: id }
// Note: matching twice to restrict the lifetime of the `i` borrow.
let did = if let clean::Item { inner: clean::ImplItem(ref i), .. } = item {
match i.for_ {
clean::ResolvedPath { did, .. } |
clean::BorrowedRef {
type_: box clean::ResolvedPath { did, .. }, ..
} => {
Some(did)
}
ref t => {
t.primitive_type().and_then(|t| {
self.primitive_locations.get(&t).map(|n| {
let id = t.to_def_index();
DefId { krate: *n, index: id }
})
})
})
}
}
} else {
unreachable!()
};
if !self.seen_mod {
if let Some(did) = did {
self.impls.entry(did).or_insert(vec![]).push(Impl {
impl_: i,
dox: attrs.value("doc").map(|s|s.to_owned()),
stability: item.stability.clone(),
impl_item: item,
});
}
}
Expand Down Expand Up @@ -1510,11 +1518,15 @@ impl<'a> Item<'a> {
// located, then we return `None`.
} else {
let cache = cache();
let path = &cache.external_paths[&self.item.def_id];
let root = match cache.extern_locations[&self.item.def_id.krate] {
(_, Remote(ref s)) => s.to_string(),
(_, Local) => self.cx.root_path.clone(),
(_, Unknown) => return None,
let path = match cache.external_paths.get(&self.item.def_id) {
Some(path) => path,
None => return None,
};
let root = match cache.extern_locations.get(&self.item.def_id.krate) {
Some(&(_, Remote(ref s))) => s.to_string(),
Some(&(_, Local)) => self.cx.root_path.clone(),
Some(&(_, Unknown)) => return None,
None => return None,
};
Some(format!("{root}{path}/{file}?gotosrc={goto}",
root = root,
Expand Down Expand Up @@ -2132,7 +2144,7 @@ fn render_stability_since_raw<'a>(w: &mut fmt::Formatter,
containing_ver: Option<&'a str>) -> fmt::Result {
if let Some(v) = ver {
if containing_ver != ver && v.len() > 0 {
write!(w, "<span class=\"since\">{}</span>",
write!(w, "<div class=\"since\">{}</div>",
v)?
}
}
Expand Down Expand Up @@ -2449,7 +2461,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
None => return Ok(()),
};
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| {
i.impl_.trait_.is_none()
i.inner_impl().trait_.is_none()
});
if !non_trait.is_empty() {
let render_header = match what {
Expand All @@ -2473,19 +2485,19 @@ fn render_assoc_items(w: &mut fmt::Formatter,
}
if !traits.is_empty() {
let deref_impl = traits.iter().find(|t| {
t.impl_.trait_.def_id() == c.deref_trait_did
t.inner_impl().trait_.def_id() == c.deref_trait_did
});
if let Some(impl_) = deref_impl {
render_deref_methods(w, cx, impl_, containing_item)?;
}
write!(w, "<h2 id='implementations'>Trait \
Implementations</h2>")?;
let (derived, manual): (Vec<_>, Vec<&Impl>) = traits.iter().partition(|i| {
i.impl_.derived
i.inner_impl().derived
});
for i in &manual {
let did = i.trait_did().unwrap();
let assoc_link = AssocItemLink::GotoSource(did, &i.impl_.provided_trait_methods);
let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
render_impl(w, cx, i, assoc_link, true, containing_item.stable_since())?;
}
if !derived.is_empty() {
Expand All @@ -2494,7 +2506,8 @@ fn render_assoc_items(w: &mut fmt::Formatter,
</h3>")?;
for i in &derived {
let did = i.trait_did().unwrap();
let assoc_link = AssocItemLink::GotoSource(did, &i.impl_.provided_trait_methods);
let assoc_link = AssocItemLink::GotoSource(did,
&i.inner_impl().provided_trait_methods);
render_impl(w, cx, i, assoc_link, true, containing_item.stable_since())?;
}
}
Expand All @@ -2504,8 +2517,8 @@ fn render_assoc_items(w: &mut fmt::Formatter,

fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl,
container_item: &clean::Item) -> fmt::Result {
let deref_type = impl_.impl_.trait_.as_ref().unwrap();
let target = impl_.impl_.items.iter().filter_map(|item| {
let deref_type = impl_.inner_impl().trait_.as_ref().unwrap();
let target = impl_.inner_impl().items.iter().filter_map(|item| {
match item.inner {
clean::TypedefItem(ref t, true) => Some(&t.type_),
_ => None,
Expand All @@ -2531,11 +2544,21 @@ fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl,
fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLink,
render_header: bool, outer_version: Option<&str>) -> fmt::Result {
if render_header {
write!(w, "<h3 class='impl'><code>{}</code>", i.impl_)?;
let since = i.stability.as_ref().map(|s| &s.since[..]);
render_stability_since_raw(w, since, outer_version)?;
write!(w, "</h3>")?;
if let Some(ref dox) = i.dox {
write!(w, "<h3 class='impl'><span class='in-band'><code>{}</code>", i.inner_impl())?;
write!(w, "</span><span class='out-of-band'>")?;
let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]);
if let Some(l) = (Item { item: &i.impl_item, cx: cx }).href() {
write!(w, "<div class='ghost'></div>")?;
render_stability_since_raw(w, since, outer_version)?;
write!(w, "<a id='src-{}' class='srclink' \
href='{}' title='{}'>[src]</a>",
i.impl_item.def_id.index.as_usize(), l, "goto source code")?;
} else {
render_stability_since_raw(w, since, outer_version)?;
}
write!(w, "</span>")?;
write!(w, "</h3>\n")?;
if let Some(ref dox) = i.impl_item.attrs.value("doc") {
write!(w, "<div class='docblock'>{}</div>", Markdown(dox))?;
}
}
Expand Down Expand Up @@ -2601,7 +2624,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
}

write!(w, "<div class='impl-items'>")?;
for trait_item in &i.impl_.items {
for trait_item in &i.inner_impl().items {
doctraititem(w, cx, trait_item, link, render_header, false, outer_version)?;
}

Expand Down Expand Up @@ -2629,7 +2652,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
// default items which weren't overridden in the implementation block.
if let Some(did) = i.trait_did() {
if let Some(t) = cache().traits.get(&did) {
render_default_items(w, cx, t, &i.impl_, render_header, outer_version)?;
render_default_items(w, cx, t, &i.inner_impl(), render_header, outer_version)?;
}
}
write!(w, "</div>")?;
Expand Down
43 changes: 39 additions & 4 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):no
h1.fqn {
border-bottom: 1px dashed;
margin-top: 0;
position: relative;
}
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {
border-bottom: 1px solid;
Expand All @@ -105,6 +106,7 @@ h3.impl, h3.method, h4.method, h3.type, h4.type {
font-weight: 600;
margin-top: 10px;
margin-bottom: 10px;
position: relative;
}
h3.impl, h3.method, h3.type {
margin-top: 15px;
Expand Down Expand Up @@ -265,20 +267,39 @@ nav.sub {

.content .out-of-band {
font-size: 23px;
width: 40%;
margin: 0px;
padding: 0px;
text-align: right;
display: inline-block;
font-weight: normal;
position: absolute;
right: 0;
}

h3.impl > .out-of-band {
font-size: 21px;
}

h4 > code, h3 > code {
position: inherit;
}

.in-band, code {
z-index: 5;
}

.content .in-band {
width: 60%;
margin: 0px;
padding: 0px;
display: inline-block;
}

#main { position: relative; }
#main > .since {
top: inherit;
font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.content table {
border-spacing: 0 5px;
border-collapse: separate;
Expand Down Expand Up @@ -498,11 +519,13 @@ em.stab p {
opacity: 0.65;
}

span.since {
float: right;
.since {
font-weight: normal;
font-size: initial;
color: grey;
position: absolute;
right: 0;
top: 0;
}

.variants_table {
Expand Down Expand Up @@ -597,7 +620,19 @@ a.test-arrow {
color: #999;
}

.ghost {
display: none;
}

.ghost + .since {
position: initial;
display: table-cell;
}

.since + .srclink {
display: table-cell;
padding-left: 10px;
}

/* Media Queries */

Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/static/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ h1.fqn {
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {
border-bottom-color: #DDDDDD;
}
.in-band, code {
background-color: white;
}

.docblock code {
background-color: #F5F5F5;
Expand Down