1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
use super::*; #[derive(Clone, Debug)] pub struct Anchor(pub String); #[derive(Clone, Debug)] pub struct SourceLink(pub String); #[derive(Clone, Debug)] pub struct Tooltip { pub base: String, pub text: String, } #[derive(Copy, Clone, Debug)] pub struct CollapseToggle(pub Option<bool>); impl Into<Html> for Anchor { fn into(self) -> Html { match self.0.len() { 0 => html! {<span class="anchor"/>}, _ => html! {<a class="anchor" href=self.0/>}, } } } impl Into<Html> for SourceLink { fn into(self) -> Html { match self.0.len() { 0 => EMPTY_HTML, _ => html! {<a class="src-link" href=self.0>{"[src]"}</a>}, } } } impl Into<Html> for Tooltip { fn into(self) -> Html { html! { <span class="tooltip">{self.base} <span class="tooltip-text">{self.text}</span> </span> } } } impl Into<Html> for CollapseToggle { fn into(self) -> Html { let inner: Html = match self.0 { None => html! {<span class="inner">{"x"}</span>}, Some(true) => html! {<span class="inner">{"−"}</span>}, Some(false) => html! {<span class="inner">{"+"}</span>}, }; html! {<a class="collapse-toggle">{"["}{inner}{"]"}</a>} } } impl Tooltip { pub fn new(base: &str, text: &str) -> Self { Self { base: String::from(base), text: String::from(text) } } pub fn html(base: &str, text: &str) -> Html { Self::new(base, text).into() } }