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()
}
}