use crate::plectureparser::{
PReferenceUrl, pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
plabeler::PLabelId,
pveccontent::PVecContent
};
#[derive(Debug, Clone, PartialEq)]
pub struct PContentWorkInProgress{
content: PVecContent,
}
impl PContentWorkInProgress {
pub fn new() -> Self{
PContentWorkInProgress {
content: Default::default(),
}
}
pub fn get_content_mut(&mut self) -> &mut PVecContent {
&mut self.content
}
}
impl PAbstractContent for PContentWorkInProgress{
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!("Work In progress {}", id)))
}
fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
where TLectureBackend: PAbstractLectureBackend
{
backend.write(&format!("\n<table id=\"{}\" class=\"workinprogress\">\n", id.get_id()));
backend.write(&String::from("\t<tr><td class=\"workinprogressimage\"><img src=\"book/images/wip.png\" alt=\"wip\" /></td></tr>\n"));
backend.write(&String::from("\t<tr><td><div class=\"workinprogresscontent\">"));
self.content.to_html(backend, id);
backend.write(&String::from("</div></td></tr>\n</table>\n"));
}
}
#[cfg(test)]
mod tests{
use super::*;
use crate::plectureparser::{
pstrbackend::PStrBackend,
PContentType,
};
#[test]
fn test_content_work_in_progress(){
let mut wip: PContentWorkInProgress = PContentWorkInProgress::new();
wip.get_content_mut().add_child(&PContentType::from_text(43, &String::from("Some idea.")));
let mut backend = PStrBackend::new();
wip.to_html(&mut backend, &PLabelId::new(42));
assert_eq!(backend.get_body(), &String::from("\n<table id=\"42\" class=\"workinprogress\">\n\t<tr><td class=\"workinprogressimage\"><img src=\"book/images/wip.png\" alt=\"wip\" /></td></tr>\n\t<tr><td><div class=\"workinprogresscontent\">Some idea.</div></td></tr>\n</table>\n"));
}
}