rustyphoenixlecture 1.3.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::{
	pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
	plabeler::PLabelId,
	preferenceurl::PReferenceUrl,
	pveccontent::PVecContent
};

///Work in progress object of the lecture
#[derive(Debug, Clone, PartialEq)]
pub struct PContentFootnote{
	///Children of content
	content: PVecContent,
}

impl PContentFootnote{
	///Constructor of a PContentFootnote
	/// # Returns
	/// Initialised PContentFootnote
	pub fn new() -> Self{
		PContentFootnote {
			content: Default::default(),
		}
	}
	///Get the mutable content of the PContentFootnote
	/// # Returns
	/// Mutable content of the PContentFootnote
	pub fn get_content_mut(&mut self) -> &mut PVecContent {
		&mut self.content
	}
}

impl PAbstractContent for PContentFootnote{
	///Say if the PContent has an embeded label
	/// # Returns
	/// True if the PContent has an embeded label, false otherwise
	fn has_embeded_label(&self) -> bool{
		true
	}
	///Get the reference url of the current PContent
	/// # Parameters
	/// - `current_file` : current output file of the PContent
	/// - `id` : id of the current PContent
	/// # Returns
	/// Corresponding PReferenceUrl
	fn get_reference_url(&self, current_file: &String, id: usize) -> PReferenceUrl{
		PReferenceUrl::from_text(current_file, id, &String::from(&format!("PContentFootnote {}", id)))
	}
	///Convert the current struct into html
	/// # Parameters
	/// - `backend` : backend which write a lecture in files
	/// - `id` : id of the current PContent
	fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
		where TLectureBackend: PAbstractLectureBackend
	{
		backend.write(&format!("<sup class=\"footnote\" id=\"{}\">", id.get_id()));
		backend.write(&String::from("<a href=\"#\">note<span class=\"footnotespan\">"));
		self.content.to_html(backend, id);
		backend.write(&String::from("</span></a>"));
		id.to_html(backend, false);
		backend.write(&String::from("</sup>"));
	}
}

#[cfg(test)]
mod tests{
	use super::*;
	use crate::pcontent::{PContentText, PContentType, plabeler::PLabeler, pstrbackend::PStrBackend};
	
	///Test the PContentFootnote
	#[test]
	fn test_content_footnote(){
		let mut footnote = PContentFootnote::new();
		footnote.get_content_mut().add_child(&PContentType::Text(PLabeler::new(43, &PContentText::new(&String::from("An important footnote")))));
		let mut backend = PStrBackend::new();
		footnote.to_html(&mut backend, &PLabelId::new(42));
		assert_eq!(backend.get_body(), &String::from("<sup class=\"footnote\" id=\"42\"><a href=\"#\">note<span class=\"footnotespan\">An important footnote</span></a></sup>"));
	}
}