Skip to content

Commit 2462cdb

Browse files
Fix trait item doc setting, add new setting, start hiding elements by default and then showing them up
1 parent 75af9df commit 2462cdb

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

src/librustdoc/html/render.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,7 @@ impl<'a> Settings<'a> {
16741674
("item-attributes", "Auto-hide item attributes.", true),
16751675
("trait-implementations", "Auto-hide trait implementations documentation",
16761676
true),
1677+
("method-docs", "Auto-hide item methods' documentation", false),
16771678
("go-to-only-result", "Directly go to item in search if there is only one result",
16781679
false),
16791680
],
@@ -2073,7 +2074,7 @@ impl<'a> Item<'a> {
20732074
fn wrap_into_docblock<F>(w: &mut fmt::Formatter,
20742075
f: F) -> fmt::Result
20752076
where F: Fn(&mut fmt::Formatter) -> fmt::Result {
2076-
write!(w, "<div class=\"docblock type-decl\">")?;
2077+
write!(w, "<div class=\"docblock type-decl hidden-by-usual-hider\">")?;
20772078
f(w)?;
20782079
write!(w, "</div>")
20792080
}

src/librustdoc/html/static/main.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,18 +1938,27 @@
19381938
if (collapse) {
19391939
toggleAllDocs(pageId, true);
19401940
}
1941-
if (getCurrentValue('rustdoc-trait-implementations') !== "false") {
1942-
onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
1941+
var collapser = function(e) {
19431942
// inherent impl ids are like 'impl' or impl-<number>'.
19441943
// they will never be hidden by default.
1945-
var n = e.parentNode;
1944+
var n = e.parentElement;
19461945
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
19471946
// Automatically minimize all non-inherent impls
19481947
if (collapse || hasClass(n, 'impl')) {
19491948
collapseDocs(e, "hide", pageId);
19501949
}
19511950
}
1952-
});
1951+
};
1952+
if (getCurrentValue('rustdoc-trait-implementations') !== "false") {
1953+
onEach(document.getElementById('implementations-list')
1954+
.getElementsByClassName("collapse-toggle"), collapser);
1955+
}
1956+
if (getCurrentValue('rustdoc-method-docs') !== "false") {
1957+
var implItems = document.getElementsByClassName('impl-items');
1958+
1959+
if (implItems && implItems.length > 0) {
1960+
onEach(implItems[0].getElementsByClassName("collapse-toggle"), collapser);
1961+
}
19531962
}
19541963
}
19551964

@@ -2001,10 +2010,12 @@
20012010
onEach(e.getElementsByClassName('associatedconstant'), func);
20022011
});
20032012

2004-
function createToggle(otherMessage, fontSize, extraClass) {
2013+
function createToggle(otherMessage, fontSize, extraClass, show) {
20052014
var span = document.createElement('span');
20062015
span.className = 'toggle-label';
2007-
span.style.display = 'none';
2016+
if (show) {
2017+
span.style.display = 'none';
2018+
}
20082019
if (!otherMessage) {
20092020
span.innerHTML = '&nbsp;Expand&nbsp;description';
20102021
} else {
@@ -2020,8 +2031,15 @@
20202031

20212032
var wrapper = document.createElement('div');
20222033
wrapper.className = 'toggle-wrapper';
2034+
if (!show) {
2035+
addClass(wrapper, 'collapsed');
2036+
var inner = mainToggle.getElementsByClassName('inner');
2037+
if (inner && inner.length > 0) {
2038+
inner[0].innerHTML = '+';
2039+
}
2040+
}
20232041
if (extraClass) {
2024-
wrapper.className += ' ' + extraClass;
2042+
addClass(wrapper, extraClass);
20252043
}
20262044
wrapper.appendChild(mainToggle);
20272045
return wrapper;
@@ -2053,10 +2071,15 @@
20532071
var otherMessage;
20542072
var fontSize;
20552073
var extraClass;
2074+
var show = true;
20562075

20572076
if (hasClass(e, "type-decl")) {
20582077
fontSize = "20px";
20592078
otherMessage = '&nbsp;Show&nbsp;declaration';
2079+
show = getCurrentValue('rustdoc-item-declarations') === "false";
2080+
if (!show) {
2081+
extraClass = 'collapsed';
2082+
}
20602083
} else if (hasClass(e, "non-exhaustive")) {
20612084
otherMessage = '&nbsp;This&nbsp;';
20622085
if (hasClass(e, "non-exhaustive-struct")) {
@@ -2071,8 +2094,8 @@
20712094
extraClass = "marg-left";
20722095
}
20732096

2074-
e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass), e);
2075-
if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") {
2097+
e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass, show), e);
2098+
if (otherMessage && show) {
20762099
collapseDocs(e.previousSibling.childNodes[0], "toggle");
20772100
}
20782101
}

0 commit comments

Comments
 (0)