-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Sidebar unification #84834
Merged
Merged
Sidebar unification #84834
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dab01a0
* Put crates list at all levels
GuillaumeGomez bc888ba
Add sidebar GUI tests
GuillaumeGomez e9b1283
Add some commented options that could be useful for other contributor…
GuillaumeGomez 5a87482
Update rustdoc test
GuillaumeGomez e081cd4
Remove unneeded file to load sidebar items at crate level
GuillaumeGomez a2ba9ef
Only list crates on the crate page
GuillaumeGomez 9b637fa
Improve display of the separation between page items and siblings in …
GuillaumeGomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -561,41 +561,40 @@ function hideThemeButtonState() { | |
} | ||
}()); | ||
|
||
function addSidebarCrates(crates) { | ||
// 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"); | ||
div.className = "block crate"; | ||
div.innerHTML = "<h3>Crates</h3>"; | ||
var ul = document.createElement("ul"); | ||
div.appendChild(ul); | ||
|
||
for (var i = 0; i < crates.length; ++i) { | ||
var klass = "crate"; | ||
if (window.rootPath !== "./" && crates[i] === window.currentCrate) { | ||
klass += " current"; | ||
} | ||
var link = document.createElement("a"); | ||
link.href = window.rootPath + crates[i] + "/index.html"; | ||
link.className = klass; | ||
link.textContent = crates[i]; | ||
|
||
var li = document.createElement("li"); | ||
li.appendChild(link); | ||
ul.appendChild(li); | ||
} | ||
sidebar.appendChild(div); | ||
} | ||
} | ||
} | ||
|
||
// delayed sidebar rendering. | ||
window.initSidebarItems = function(items) { | ||
var sidebar = document.getElementsByClassName("sidebar-elems")[0]; | ||
var current = window.sidebarCurrent; | ||
|
||
function addSidebarCrates(crates) { | ||
if (!hasClass(document.body, "crate")) { | ||
// We only want to list crates on the crate page. | ||
return; | ||
} | ||
// Draw a convenient sidebar of known crates if we have a listing | ||
var div = document.createElement("div"); | ||
div.className = "block crate"; | ||
div.innerHTML = "<h3>Crates</h3>"; | ||
var ul = document.createElement("ul"); | ||
div.appendChild(ul); | ||
|
||
for (var i = 0; i < crates.length; ++i) { | ||
var klass = "crate"; | ||
if (window.rootPath !== "./" && crates[i] === window.currentCrate) { | ||
klass += " current"; | ||
} | ||
var link = document.createElement("a"); | ||
link.href = window.rootPath + crates[i] + "/index.html"; | ||
link.className = klass; | ||
link.textContent = crates[i]; | ||
|
||
var li = document.createElement("li"); | ||
li.appendChild(link); | ||
ul.appendChild(li); | ||
} | ||
sidebar.appendChild(div); | ||
} | ||
|
||
function block(shortty, longty) { | ||
var filtered = items[shortty]; | ||
if (!filtered) { | ||
|
@@ -634,28 +633,32 @@ function hideThemeButtonState() { | |
ul.appendChild(li); | ||
} | ||
div.appendChild(ul); | ||
if (sidebar) { | ||
sidebar.appendChild(div); | ||
} | ||
sidebar.appendChild(div); | ||
} | ||
|
||
block("primitive", "Primitive Types"); | ||
block("mod", "Modules"); | ||
block("macro", "Macros"); | ||
block("struct", "Structs"); | ||
block("enum", "Enums"); | ||
block("union", "Unions"); | ||
block("constant", "Constants"); | ||
block("static", "Statics"); | ||
block("trait", "Traits"); | ||
block("fn", "Functions"); | ||
block("type", "Type Definitions"); | ||
block("foreigntype", "Foreign Types"); | ||
block("keyword", "Keywords"); | ||
block("traitalias", "Trait Aliases"); | ||
|
||
// `crates{version}.js` should always be loaded before this script, so we can use it safely. | ||
addSidebarCrates(window.ALL_CRATES); | ||
if (sidebar) { | ||
var isModule = hasClass(document.body, "mod"); | ||
if (!isModule) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to render these info on a module (they are already on listed on its page). |
||
block("primitive", "Primitive Types"); | ||
block("mod", "Modules"); | ||
block("macro", "Macros"); | ||
block("struct", "Structs"); | ||
block("enum", "Enums"); | ||
block("union", "Unions"); | ||
block("constant", "Constants"); | ||
block("static", "Statics"); | ||
block("trait", "Traits"); | ||
block("fn", "Functions"); | ||
block("type", "Type Definitions"); | ||
block("foreigntype", "Foreign Types"); | ||
block("keyword", "Keywords"); | ||
block("traitalias", "Trait Aliases"); | ||
} | ||
|
||
// `crates{version}.js` should always be loaded before this script, so we can use | ||
// it safely. | ||
addSidebarCrates(window.ALL_CRATES); | ||
} | ||
}; | ||
|
||
window.register_implementors = function(imp) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
goto: file://|DOC_PATH|/test_docs/index.html | ||
assert: (".sidebar > .location", "Crate test_docs") | ||
// In modules, we only have one "location" element. | ||
assert: (".sidebar .location", 1) | ||
assert: (".sidebar-elems > #all-types", "See all test_docs's items") | ||
// We check that we have the crates list and that the "current" on is "test_docs". | ||
assert: (".sidebar-elems > .crate > ul > li > a.current", "test_docs") | ||
// And we're also supposed to have the list of items in the current module. | ||
assert: (".sidebar-elems > .items > ul > li:nth-child(1)", "Modules") | ||
assert: (".sidebar-elems > .items > ul > li:nth-child(2)", "Structs") | ||
assert: (".sidebar-elems > .items > ul > li:nth-child(3)", "Enums") | ||
assert: (".sidebar-elems > .items > ul > li:nth-child(4)", "Traits") | ||
assert: (".sidebar-elems > .items > ul > li:nth-child(5)", "Functions") | ||
assert: (".sidebar-elems > .items > ul > li:nth-child(6)", "Keywords") | ||
assert: ("#structs + table td > a", "Foo") | ||
click: "#structs + table td > a" | ||
|
||
// PAGE: struct.Foo.html | ||
assert: (".sidebar .location", 2) | ||
// We check that there is no crate listed outside of the top level. | ||
assert-false: ".sidebar-elems > .crate" | ||
// We now go back to the crate page to click on the "lib2" crate link. | ||
goto: file://|DOC_PATH|/test_docs/index.html | ||
click: ".sidebar-elems > .crate > ul > li:first-child > a" | ||
|
||
// PAGE: lib2/index.html | ||
goto: file://|DOC_PATH|/lib2/index.html | ||
assert: (".sidebar > .location", "Crate lib2") | ||
// We check that we have the crates list and that the "current" on is now "lib2". | ||
assert: (".sidebar-elems > .crate > ul > li > a.current", "lib2") | ||
// We now go to the "foobar" function page. | ||
assert: (".sidebar-elems > .items > ul > li:nth-child(1)", "Modules") | ||
assert: (".sidebar-elems > .items > ul > li:nth-child(2)", "Functions") | ||
assert: ("#functions + table td > a", "foobar") | ||
click: "#functions + table td > a" | ||
|
||
// PAGE: fn.foobar.html | ||
// In items containing no items (like functions or constants) and in modules, we have one | ||
// "location" elements. | ||
assert: (".sidebar .location", 1) | ||
// There is a "<br>" tag between "in" and "lib2", but it doesn't count as a space. | ||
assert: (".sidebar .sidebar-elems .location", "Other items inlib2") | ||
// We check that we don't have the crate list. | ||
assert-false: ".sidebar-elems > .crate" | ||
|
||
goto: ./module/index.html | ||
assert: (".sidebar > .location", "Module module") | ||
// We check that we don't have the crate list. | ||
assert-false: ".sidebar-elems > .crate" | ||
|
||
goto: ./sub_module/sub_sub_module/index.html | ||
assert: (".sidebar > .location", "Module sub_sub_module") | ||
// We check that we don't have the crate list. | ||
assert-false: ".sidebar-elems > .crate" | ||
assert: (".sidebar-elems > .items > ul > li:nth-child(1)", "Functions") | ||
assert: ("#functions + table td > a", "foo") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pub mod module { | ||
pub mod sub_module { | ||
pub mod sub_sub_module { | ||
pub fn foo() {} | ||
} | ||
pub fn bar() {} | ||
} | ||
pub fn whatever() {} | ||
} | ||
|
||
pub fn foobar() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this function here so it has access to the
sidebar
variable from the scope instead of querying it like before.