Skip to content

rustdoc: fold fields for enum struct variants into a docblock #37728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<h3 class='fields'>Fields</h3>\n
<table>")?;
let variant_id = derive_id(format!("{}.{}.fields",
ItemType::Variant,
variant.name.as_ref().unwrap()));
write!(w, "<span class='docblock autohide sub-variant' id='{id}'>",
id = variant_id)?;
write!(w, "<h3 class='fields'>Fields of <code>{name}</code></h3>\n
<table>", name = variant.name.as_ref().unwrap())?;
for field in &s.fields {
use clean::StructFieldItem;
if let StructFieldItem(ref ty) = field.inner {
Expand All @@ -2492,7 +2497,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "</td></tr>")?;
}
}
write!(w, "</table>")?;
write!(w, "</table></span>")?;
}
render_stability_since(w, variant, it)?;
}
Expand Down
16 changes: 16 additions & 0 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,22 @@
.html('&nbsp;Expand&nbsp;description'));
var wrapper = $("<div class='toggle-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(
$('<span/>', {'class': 'toggle-label'})
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down