* Put crates list at all levels
* Fix bug in module sidebar: the list of items was from the parent module
This commit is contained in:
parent
dc08641128
commit
dab01a05fb
5 changed files with 80 additions and 89 deletions
|
@ -526,7 +526,6 @@ impl Item {
|
||||||
crate fn is_crate(&self) -> bool {
|
crate fn is_crate(&self) -> bool {
|
||||||
self.is_mod() && self.def_id.as_real().map_or(false, |did| did.index == CRATE_DEF_INDEX)
|
self.is_mod() && self.def_id.as_real().map_or(false, |did| did.index == CRATE_DEF_INDEX)
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn is_mod(&self) -> bool {
|
crate fn is_mod(&self) -> bool {
|
||||||
self.type_() == ItemType::Module
|
self.type_() == ItemType::Module
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ crate fn render<T: Print, S: Print>(
|
||||||
{after_content}\
|
{after_content}\
|
||||||
<div id=\"rustdoc-vars\" data-root-path=\"{root_path}\" data-current-crate=\"{krate}\" \
|
<div id=\"rustdoc-vars\" data-root-path=\"{root_path}\" data-current-crate=\"{krate}\" \
|
||||||
data-search-index-js=\"{root_path}search-index{suffix}.js\" \
|
data-search-index-js=\"{root_path}search-index{suffix}.js\" \
|
||||||
data-search-js=\"{static_root_path}search{suffix}.js\"></div>
|
data-search-js=\"{static_root_path}search{suffix}.js\"></div>\
|
||||||
<script src=\"{static_root_path}main{suffix}.js\"></script>\
|
<script src=\"{static_root_path}main{suffix}.js\"></script>\
|
||||||
{extra_scripts}\
|
{extra_scripts}\
|
||||||
</body>\
|
</body>\
|
||||||
|
|
|
@ -1703,7 +1703,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
|
||||||
"<div class=\"block version\">\
|
"<div class=\"block version\">\
|
||||||
<p>Version {}</p>\
|
<p>Version {}</p>\
|
||||||
</div>",
|
</div>",
|
||||||
Escape(version)
|
Escape(version),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1713,9 +1713,10 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
|
||||||
write!(
|
write!(
|
||||||
buffer,
|
buffer,
|
||||||
"<a id=\"all-types\" href=\"all.html\"><p>See all {}'s items</p></a>",
|
"<a id=\"all-types\" href=\"all.html\"><p>See all {}'s items</p></a>",
|
||||||
it.name.as_ref().expect("crates always have a name")
|
it.name.as_ref().expect("crates always have a name"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
match *it.kind {
|
match *it.kind {
|
||||||
clean::StructItem(ref s) => sidebar_struct(cx, buffer, it, s),
|
clean::StructItem(ref s) => sidebar_struct(cx, buffer, it, s),
|
||||||
clean::TraitItem(ref t) => sidebar_trait(cx, buffer, it, t),
|
clean::TraitItem(ref t) => sidebar_trait(cx, buffer, it, t),
|
||||||
|
@ -1725,7 +1726,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
|
||||||
clean::TypedefItem(_, _) => sidebar_typedef(cx, buffer, it),
|
clean::TypedefItem(_, _) => sidebar_typedef(cx, buffer, it),
|
||||||
clean::ModuleItem(ref m) => sidebar_module(buffer, &m.items),
|
clean::ModuleItem(ref m) => sidebar_module(buffer, &m.items),
|
||||||
clean::ForeignTypeItem => sidebar_foreign_type(cx, buffer, it),
|
clean::ForeignTypeItem => sidebar_foreign_type(cx, buffer, it),
|
||||||
_ => (),
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The sidebar is designed to display sibling functions, modules and
|
// The sidebar is designed to display sibling functions, modules and
|
||||||
|
@ -1736,6 +1737,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
|
||||||
// as much HTML as possible in order to allow non-JS-enabled browsers
|
// as much HTML as possible in order to allow non-JS-enabled browsers
|
||||||
// to navigate the documentation (though slightly inefficiently).
|
// to navigate the documentation (though slightly inefficiently).
|
||||||
|
|
||||||
|
if !it.is_mod() {
|
||||||
buffer.write_str("<p class=\"location\">");
|
buffer.write_str("<p class=\"location\">");
|
||||||
for (i, name) in cx.current.iter().take(parentlen).enumerate() {
|
for (i, name) in cx.current.iter().take(parentlen).enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
|
@ -1749,9 +1751,10 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
buffer.write_str("</p>");
|
buffer.write_str("</p>");
|
||||||
|
}
|
||||||
|
|
||||||
// Sidebar refers to the enclosing module, not this module.
|
// Sidebar refers to the enclosing module, not this module.
|
||||||
let relpath = if it.is_mod() { "../" } else { "" };
|
let relpath = if it.is_mod() && parentlen != 0 { "./" } else { "" };
|
||||||
write!(
|
write!(
|
||||||
buffer,
|
buffer,
|
||||||
"<div id=\"sidebar-vars\" data-name=\"{name}\" data-ty=\"{ty}\" data-relpath=\"{path}\">\
|
"<div id=\"sidebar-vars\" data-name=\"{name}\" data-ty=\"{ty}\" data-relpath=\"{path}\">\
|
||||||
|
@ -1760,17 +1763,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
|
||||||
ty = it.type_(),
|
ty = it.type_(),
|
||||||
path = relpath
|
path = relpath
|
||||||
);
|
);
|
||||||
|
|
||||||
if parentlen == 0 {
|
|
||||||
write!(
|
|
||||||
buffer,
|
|
||||||
"<script defer src=\"{}sidebar-items{}.js\"></script>",
|
|
||||||
relpath, cx.shared.resource_suffix
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
write!(buffer, "<script defer src=\"{}sidebar-items.js\"></script>", relpath);
|
write!(buffer, "<script defer src=\"{}sidebar-items.js\"></script>", relpath);
|
||||||
}
|
|
||||||
|
|
||||||
// Closes sidebar-elems div.
|
// Closes sidebar-elems div.
|
||||||
buffer.write_str("</div>");
|
buffer.write_str("</div>");
|
||||||
}
|
}
|
||||||
|
@ -2278,8 +2271,8 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_ty_to_strs(ty: &ItemType) -> (&'static str, &'static str) {
|
fn item_ty_to_strs(ty: ItemType) -> (&'static str, &'static str) {
|
||||||
match *ty {
|
match ty {
|
||||||
ItemType::ExternCrate | ItemType::Import => ("reexports", "Re-exports"),
|
ItemType::ExternCrate | ItemType::Import => ("reexports", "Re-exports"),
|
||||||
ItemType::Module => ("modules", "Modules"),
|
ItemType::Module => ("modules", "Modules"),
|
||||||
ItemType::Struct => ("structs", "Structs"),
|
ItemType::Struct => ("structs", "Structs"),
|
||||||
|
@ -2311,10 +2304,14 @@ fn item_ty_to_strs(ty: &ItemType) -> (&'static str, &'static str) {
|
||||||
fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
|
fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
|
||||||
let mut sidebar = String::new();
|
let mut sidebar = String::new();
|
||||||
|
|
||||||
|
// Re-exports are handled a bit differently because they can be extern crates or imports.
|
||||||
if items.iter().any(|it| {
|
if items.iter().any(|it| {
|
||||||
it.type_() == ItemType::ExternCrate || (it.type_() == ItemType::Import && !it.is_stripped())
|
it.name.is_some()
|
||||||
|
&& (it.type_() == ItemType::ExternCrate
|
||||||
|
|| (it.type_() == ItemType::Import && !it.is_stripped()))
|
||||||
}) {
|
}) {
|
||||||
sidebar.push_str("<li><a href=\"#reexports\">Re-exports</a></li>");
|
let (id, name) = item_ty_to_strs(ItemType::Import);
|
||||||
|
sidebar.push_str(&format!("<li><a href=\"#{}\">{}</a></li>", id, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ordering taken from item_module, reorder, where it prioritized elements in a certain order
|
// ordering taken from item_module, reorder, where it prioritized elements in a certain order
|
||||||
|
@ -2341,13 +2338,9 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
|
||||||
ItemType::ForeignType,
|
ItemType::ForeignType,
|
||||||
ItemType::Keyword,
|
ItemType::Keyword,
|
||||||
] {
|
] {
|
||||||
if items.iter().any(|it| !it.is_stripped() && it.type_() == myty) {
|
if items.iter().any(|it| !it.is_stripped() && it.type_() == myty && it.name.is_some()) {
|
||||||
let (short, name) = item_ty_to_strs(&myty);
|
let (id, name) = item_ty_to_strs(myty);
|
||||||
sidebar.push_str(&format!(
|
sidebar.push_str(&format!("<li><a href=\"#{}\">{}</a></li>", id, name));
|
||||||
"<li><a href=\"#{id}\">{name}</a></li>",
|
|
||||||
id = short,
|
|
||||||
name = name
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,7 +262,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
|
||||||
w.write_str("</table>");
|
w.write_str("</table>");
|
||||||
}
|
}
|
||||||
curty = myty;
|
curty = myty;
|
||||||
let (short, name) = item_ty_to_strs(&myty.unwrap());
|
let (short, name) = item_ty_to_strs(myty.unwrap());
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
"<h2 id=\"{id}\" class=\"section-header\">\
|
"<h2 id=\"{id}\" class=\"section-header\">\
|
||||||
|
|
|
@ -561,11 +561,14 @@ function hideThemeButtonState() {
|
||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
// delayed sidebar rendering.
|
||||||
|
window.initSidebarItems = function(items) {
|
||||||
|
var sidebar = document.getElementsByClassName("sidebar-elems")[0];
|
||||||
|
var current = window.sidebarCurrent;
|
||||||
|
var isModule = hasClass(document.body, "mod");
|
||||||
|
|
||||||
function addSidebarCrates(crates) {
|
function addSidebarCrates(crates) {
|
||||||
// Draw a convenient sidebar of known crates if we have a listing
|
// Draw a convenient sidebar of known crates if we have a listing
|
||||||
if (window.rootPath === "../" || window.rootPath === "./") {
|
|
||||||
var sidebar = document.getElementsByClassName("sidebar-elems")[0];
|
|
||||||
if (sidebar) {
|
|
||||||
var div = document.createElement("div");
|
var div = document.createElement("div");
|
||||||
div.className = "block crate";
|
div.className = "block crate";
|
||||||
div.innerHTML = "<h3>Crates</h3>";
|
div.innerHTML = "<h3>Crates</h3>";
|
||||||
|
@ -588,13 +591,6 @@ function hideThemeButtonState() {
|
||||||
}
|
}
|
||||||
sidebar.appendChild(div);
|
sidebar.appendChild(div);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// delayed sidebar rendering.
|
|
||||||
window.initSidebarItems = function(items) {
|
|
||||||
var sidebar = document.getElementsByClassName("sidebar-elems")[0];
|
|
||||||
var current = window.sidebarCurrent;
|
|
||||||
|
|
||||||
function block(shortty, longty) {
|
function block(shortty, longty) {
|
||||||
var filtered = items[shortty];
|
var filtered = items[shortty];
|
||||||
|
@ -634,11 +630,11 @@ function hideThemeButtonState() {
|
||||||
ul.appendChild(li);
|
ul.appendChild(li);
|
||||||
}
|
}
|
||||||
div.appendChild(ul);
|
div.appendChild(ul);
|
||||||
if (sidebar) {
|
|
||||||
sidebar.appendChild(div);
|
sidebar.appendChild(div);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if (sidebar) {
|
||||||
|
if (!isModule) {
|
||||||
block("primitive", "Primitive Types");
|
block("primitive", "Primitive Types");
|
||||||
block("mod", "Modules");
|
block("mod", "Modules");
|
||||||
block("macro", "Macros");
|
block("macro", "Macros");
|
||||||
|
@ -653,9 +649,12 @@ function hideThemeButtonState() {
|
||||||
block("foreigntype", "Foreign Types");
|
block("foreigntype", "Foreign Types");
|
||||||
block("keyword", "Keywords");
|
block("keyword", "Keywords");
|
||||||
block("traitalias", "Trait Aliases");
|
block("traitalias", "Trait Aliases");
|
||||||
|
}
|
||||||
|
|
||||||
// `crates{version}.js` should always be loaded before this script, so we can use it safely.
|
// `crates{version}.js` should always be loaded before this script, so we can use
|
||||||
|
// it safely.
|
||||||
addSidebarCrates(window.ALL_CRATES);
|
addSidebarCrates(window.ALL_CRATES);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.register_implementors = function(imp) {
|
window.register_implementors = function(imp) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue