提交 15e8c5d8 编写于 作者: B bors

Auto merge of #49412 - GuillaumeGomez:hide-type-decl, r=QuietMisdreavus

Hide type declarations by default

I'm not very happy for the moment about the rendering but the bases are here:

<img width="610" alt="screen shot 2018-03-27 at 11 56 27" src="https://user-images.githubusercontent.com/3050060/37960492-0e045954-31b6-11e8-9cea-1ef8a3f980c4.png">

r? @QuietMisdreavus
......@@ -1675,11 +1675,19 @@ fn src_href(&self) -> Option<String> {
}
}
fn wrap_into_docblock<F>(w: &mut fmt::Formatter,
f: F) -> fmt::Result
where F: Fn(&mut fmt::Formatter) -> fmt::Result {
write!(w, "<div class=\"docblock type-decl\">")?;
f(w)?;
write!(w, "</div>")
}
impl<'a> fmt::Display for Item<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
debug_assert!(!self.item.is_stripped());
// Write the breadcrumb trail header for the top
write!(fmt, "\n<h1 class='fqn'><span class='in-band'>")?;
write!(fmt, "<h1 class='fqn'><span class='in-band'>")?;
match self.item.inner {
clean::ModuleItem(ref m) => if m.is_crate {
write!(fmt, "Crate ")?;
......@@ -1741,14 +1749,11 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
}
}
write!(fmt, "</span>")?; // out-of-band
write!(fmt, "</h1>\n")?;
write!(fmt, "</span></h1>")?; // out-of-band
match self.item.inner {
clean::ModuleItem(ref m) => {
item_module(fmt, self.cx, self.item, &m.items)
}
clean::ModuleItem(ref m) =>
item_module(fmt, self.cx, self.item, &m.items),
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) =>
item_function(fmt, self.cx, self.item, f),
clean::TraitItem(ref t) => item_trait(fmt, self.cx, self.item, t),
......@@ -2306,7 +2311,13 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}
}
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::<Vec<_>>();
let required = t.items.iter().filter(|m| m.is_ty_method()).collect::<Vec<_>>();
let provided = t.items.iter().filter(|m| m.is_method()).collect::<Vec<_>>();
// Output the trait definition
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust trait'>")?;
render_attributes(w, it)?;
write!(w, "{}{}{}trait {}{}{}",
......@@ -2323,11 +2334,6 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, " ")?;
}
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::<Vec<_>>();
let required = t.items.iter().filter(|m| m.is_ty_method()).collect::<Vec<_>>();
let provided = t.items.iter().filter(|m| m.is_method()).collect::<Vec<_>>();
if t.items.is_empty() {
write!(w, "{{ }}")?;
} else {
......@@ -2378,7 +2384,8 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}
write!(w, "}}")?;
}
write!(w, "</pre>")?;
write!(w, "</pre>")
})?;
// Trait documentation
document(w, cx, it)?;
......@@ -2717,6 +2724,7 @@ fn method(w: &mut fmt::Formatter,
fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
s: &clean::Struct) -> fmt::Result {
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust struct'>")?;
render_attributes(w, it)?;
render_struct(w,
......@@ -2726,7 +2734,8 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
&s.fields,
"",
true)?;
write!(w, "</pre>")?;
write!(w, "</pre>")
})?;
document(w, cx, it)?;
let mut fields = s.fields.iter().filter_map(|f| {
......@@ -2769,6 +2778,7 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
s: &clean::Union) -> fmt::Result {
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust union'>")?;
render_attributes(w, it)?;
render_union(w,
......@@ -2777,7 +2787,8 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
&s.fields,
"",
true)?;
write!(w, "</pre>")?;
write!(w, "</pre>")
})?;
document(w, cx, it)?;
let mut fields = s.fields.iter().filter_map(|f| {
......@@ -2807,6 +2818,7 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
e: &clean::Enum) -> fmt::Result {
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust enum'>")?;
render_attributes(w, it)?;
write!(w, "{}enum {}{}{}",
......@@ -2856,7 +2868,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}
write!(w, "}}")?;
}
write!(w, "</pre>")?;
write!(w, "</pre>")
})?;
document(w, cx, it)?;
if !e.variants.is_empty() {
......@@ -4044,11 +4057,13 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn item_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
t: &clean::Macro) -> fmt::Result {
wrap_into_docblock(w, |w| {
w.write_str(&highlight::render_with_highlighting(&t.source,
Some("macro"),
None,
None,
None))?;
None))
})?;
document(w, cx, it)
}
......
......@@ -1845,11 +1845,16 @@
onEach(e.getElementsByClassName('associatedconstant'), func);
});
function createToggle() {
function createToggle(otherMessage) {
var span = document.createElement('span');
span.className = 'toggle-label';
span.style.display = 'none';
if (!otherMessage) {
span.innerHTML = '&nbsp;Expand&nbsp;description';
} else {
span.innerHTML = otherMessage;
span.style.fontSize = '20px';
}
var mainToggle = toggle.cloneNode(true);
mainToggle.appendChild(span);
......@@ -1862,7 +1867,14 @@
onEach(document.getElementById('main').getElementsByClassName('docblock'), function(e) {
if (e.parentNode.id === "main") {
e.parentNode.insertBefore(createToggle(), e);
var otherMessage;
if (hasClass(e, "type-decl")) {
otherMessage = '&nbsp;Show&nbsp;type&nbsp;declaration';
}
e.parentNode.insertBefore(createToggle(otherMessage), e);
if (otherMessage) {
collapseDocs(e.previousSibling.childNodes[0], "toggle");
}
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册