From fff921672f8e679c42d0659c475ee57fddac13b6 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Fri, 11 Nov 2016 16:41:00 -0600 Subject: [PATCH] rustdoc: fold fields for enum struct variants into a docblock --- src/librustdoc/html/render.rs | 11 ++++++++--- src/librustdoc/html/static/main.js | 16 ++++++++++++++++ src/librustdoc/html/static/rustdoc.css | 8 ++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 2db771d7711..ddbdb28c2ad 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2467,8 +2467,13 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, if let clean::VariantItem(Variant { kind: VariantKind::Struct(ref s) }) = variant.inner { - write!(w, "

Fields

\n - ")?; + let variant_id = derive_id(format!("{}.{}.fields", + ItemType::Variant, + variant.name.as_ref().unwrap())); + write!(w, "", + id = variant_id)?; + write!(w, "

Fields of {name}

\n +
", name = variant.name.as_ref().unwrap())?; for field in &s.fields { use clean::StructFieldItem; if let StructFieldItem(ref ty) = field.inner { @@ -2492,7 +2497,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, "")?; } } - write!(w, "
")?; + write!(w, "")?; } render_stability_since(w, variant, it)?; } diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 474d2bbe7fc..5ffab949d01 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1013,6 +1013,22 @@ .html(' Expand description')); var wrapper = $("
").append(mainToggle); $("#main > .docblock").before(wrapper); + + $(".docblock.autohide").each(function() { + var wrap = $(this).prev(); + if (wrap.is(".toggle-wrapper")) { + var toggle = wrap.children().first(); + if ($(this).children().first().is("h3")) { + toggle.children(".toggle-label") + .text(" Show " + $(this).children().first().text()); + } + $(this).hide(); + wrap.addClass("collapsed"); + toggle.children(".inner").text(labelForToggleButton(true)); + toggle.children(".toggle-label").show(); + } + }); + var mainToggle = $(toggle).append( $('', {'class': 'toggle-label'}) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 46b34b5a638..35d43314c70 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -339,6 +339,10 @@ h4 > code, h3 > code, .invisible > code { border-bottom: 1px solid; } +.fields + table { + margin-bottom: 1em; +} + .content .item-list { list-style-type: none; padding: 0; @@ -663,6 +667,10 @@ span.since { margin-top: 5px; } +.sub-variant, .sub-variant > h3 { + margin-top: 0 !important; +} + .enum > .toggle-wrapper + .docblock, .struct > .toggle-wrapper + .docblock { margin-left: 30px; margin-bottom: 20px;