2020-12-16 02:40:41 +00:00
|
|
|
use crate::LinkKind;
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct Link {
|
|
|
|
pub(crate) href: String,
|
|
|
|
pub(crate) kind: LinkKind,
|
2021-01-11 03:59:11 +00:00
|
|
|
pub(crate) title: Option<String>,
|
2021-01-24 04:01:48 +00:00
|
|
|
classes: Vec<String>,
|
2021-01-11 03:59:11 +00:00
|
|
|
plain: bool,
|
2020-12-16 02:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Link {
|
|
|
|
pub fn current_tab(href: &str) -> Self {
|
|
|
|
Link {
|
|
|
|
href: href.to_owned(),
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_tab(href: &str) -> Self {
|
|
|
|
Link {
|
|
|
|
href: href.to_owned(),
|
|
|
|
kind: LinkKind::NewTab,
|
2021-01-11 03:59:11 +00:00
|
|
|
title: None,
|
|
|
|
plain: false,
|
2021-01-24 04:01:48 +00:00
|
|
|
classes: vec![],
|
2020-12-16 02:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-09 04:32:02 +00:00
|
|
|
|
2021-01-22 05:42:19 +00:00
|
|
|
pub fn title(mut self, title: &str) -> Self {
|
2021-01-11 03:59:11 +00:00
|
|
|
self.title = Some(title.to_owned());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-01-24 04:01:48 +00:00
|
|
|
pub fn plain(mut self, plain: bool) -> Self {
|
|
|
|
self.plain = plain;
|
2021-01-09 04:32:02 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-01-24 04:01:48 +00:00
|
|
|
pub fn class(mut self, class: &str) -> Self {
|
|
|
|
self.classes.push(class.to_owned());
|
2021-01-11 03:59:11 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-01-09 04:32:02 +00:00
|
|
|
pub(crate) fn class_string(&self) -> String {
|
2021-01-24 04:01:48 +00:00
|
|
|
let mut classes = self.classes.clone();
|
|
|
|
|
|
|
|
classes.push("toolkit-link".to_owned());
|
2021-01-09 04:32:02 +00:00
|
|
|
|
2021-01-11 03:59:11 +00:00
|
|
|
if self.plain {
|
2021-01-24 04:01:48 +00:00
|
|
|
classes.push("toolkit-plain".to_owned());
|
2021-01-11 03:59:11 +00:00
|
|
|
}
|
2021-01-09 04:32:02 +00:00
|
|
|
|
|
|
|
classes.join(" ")
|
|
|
|
}
|
2020-12-16 02:40:41 +00:00
|
|
|
}
|