Skip to content

Commit e7f1880

Browse files
committed
Auto merge of #52962 - GuillaumeGomez:few-things, r=QuietMisdreavus
Fix trait item doc setting, add new setting, start hiding elements by default and then showing them up r? @QuietMisdreavus
2 parents 4f921d7 + e1ec055 commit e7f1880

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

src/librustdoc/html/render.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@ impl<'a> Settings<'a> {
16671667
("item-attributes", "Auto-hide item attributes.", true),
16681668
("trait-implementations", "Auto-hide trait implementations documentation",
16691669
true),
1670+
("method-docs", "Auto-hide item methods' documentation", false),
16701671
("go-to-only-result", "Directly go to item in search if there is only one result",
16711672
false),
16721673
],
@@ -2074,7 +2075,7 @@ impl<'a> Item<'a> {
20742075
fn wrap_into_docblock<F>(w: &mut fmt::Formatter,
20752076
f: F) -> fmt::Result
20762077
where F: Fn(&mut fmt::Formatter) -> fmt::Result {
2077-
write!(w, "<div class=\"docblock type-decl\">")?;
2078+
write!(w, "<div class=\"docblock type-decl hidden-by-usual-hider\">")?;
20782079
f(w)?;
20792080
write!(w, "</div>")
20802081
}

src/librustdoc/html/static/main.js

+34-9
Original file line numberDiff line numberDiff line change
@@ -1979,18 +1979,29 @@
19791979
if (collapse) {
19801980
toggleAllDocs(pageId, true);
19811981
}
1982-
if (getCurrentValue('rustdoc-trait-implementations') !== "false") {
1983-
onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
1982+
var collapser = function(e) {
19841983
// inherent impl ids are like 'impl' or impl-<number>'.
19851984
// they will never be hidden by default.
1986-
var n = e.parentNode;
1985+
var n = e.parentElement;
19871986
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
19881987
// Automatically minimize all non-inherent impls
19891988
if (collapse || hasClass(n, 'impl')) {
19901989
collapseDocs(e, "hide", pageId);
19911990
}
19921991
}
1993-
});
1992+
};
1993+
if (getCurrentValue('rustdoc-trait-implementations') !== "false") {
1994+
onEach(document.getElementById('implementations-list')
1995+
.getElementsByClassName("collapse-toggle"), collapser);
1996+
}
1997+
if (getCurrentValue('rustdoc-method-docs') !== "false") {
1998+
var implItems = document.getElementsByClassName('impl-items');
1999+
2000+
if (implItems && implItems.length > 0) {
2001+
onEach(implItems, function(elem) {
2002+
onEach(elem.getElementsByClassName("collapse-toggle"), collapser);
2003+
});
2004+
}
19942005
}
19952006
}
19962007

@@ -2041,10 +2052,12 @@
20412052
onEach(document.getElementsByClassName('associatedconstant'), func);
20422053
onEach(document.getElementsByClassName('impl'), func);
20432054

2044-
function createToggle(otherMessage, fontSize, extraClass) {
2055+
function createToggle(otherMessage, fontSize, extraClass, show) {
20452056
var span = document.createElement('span');
20462057
span.className = 'toggle-label';
2047-
span.style.display = 'none';
2058+
if (show) {
2059+
span.style.display = 'none';
2060+
}
20482061
if (!otherMessage) {
20492062
span.innerHTML = '&nbsp;Expand&nbsp;description';
20502063
} else {
@@ -2060,8 +2073,15 @@
20602073

20612074
var wrapper = document.createElement('div');
20622075
wrapper.className = 'toggle-wrapper';
2076+
if (!show) {
2077+
addClass(wrapper, 'collapsed');
2078+
var inner = mainToggle.getElementsByClassName('inner');
2079+
if (inner && inner.length > 0) {
2080+
inner[0].innerHTML = '+';
2081+
}
2082+
}
20632083
if (extraClass) {
2064-
wrapper.className += ' ' + extraClass;
2084+
addClass(wrapper, extraClass);
20652085
}
20662086
wrapper.appendChild(mainToggle);
20672087
return wrapper;
@@ -2093,10 +2113,15 @@
20932113
var otherMessage;
20942114
var fontSize;
20952115
var extraClass;
2116+
var show = true;
20962117

20972118
if (hasClass(e, "type-decl")) {
20982119
fontSize = "20px";
20992120
otherMessage = '&nbsp;Show&nbsp;declaration';
2121+
show = getCurrentValue('rustdoc-item-declarations') === "false";
2122+
if (!show) {
2123+
extraClass = 'collapsed';
2124+
}
21002125
} else if (hasClass(e, "non-exhaustive")) {
21012126
otherMessage = '&nbsp;This&nbsp;';
21022127
if (hasClass(e, "non-exhaustive-struct")) {
@@ -2111,8 +2136,8 @@
21112136
extraClass = "marg-left";
21122137
}
21132138

2114-
e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass), e);
2115-
if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") {
2139+
e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass, show), e);
2140+
if (otherMessage && show) {
21162141
collapseDocs(e.previousSibling.childNodes[0], "toggle");
21172142
}
21182143
}

0 commit comments

Comments
 (0)