Skip to content
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
53 changes: 45 additions & 8 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2492,18 +2492,55 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
Ok(())
}

fn attribute_without_value(s: &str) -> bool {
["must_use", "no_mangle", "unsafe_destructor_blind_to_params"].iter().any(|x| x == &s)
}

fn attribute_with_value(s: &str) -> bool {
["export_name", "lang", "link_section", "must_use"].iter().any(|x| x == &s)
}

fn attribute_with_values(s: &str) -> bool {
["repr"].iter().any(|x| x == &s)
}

fn render_attribute(attr: &clean::Attribute, recurse: bool) -> Option<String> {
match *attr {
clean::Word(ref s) if attribute_without_value(&*s) || recurse => {
Some(format!("{}", s))
}
clean::NameValue(ref k, ref v) if attribute_with_value(&*k) => {
Some(format!("{} = \"{}\"", k, v))
}
clean::List(ref k, ref values) if attribute_with_values(&*k) => {
let display: Vec<_> = values.iter()
.filter_map(|value| render_attribute(value, true))
.map(|entry| format!("{}", entry))
.collect();

if display.len() > 0 {
Some(format!("{}({})", k, display.join(", ")))
} else {
None
}
}
_ => {
None
}
}
}

fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
let mut attrs = String::new();

for attr in &it.attrs {
match *attr {
clean::Word(ref s) if *s == "must_use" => {
write!(w, "#[{}]\n", s)?;
}
clean::NameValue(ref k, ref v) if *k == "must_use" => {
write!(w, "#[{} = \"{}\"]\n", k, v)?;
}
_ => ()
if let Some(s) = render_attribute(attr, false) {
attrs.push_str(&format!("#[{}]\n", s));
}
}
if attrs.len() > 0 {
write!(w, "<div class=\"docblock attributes\">{}</div>", &attrs)?;
}
Ok(())
}

Expand Down
32 changes: 25 additions & 7 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,27 +963,35 @@
}
}

$("#toggle-all-docs").on("click", toggleAllDocs);

$(document).on("click", ".collapse-toggle", function() {
var toggle = $(this);
function collapseDocs(toggle, animate) {
var relatedDoc = toggle.parent().next();
if (relatedDoc.is(".stability")) {
relatedDoc = relatedDoc.next();
}
if (relatedDoc.is(".docblock")) {
if (relatedDoc.is(":visible")) {
relatedDoc.slideUp({duration: 'fast', easing: 'linear'});
if (animate === true) {
relatedDoc.slideUp({duration: 'fast', easing: 'linear'});
toggle.children(".toggle-label").fadeIn();
} else {
relatedDoc.hide();
toggle.children(".toggle-label").show();
}
toggle.parent(".toggle-wrapper").addClass("collapsed");
toggle.children(".inner").text(labelForToggleButton(true));
toggle.children(".toggle-label").fadeIn();
} else {
relatedDoc.slideDown({duration: 'fast', easing: 'linear'});
toggle.parent(".toggle-wrapper").removeClass("collapsed");
toggle.children(".inner").text(labelForToggleButton(false));
toggle.children(".toggle-label").hide();
}
}
}

$("#toggle-all-docs").on("click", toggleAllDocs);

$(document).on("click", ".collapse-toggle", function() {
collapseDocs($(this), true)
});

$(function() {
Expand All @@ -999,12 +1007,22 @@
});

var mainToggle =
$(toggle).append(
$(toggle.clone()).append(
$('<span/>', {'class': 'toggle-label'})
.css('display', 'none')
.html('&nbsp;Expand&nbsp;description'));
var wrapper = $("<div class='toggle-wrapper'>").append(mainToggle);
$("#main > .docblock").before(wrapper);
var mainToggle =
$(toggle).append(
$('<span/>', {'class': 'toggle-label'})
.css('display', 'none')
.html('&nbsp;Expand&nbsp;attributes'));
var wrapper = $("<div class='toggle-wrapper toggle-attributes'>").append(mainToggle);
$("#main > pre > .attributes").each(function() {
$(this).before(wrapper);
collapseDocs($($(this).prev().children()[0]), false);
});
});

$('pre.line-numbers').on('click', 'span', function() {
Expand Down
Loading