Skip to content

Multiple rustdoc fixes #48755

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

Merged
merged 4 commits into from
Mar 10, 2018
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
51 changes: 23 additions & 28 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3500,11 +3500,9 @@ impl<'a> fmt::Display for Sidebar<'a> {
let cx = self.cx;
let it = self.item;
let parentlen = cx.current.len() - if it.is_mod() {1} else {0};
let mut should_close = false;

if it.is_struct() || it.is_trait() || it.is_primitive() || it.is_union()
|| it.is_enum() || it.is_mod() || it.is_typedef()
{
|| it.is_enum() || it.is_mod() || it.is_typedef() {
write!(fmt, "<p class='location'>")?;
match it.inner {
clean::StructItem(..) => write!(fmt, "Struct ")?,
Expand All @@ -3523,30 +3521,29 @@ impl<'a> fmt::Display for Sidebar<'a> {
}
write!(fmt, "{}", it.name.as_ref().unwrap())?;
write!(fmt, "</p>")?;
}

if it.is_crate() {
if let Some(ref version) = cache().crate_version {
write!(fmt,
"<div class='block version'>\
<p>Version {}</p>\
</div>",
version)?;
}
if it.is_crate() {
if let Some(ref version) = cache().crate_version {
write!(fmt,
"<div class='block version'>\
<p>Version {}</p>\
</div>",
version)?;
}
}

write!(fmt, "<div class=\"sidebar-elems\">")?;
should_close = true;
match it.inner {
clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?,
clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?,
clean::PrimitiveItem(ref p) => sidebar_primitive(fmt, it, p)?,
clean::UnionItem(ref u) => sidebar_union(fmt, it, u)?,
clean::EnumItem(ref e) => sidebar_enum(fmt, it, e)?,
clean::TypedefItem(ref t, _) => sidebar_typedef(fmt, it, t)?,
clean::ModuleItem(ref m) => sidebar_module(fmt, it, &m.items)?,
clean::ForeignTypeItem => sidebar_foreign_type(fmt, it)?,
_ => (),
}
write!(fmt, "<div class=\"sidebar-elems\">")?;
match it.inner {
clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?,
clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?,
clean::PrimitiveItem(ref p) => sidebar_primitive(fmt, it, p)?,
clean::UnionItem(ref u) => sidebar_union(fmt, it, u)?,
clean::EnumItem(ref e) => sidebar_enum(fmt, it, e)?,
clean::TypedefItem(ref t, _) => sidebar_typedef(fmt, it, t)?,
clean::ModuleItem(ref m) => sidebar_module(fmt, it, &m.items)?,
clean::ForeignTypeItem => sidebar_foreign_type(fmt, it)?,
_ => (),
}

// The sidebar is designed to display sibling functions, modules and
Expand Down Expand Up @@ -3586,10 +3583,8 @@ impl<'a> fmt::Display for Sidebar<'a> {
write!(fmt, "<script defer src=\"{path}sidebar-items.js\"></script>",
path = relpath)?;
}
if should_close {
// Closes sidebar-elems div.
write!(fmt, "</div>")?;
}
// Closes sidebar-elems div.
write!(fmt, "</div>")?;

Ok(())
}
Expand Down
88 changes: 52 additions & 36 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,15 @@
}

function handleShortcut(ev) {
if (document.activeElement.tagName === "INPUT")
if (document.activeElement.tagName === "INPUT" &&
hasClass(document.getElementById('main'), "hidden")) {
return;
}

// Don't interfere with browser shortcuts
if (ev.ctrlKey || ev.altKey || ev.metaKey)
if (ev.ctrlKey || ev.altKey || ev.metaKey) {
return;
}

var help = document.getElementById("help");
switch (getVirtualKey(ev)) {
Expand Down Expand Up @@ -1457,36 +1460,38 @@
// Draw a convenient sidebar of known crates if we have a listing
if (rootPath === '../') {
var sidebar = document.getElementsByClassName('sidebar-elems')[0];
var div = document.createElement('div');
div.className = 'block crate';
div.innerHTML = '<h3>Crates</h3>';
var ul = document.createElement('ul');
div.appendChild(ul);

var crates = [];
for (var crate in rawSearchIndex) {
if (!rawSearchIndex.hasOwnProperty(crate)) {
continue;
if (sidebar) {
var div = document.createElement('div');
div.className = 'block crate';
div.innerHTML = '<h3>Crates</h3>';
var ul = document.createElement('ul');
div.appendChild(ul);

var crates = [];
for (var crate in rawSearchIndex) {
if (!rawSearchIndex.hasOwnProperty(crate)) {
continue;
}
crates.push(crate);
}
crates.push(crate);
}
crates.sort();
for (var i = 0; i < crates.length; ++i) {
var klass = 'crate';
if (crates[i] === window.currentCrate) {
klass += ' current';
crates.sort();
for (var i = 0; i < crates.length; ++i) {
var klass = 'crate';
if (crates[i] === window.currentCrate) {
klass += ' current';
}
var link = document.createElement('a');
link.href = '../' + crates[i] + '/index.html';
link.title = rawSearchIndex[crates[i]].doc;
link.className = klass;
link.textContent = crates[i];

var li = document.createElement('li');
li.appendChild(link);
ul.appendChild(li);
}
var link = document.createElement('a');
link.href = '../' + crates[i] + '/index.html';
link.title = rawSearchIndex[crates[i]].doc;
link.className = klass;
link.textContent = crates[i];

var li = document.createElement('li');
li.appendChild(link);
ul.appendChild(li);
sidebar.appendChild(div);
}
sidebar.appendChild(div);
}
}

Expand Down Expand Up @@ -1776,22 +1781,33 @@
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

function checkIfThereAreMethods(elems) {
var areThereMethods = false;

onEach(elems, function(e) {
if (hasClass(e, "method")) {
areThereMethods = true;
return true;
}
});
return areThereMethods;
}

var toggle = document.createElement('a');
toggle.href = 'javascript:void(0)';
toggle.className = 'collapse-toggle';
toggle.innerHTML = "[<span class='inner'>"+labelForToggleButton(false)+"</span>]";
toggle.innerHTML = "[<span class='inner'>" + labelForToggleButton(false) + "</span>]";

var func = function(e) {
var next = e.nextElementSibling;
if (!next) {
return;
}
if (hasClass(next, 'docblock') ||
(hasClass(next, 'stability') &&
hasClass(next.nextElementSibling, 'docblock'))) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
}
if (hasClass(e, 'impl')) {
if ((checkIfThereAreMethods(next.childNodes) || hasClass(e, 'method')) &&
(hasClass(next, 'docblock') ||
hasClass(e, 'impl') ||
(hasClass(next, 'stability') &&
hasClass(next.nextElementSibling, 'docblock')))) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ a {
.anchor.field {
left: -5px;
}
.small-section-header > .anchor {
left: -28px;
}
.anchor:before {
content: '\2002\00a7\2002';
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/rustdoc/fn-sidebar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![crate_name = "foo"]

// @has foo/fn.bar.html
// @has - '//*[@class="sidebar-elems"]' ''
pub fn bar() {}

// @has foo/constant.BAR.html
// @has - '//*[@class="sidebar-elems"]' ''
pub const BAR: u32 = 0;