use crate::plectureparser::{
pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
plabeler::PLabelId,
preferenceurl::PReferenceUrl,
pveccontent::PVecContent
};
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PContentDetail{
content: PVecContent,
}
impl PContentDetail {
pub fn new() -> Self{
PContentDetail {
content: Default::default(),
}
}
pub fn get_content_mut(&mut self) -> &mut PVecContent {
&mut self.content
}
}
impl PAbstractContent for PContentDetail{
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!("PContentDetail {}", id)))
}
fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
where TLectureBackend: PAbstractLectureBackend
{
backend.write(&String::from(format!("\n<details id=\"{}\" class=\"details\"><br />\n", id.get_id())));
self.content.to_html(backend, id);
backend.write(&String::from("\n</details>\n"));
}
}
#[cfg(test)]
mod tests{
use crate::plectureparser::{
PContentText, PContentType, plabeler::PLabeler, pstrbackend::PStrBackend
};
use super::*;
#[test]
fn test_pcontent_detail(){
let mut detail = PContentDetail::new();
detail.get_content_mut().add_child(&PContentType::Text(PLabeler::new(43, &PContentText::new(&String::from("Detail title")))));
detail.get_content_mut().add_child(&PContentType::Text(PLabeler::new(44, &PContentText::new(&String::from("Detail content")))));
let mut backend = PStrBackend::new();
detail.to_html(&mut backend, &PLabelId::new(42));
assert_eq!(backend.get_body(), &String::from("\n<details id=\"42\" class=\"details\"><br />\nDetail titleDetail content\n</details>\n"));
}
}