rustyphoenixlecture 2.0.0

This project aims to provide a simple a powerfull lecture compilation to generate html web sites
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/

use crate::pcontent::{
	PLabelId, pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
	preferenceurl::PReferenceUrl
};

///Type of the content status
#[derive(Debug, Clone, Default, PartialEq)]
pub enum PStatusType {
	#[default]
	///The idea is in the backlog
	Backlog,
	///The idea has to be done but, not started yet
	Todo,
	///The idea is waiting for an other
	Waiting,
	///The idea is blocked
	Blocked,
	///The idea is ongoing
	Ongoing,
	///The idea is done
	Done,
}


///Content object of the lecture
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PContentStatus{
	///Vector of children
	p_type: PStatusType,
}

impl PContentStatus {
	///Constructor of the PContentStatus
	/// # Parameters
	/// - `status_type` : type of the status
	/// # Returns
	/// Initialised PContentStatus
	pub fn new(status_type: &PStatusType) -> Self{
		PContentStatus {
			p_type: status_type.clone(),
		}
	}
	///Get the type of the PContentSattus
	/// # Returns
	/// Type of the PContentSattus
	pub fn get_type(&self) -> &PStatusType{
		&self.p_type
	}
}

impl PAbstractContent for PContentStatus{
	///Say if the PContentStatus has an embeded label
	/// # Returns
	/// True if the PContentStatus has an embeded label, false otherwise
	fn has_embeded_label(&self) -> bool{
		false
	}
	///Get the reference url of the current PContentStatus
	/// # Parameters
	/// - `current_file` : current output file of the PContentStatus
	/// - `id` : id of the PContentStatus
	/// # Returns
	/// Corresponding PReferenceUrl
	fn get_reference_url(&self, current_file: &String, id: usize) -> PReferenceUrl{
		PReferenceUrl::from_text(current_file, id, &String::from(&format!("PContentStatus {}", id)))
	}
	///Convert the current struct into html
	/// # Parameters
	/// - `backend` : backend which write a lecture in files
	/// - `id` : id of the PContentStatus
	fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
		where TLectureBackend: PAbstractLectureBackend
	{
		match self.p_type {
			PStatusType::Backlog => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_backlog.svg\" alt=\"backlog\" />", id.get_id())),
			PStatusType::Todo => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_todo.svg\" alt=\"todo\" />", id.get_id())),
			PStatusType::Waiting => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_waiting.svg\" alt=\"waiting\" />", id.get_id())),
			PStatusType::Blocked => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_blocked.svg\" alt=\"blocked\" />", id.get_id())),
			PStatusType::Ongoing => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_ongoing.svg\" alt=\"ongoing\" />", id.get_id())),
			PStatusType::Done => backend.write(&format!("<img id=\"{}\" src=\"book/images/status_done.svg\" alt=\"done\" />", id.get_id())),
		}
	}
}

#[cfg(test)]
mod tests{
	use super::*;
	use crate::pcontent::pstrbackend::PStrBackend;
	
	///Test the PContentStatus with a given type
	/// # Parameters
	/// - `status_type` : type of the status to be tested
	/// - `expected_output` : expected html output
	/// # Error
	/// The function will panic if the output differs from the expected output
	fn test_pcontent_status_type(status_type: &PStatusType, expected_output: &String){
		let content_status: PContentStatus = PContentStatus::new(status_type);
		let mut backend = PStrBackend::new();
		content_status.to_html(&mut backend, &PLabelId::new(42));
		assert_eq!(backend.get_body(), expected_output);
	}
	///Test the PContentStatus
	#[test]
	fn test_pcontent_status(){
		test_pcontent_status_type(&PStatusType::Backlog, &String::from("<img id=\"42\" src=\"book/images/status_backlog.svg\" alt=\"backlog\" />"));
		test_pcontent_status_type(&PStatusType::Todo, &String::from("<img id=\"42\" src=\"book/images/status_todo.svg\" alt=\"todo\" />"));
		test_pcontent_status_type(&PStatusType::Waiting, &String::from("<img id=\"42\" src=\"book/images/status_waiting.svg\" alt=\"waiting\" />"));
		test_pcontent_status_type(&PStatusType::Blocked, &String::from("<img id=\"42\" src=\"book/images/status_blocked.svg\" alt=\"blocked\" />"));
		test_pcontent_status_type(&PStatusType::Ongoing, &String::from("<img id=\"42\" src=\"book/images/status_ongoing.svg\" alt=\"ongoing\" />"));
		test_pcontent_status_type(&PStatusType::Done, &String::from("<img id=\"42\" src=\"book/images/status_done.svg\" alt=\"done\" />"));
	}
}