1
Fork 0

Hide type declarations by default

This commit is contained in:
Guillaume Gomez 2018-03-27 11:57:00 +02:00
parent 184156ed97
commit 73b97c7e7c
2 changed files with 166 additions and 139 deletions

View file

@ -1675,11 +1675,19 @@ impl<'a> Item<'a> {
} }
} }
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> { impl<'a> fmt::Display for Item<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
debug_assert!(!self.item.is_stripped()); debug_assert!(!self.item.is_stripped());
// Write the breadcrumb trail header for the top // 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 { match self.item.inner {
clean::ModuleItem(ref m) => if m.is_crate { clean::ModuleItem(ref m) => if m.is_crate {
write!(fmt, "Crate ")?; write!(fmt, "Crate ")?;
@ -1741,14 +1749,11 @@ impl<'a> fmt::Display for Item<'a> {
} }
} }
write!(fmt, "</span>")?; // out-of-band write!(fmt, "</span></h1>")?; // out-of-band
write!(fmt, "</h1>\n")?;
match self.item.inner { match self.item.inner {
clean::ModuleItem(ref m) => { clean::ModuleItem(ref m) =>
item_module(fmt, self.cx, self.item, &m.items) item_module(fmt, self.cx, self.item, &m.items),
}
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) => clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) =>
item_function(fmt, self.cx, self.item, f), item_function(fmt, self.cx, self.item, f),
clean::TraitItem(ref t) => item_trait(fmt, self.cx, self.item, t), 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 // Output the trait definition
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust trait'>")?; write!(w, "<pre class='rust trait'>")?;
render_attributes(w, it)?; render_attributes(w, it)?;
write!(w, "{}{}{}trait {}{}{}", write!(w, "{}{}{}trait {}{}{}",
@ -2323,11 +2334,6 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, " ")?; 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() { if t.items.is_empty() {
write!(w, "{{ }}")?; write!(w, "{{ }}")?;
} else { } else {
@ -2378,7 +2384,8 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
} }
write!(w, "}}")?; write!(w, "}}")?;
} }
write!(w, "</pre>")?; write!(w, "</pre>")
})?;
// Trait documentation // Trait documentation
document(w, cx, it)?; document(w, cx, it)?;
@ -2717,6 +2724,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
s: &clean::Struct) -> fmt::Result { s: &clean::Struct) -> fmt::Result {
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust struct'>")?; write!(w, "<pre class='rust struct'>")?;
render_attributes(w, it)?; render_attributes(w, it)?;
render_struct(w, render_struct(w,
@ -2726,7 +2734,8 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
&s.fields, &s.fields,
"", "",
true)?; true)?;
write!(w, "</pre>")?; write!(w, "</pre>")
})?;
document(w, cx, it)?; document(w, cx, it)?;
let mut fields = s.fields.iter().filter_map(|f| { 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, fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
s: &clean::Union) -> fmt::Result { s: &clean::Union) -> fmt::Result {
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust union'>")?; write!(w, "<pre class='rust union'>")?;
render_attributes(w, it)?; render_attributes(w, it)?;
render_union(w, render_union(w,
@ -2777,7 +2787,8 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
&s.fields, &s.fields,
"", "",
true)?; true)?;
write!(w, "</pre>")?; write!(w, "</pre>")
})?;
document(w, cx, it)?; document(w, cx, it)?;
let mut fields = s.fields.iter().filter_map(|f| { 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, fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
e: &clean::Enum) -> fmt::Result { e: &clean::Enum) -> fmt::Result {
wrap_into_docblock(w, |w| {
write!(w, "<pre class='rust enum'>")?; write!(w, "<pre class='rust enum'>")?;
render_attributes(w, it)?; render_attributes(w, it)?;
write!(w, "{}enum {}{}{}", write!(w, "{}enum {}{}{}",
@ -2856,7 +2868,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
} }
write!(w, "}}")?; write!(w, "}}")?;
} }
write!(w, "</pre>")?; write!(w, "</pre>")
})?;
document(w, cx, it)?; document(w, cx, it)?;
if !e.variants.is_empty() { if !e.variants.is_empty() {
@ -4043,11 +4056,13 @@ impl<'a> fmt::Display for Source<'a> {
fn item_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, fn item_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
t: &clean::Macro) -> fmt::Result { t: &clean::Macro) -> fmt::Result {
wrap_into_docblock(w, |w| {
w.write_str(&highlight::render_with_highlighting(&t.source, w.write_str(&highlight::render_with_highlighting(&t.source,
Some("macro"), Some("macro"),
None, None,
None, None,
None))?; None))
})?;
document(w, cx, it) document(w, cx, it)
} }

View file

@ -1833,11 +1833,16 @@
onEach(e.getElementsByClassName('associatedconstant'), func); onEach(e.getElementsByClassName('associatedconstant'), func);
}); });
function createToggle() { function createToggle(otherMessage) {
var span = document.createElement('span'); var span = document.createElement('span');
span.className = 'toggle-label'; span.className = 'toggle-label';
span.style.display = 'none'; span.style.display = 'none';
if (!otherMessage) {
span.innerHTML = '&nbsp;Expand&nbsp;description'; span.innerHTML = '&nbsp;Expand&nbsp;description';
} else {
span.innerHTML = otherMessage;
span.style.fontSize = '20px';
}
var mainToggle = toggle.cloneNode(true); var mainToggle = toggle.cloneNode(true);
mainToggle.appendChild(span); mainToggle.appendChild(span);
@ -1850,7 +1855,14 @@
onEach(document.getElementById('main').getElementsByClassName('docblock'), function(e) { onEach(document.getElementById('main').getElementsByClassName('docblock'), function(e) {
if (e.parentNode.id === "main") { 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");
}
} }
}); });