Add tooltip for important traits display

This commit is contained in:
Guillaume Gomez 2017-11-18 00:32:12 +01:00
parent d86621f69e
commit 6047a03659
4 changed files with 15 additions and 9 deletions

View file

@ -3255,6 +3255,7 @@ fn render_spotlight_traits(item: &clean::Item) -> Result<String, fmt::Error> {
fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
let mut out = String::new();
let mut trait_ = String::new();
if let Some(did) = decl.output.def_id() {
let c = cache();
@ -3265,9 +3266,10 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
.map_or(false, |t| t.is_spotlight) {
if out.is_empty() {
out.push_str(
&format!("<h3 class=\"important\">Important traits for {}</h3>",
&format!("<h3 class=\"important\">Important traits for {}</h3>\
<code class=\"content\">",
impl_.for_));
out.push_str("<code class=\"content\">");
trait_.push_str(&format!("{}", impl_.for_));
}
//use the "where" class here to make it small
@ -3288,8 +3290,11 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
}
if !out.is_empty() {
out.insert_str(0, "<div class=\"important-traits\">ⓘ<div class=\"content hidden\">");
out.push_str("</code></span></div></div>");
out.insert_str(0, &format!("<div class=\"important-traits\"><div class='tooltip'>ⓘ\
<span class='tooltiptext'>Important traits for {}</span></div>\
<div class=\"content hidden\">",
trait_));
out.push_str("</code></div></div>");
}
Ok(out)

View file

@ -1737,7 +1737,7 @@
onEach(document.getElementsByClassName('important-traits'), function(e) {
e.onclick = function() {
showModal(e.firstElementChild.innerHTML);
showModal(e.lastElementChild.innerHTML);
};
});

View file

@ -958,6 +958,7 @@ pre.rust {
.important-traits {
cursor: pointer;
z-index: 2;
}
h4 > .important-traits {

View file

@ -19,7 +19,7 @@ impl<T: SomeTrait> SomeTrait for Wrapper<T> {}
#[doc(spotlight)]
pub trait SomeTrait {
// @has doc_spotlight/trait.SomeTrait.html
// @has - '//code[@class="spotlight"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
// @has - '//code[@class="content"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
fn wrap_me(self) -> Wrapper<Self> where Self: Sized {
Wrapper {
inner: self,
@ -32,15 +32,15 @@ impl SomeTrait for SomeStruct {}
impl SomeStruct {
// @has doc_spotlight/struct.SomeStruct.html
// @has - '//code[@class="spotlight"]' 'impl SomeTrait for SomeStruct'
// @has - '//code[@class="spotlight"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
// @has - '//code[@class="content"]' 'impl SomeTrait for SomeStruct'
// @has - '//code[@class="content"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
pub fn new() -> SomeStruct {
SomeStruct
}
}
// @has doc_spotlight/fn.bare_fn.html
// @has - '//code[@class="spotlight"]' 'impl SomeTrait for SomeStruct'
// @has - '//code[@class="content"]' 'impl SomeTrait for SomeStruct'
pub fn bare_fn() -> SomeStruct {
SomeStruct
}