提交 2321d11b 编写于 作者: E Eduard-Mihai Burtescu 提交者: GitHub

Rollup merge of #37134 - GuillaumeGomez:display_tag, r=steveklabnik

Print more tags in rustdoc

r? @steveklabnik

cc @frewsxcv

A little screenshot:

<img width="1440" alt="screen shot 2016-10-13 at 01 41 53" src="https://cloud.githubusercontent.com/assets/3050060/19331745/873cd71e-90e6-11e6-88f8-715668366a3f.png">
......@@ -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(())
}
......
......@@ -963,20 +963,22 @@
}
}
$("#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");
......@@ -984,6 +986,12 @@
toggle.children(".toggle-label").hide();
}
}
}
$("#toggle-all-docs").on("click", toggleAllDocs);
$(document).on("click", ".collapse-toggle", function() {
collapseDocs($(this), true)
});
$(function() {
......@@ -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() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册