use crate::pcontent::{
PLabelId, pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
preferenceurl::PReferenceUrl,
};
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PContentSpeaker{
p_name: String,
p_title: String,
p_function: String,
p_affiliation: String,
}
impl PContentSpeaker {
pub fn new(name: &String, title: &String, function: &String, affiliation: &String) -> Self{
PContentSpeaker {
p_name: name.clone(),
p_title: title.clone(),
p_function: function.clone(),
p_affiliation: affiliation.clone(),
}
}
}
impl PAbstractContent for PContentSpeaker{
fn has_embeded_label(&self) -> bool{
false
}
fn get_reference_url(&self, current_file: &String, id: usize) -> PReferenceUrl{
PReferenceUrl::from_text(current_file, id, &String::from(&format!("{}", self.p_name)))
}
fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
where TLectureBackend: PAbstractLectureBackend
{
backend.write(&String::from(format!("<div id=\"{}\"><b>Speaker : </b>", id.get_id())));
if !self.p_title.is_empty(){
backend.write(&String::from(format!("{} ", self.p_title)));
}
backend.write(&String::from(format!("{}<br /><b>Affiliation : </b>{}<br /><b>Function : </b>{}<br />\n", self.p_name, self.p_affiliation, self.p_function)));
}
}
#[cfg(test)]
mod tests{
use crate::pcontent::PStrBackend;
use super::*;
#[test]
fn test_content_speaker(){
let speaker = PContentSpeaker::new(&String::from("John Doe"), &String::from("Dr"), &String::from("Yes"), &String::from("Shmu"));
let mut backend = PStrBackend::new();
speaker.to_html(&mut backend, &PLabelId::new(42));
assert_eq!(backend.get_body(), &String::from("<div id=\"42\"><b>Speaker : </b>Dr John Doe<br /><b>Affiliation : </b>Shmu<br /><b>Function : </b>Yes<br />\n"));
}
}