rustyphoenixlecture 1.6.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,
};

///Content object of the lecture
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PContentSpeaker{
	///Name of the speaker
	p_name: String,
	///Title of the speaker
	p_title: String,
	///Function / job of the speaker
	p_function: String,
	///Affiliation of the speaker
	p_affiliation: String,
}

impl PContentSpeaker {
	///Constructor of the PContentSpeaker
	/// # Parameters
	/// - `name` : name of the speaker
	/// - `title` : title of the speaker
	/// - `function` : function / job of the speaker
	/// - `affiliation` : affiliation of the speaker
	/// # Returns
	/// Initialised 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{
	///Say if the PContentSpeaker has an embeded label
	/// # Returns
	/// True if the PContentSpeaker has an embeded label, false otherwise
	fn has_embeded_label(&self) -> bool{
		false
	}
	///Get the reference url of the current PContentSpeaker
	/// # Parameters
	/// - `current_file` : current output file of the PContentSpeaker
	/// - `id` : id of the PContentSpeaker
	/// # Returns
	/// Corresponding PReferenceUrl
	fn get_reference_url(&self, current_file: &String, id: usize) -> PReferenceUrl{
		PReferenceUrl::from_text(current_file, id, &String::from(&format!("{}", self.p_name)))
	}
	///Convert the current struct into html
	/// # Parameters
	/// - `backend` : backend which write a lecture in files
	/// - `id` : id of the PContentSpeaker
	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 the PContentSpeaker
	#[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"));
	}
}