Add missing items in the sidebar for functions

This commit is contained in:
Guillaume Gomez 2018-03-05 22:40:43 +01:00
parent a628543891
commit 6235ef0422
3 changed files with 70 additions and 54 deletions

View file

@ -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 ")?,
@ -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
@ -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(())
}

View file

@ -1457,36 +1457,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);
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;
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';
}
var link = document.createElement('a');
link.href = '../' + crates[i] + '/index.html';
link.title = rawSearchIndex[crates[i]].doc;
link.className = klass;
link.textContent = crates[i];
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 li = document.createElement('li');
li.appendChild(link);
ul.appendChild(li);
}
sidebar.appendChild(div);
}
sidebar.appendChild(div);
}
}

View file

@ -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;