1
Fork 0

print enum variant fields in docs

This commit is contained in:
Oliver Schneider 2016-05-27 12:04:56 +02:00
parent dd6e8d45e1
commit b0c7033042
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
4 changed files with 65 additions and 40 deletions

View file

@ -117,6 +117,7 @@ from xml.etree import cElementTree as ET
from htmlentitydefs import entitydefs from htmlentitydefs import entitydefs
entitydefs['larrb'] = u'\u21e4' entitydefs['larrb'] = u'\u21e4'
entitydefs['rarrb'] = u'\u21e5' entitydefs['rarrb'] = u'\u21e5'
entitydefs['nbsp'] = ' '
# "void elements" (no closing tag) from the HTML Standard section 12.1.2 # "void elements" (no closing tag) from the HTML Standard section 12.1.2
VOID_ELEMENTS = set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', VOID_ELEMENTS = set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',

View file

@ -111,27 +111,27 @@ impl fmt::Display for clean::Generics {
for (i, life) in self.lifetimes.iter().enumerate() { for (i, life) in self.lifetimes.iter().enumerate() {
if i > 0 { if i > 0 {
f.write_str(", ")?; f.write_str(", ")?;
} }
write!(f, "{}", *life)?; write!(f, "{}", *life)?;
} }
if !self.type_params.is_empty() { if !self.type_params.is_empty() {
if !self.lifetimes.is_empty() { if !self.lifetimes.is_empty() {
f.write_str(", ")?; f.write_str(", ")?;
} }
for (i, tp) in self.type_params.iter().enumerate() { for (i, tp) in self.type_params.iter().enumerate() {
if i > 0 { if i > 0 {
f.write_str(", ")? f.write_str(", ")?
} }
f.write_str(&tp.name)?; f.write_str(&tp.name)?;
if !tp.bounds.is_empty() { if !tp.bounds.is_empty() {
write!(f, ": {}", TyParamBounds(&tp.bounds))?; write!(f, ": {}", TyParamBounds(&tp.bounds))?;
} }
match tp.default { match tp.default {
Some(ref ty) => { write!(f, " = {}", ty)?; }, Some(ref ty) => { write!(f, " = {}", ty)?; },
None => {} None => {}
}; };
} }
@ -229,21 +229,21 @@ impl fmt::Display for clean::PathParameters {
let mut comma = false; let mut comma = false;
for lifetime in lifetimes { for lifetime in lifetimes {
if comma { if comma {
f.write_str(", ")?; f.write_str(", ")?;
} }
comma = true; comma = true;
write!(f, "{}", *lifetime)?; write!(f, "{}", *lifetime)?;
} }
for ty in types { for ty in types {
if comma { if comma {
f.write_str(", ")?; f.write_str(", ")?;
} }
comma = true; comma = true;
write!(f, "{}", *ty)?; write!(f, "{}", *ty)?;
} }
for binding in bindings { for binding in bindings {
if comma { if comma {
f.write_str(", ")?; f.write_str(", ")?;
} }
comma = true; comma = true;
write!(f, "{}", *binding)?; write!(f, "{}", *binding)?;

View file

@ -2243,26 +2243,24 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "</pre>")?; write!(w, "</pre>")?;
document(w, cx, it)?; document(w, cx, it)?;
let mut fields = s.fields.iter().filter(|f| { let mut fields = s.fields.iter().filter_map(|f| {
match f.inner { match f.inner {
clean::StructFieldItem(..) => true, clean::StructFieldItem(ref ty) => Some((f, ty)),
_ => false, _ => None,
} }
}).peekable(); }).peekable();
if let doctree::Plain = s.struct_type { if let doctree::Plain = s.struct_type {
if fields.peek().is_some() { if fields.peek().is_some() {
write!(w, "<h2 class='fields'>Fields</h2>\n<table>")?; write!(w, "<h2 class='fields'>Fields</h2>")?;
for field in fields { for (field, ty) in fields {
write!(w, "<tr class='stab {stab}'> write!(w, "<span id='{shortty}.{name}'><code>{name}: {ty}</code></span>
<td id='{shortty}.{name}'>\ <span class='stab {stab}'></span>",
<code>{name}</code></td><td>",
shortty = ItemType::StructField, shortty = ItemType::StructField,
stab = field.stability_class(), stab = field.stability_class(),
name = field.name.as_ref().unwrap())?; name = field.name.as_ref().unwrap(),
ty = ty)?;
document(w, cx, field)?; document(w, cx, field)?;
write!(w, "</td></tr>")?;
} }
write!(w, "</table>")?;
} }
} }
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All) render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
@ -2292,7 +2290,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "{}(", name)?; write!(w, "{}(", name)?;
for (i, ty) in tys.iter().enumerate() { for (i, ty) in tys.iter().enumerate() {
if i > 0 { if i > 0 {
write!(w, ", ")? write!(w, ",&nbsp;")?
} }
write!(w, "{}", *ty)?; write!(w, "{}", *ty)?;
} }
@ -2324,40 +2322,47 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
document(w, cx, it)?; document(w, cx, it)?;
if !e.variants.is_empty() { if !e.variants.is_empty() {
write!(w, "<h2 class='variants'>Variants</h2>\n<table class='variants_table'>")?; write!(w, "<h2 class='variants'>Variants</h2>\n")?;
for variant in &e.variants { for variant in &e.variants {
write!(w, "<tr><td id='{shortty}.{name}'><code>{name}</code></td><td>", write!(w, "<span id='{shortty}.{name}' class='variant'><code>{name}",
shortty = ItemType::Variant, shortty = ItemType::Variant,
name = variant.name.as_ref().unwrap())?; name = variant.name.as_ref().unwrap())?;
if let clean::VariantItem(ref var) = variant.inner {
if let clean::TupleVariant(ref tys) = var.kind {
write!(w, "(")?;
for (i, ty) in tys.iter().enumerate() {
if i > 0 {
write!(w, ",&nbsp;")?;
}
write!(w, "{}", *ty)?;
}
write!(w, ")")?;
}
}
write!(w, "</code></span>")?;
document(w, cx, variant)?; document(w, cx, variant)?;
use clean::{Variant, StructVariant}; use clean::{Variant, StructVariant};
if let clean::VariantItem( Variant { kind: StructVariant(ref s) } ) = variant.inner { if let clean::VariantItem( Variant { kind: StructVariant(ref s) } ) = variant.inner {
let fields = s.fields.iter().filter(|f| {
match f.inner {
clean::StructFieldItem(..) => true,
_ => false,
}
});
write!(w, "<h3 class='fields'>Fields</h3>\n write!(w, "<h3 class='fields'>Fields</h3>\n
<table>")?; <table>")?;
for field in fields { for field in &s.fields {
write!(w, "<tr><td \ use clean::StructFieldItem;
id='{shortty}.{v}.field.{f}'>\ if let StructFieldItem(ref ty) = field.inner {
<code>{f}</code></td><td>", write!(w, "<tr><td \
shortty = ItemType::Variant, id='variant.{v}.field.{f}'>\
v = variant.name.as_ref().unwrap(), <code>{f}:&nbsp;{t}</code></td><td>",
f = field.name.as_ref().unwrap())?; v = variant.name.as_ref().unwrap(),
document(w, cx, field)?; f = field.name.as_ref().unwrap(),
write!(w, "</td></tr>")?; t = *ty)?;
document(w, cx, field)?;
write!(w, "</td></tr>")?;
}
} }
write!(w, "</table>")?; write!(w, "</table>")?;
} }
write!(w, "</td><td>")?;
render_stability_since(w, variant, it)?; render_stability_since(w, variant, it)?;
write!(w, "</td></tr>")?;
} }
write!(w, "</table>")?;
} }
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)?; render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)?;
Ok(()) Ok(())

View file

@ -265,6 +265,10 @@ nav.sub {
.docblock h2 { font-size: 1.15em; } .docblock h2 { font-size: 1.15em; }
.docblock h3, .docblock h4, .docblock h5 { font-size: 1em; } .docblock h3, .docblock h4, .docblock h5 { font-size: 1em; }
.docblock {
margin-left: 24px;
}
.content .out-of-band { .content .out-of-band {
font-size: 23px; font-size: 23px;
margin: 0px; margin: 0px;
@ -640,6 +644,21 @@ span.since {
margin-right: 5px; margin-right: 5px;
} }
.enum > .toggle-wrapper > .collapse-toggle, .struct > .toggle-wrapper > .collapse-toggle {
left: 0;
margin-top: 5px;
}
.enum > .toggle-wrapper + .docblock, .struct > .toggle-wrapper + .docblock {
margin-left: 30px;
margin-bottom: 20px;
margin-top: 5px;
}
.enum > .collapsed, .struct > .collapsed {
margin-bottom: 25px;
}
:target > code { :target > code {
background: #FDFFD3; background: #FDFFD3;
} }