rustyphoenixlecture 1.8.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::{
	PContentText, PContentType, pabstractcontent::{PAbstractContent, PAbstractLectureBackend}, plabeler::{PLabelId, PLabeler}, pveccontent::PVecContent
};


///Content object of the lecture
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PReferenceUrl{
	///Url of the PReferenceUrl
	url: String,
	///Text of url
	text: PVecContent,
	///Simple text of the reference
	p_simple_text: String,
	///Label of the PContent
	p_label: String,
}

impl PReferenceUrl {
	///Create a PReferenceUrl
	/// # Parameters
	/// - `current_file` : current output file
	/// - `id` : id of the PContent to be referenced
	/// - `text` : text of the url
	pub fn from_text(current_file: &String, id: usize, text: &String) -> Self{
		let mut other = PReferenceUrl {
			url: String::from(&format!("{}#{}", current_file, id)),
			text: Default::default(),
			p_simple_text: text.clone(),
			p_label: String::from(""),
		};
		other.get_text_mut().add_child(&PContentType::Text(PLabeler::new(id + 100000000000, &PContentText::new(text))));
		return other;
	}
	///Create a PReferenceUrl
	/// # Parameters
	/// - `current_file` : current output file
	/// - `id` : id of the PContent to be referenced
	/// - `text` : text of the link as PVecContent
	pub fn from_content(current_file: &String, id: usize, text: &PVecContent) -> Self{
		PReferenceUrl {
			url: String::from(&format!("{}#{}", current_file, id)),
			text: text.clone(),
			p_simple_text: String::from(""),
			p_label: String::from(""),
		}
	}
	///Create a PReferenceUrl
	/// # Parameters
	/// - `url` : url of the reference
	/// - `text` : text of the link
	pub fn from_url(url: &String, text: &String) -> Self{
		let mut other = PReferenceUrl {
			url: url.clone(),
			text: Default::default(),
			p_simple_text: text.clone(),
			p_label: String::from(""),
		};
		other.get_text_mut().add_child(&PContentType::Text(PLabeler::new(200000000000, &PContentText::new(text))));
		return other;
	}
	///Get the mutable text of the PReferenceUrl
	/// # Returns
	/// Mutable text of the PReferenceUrl
	pub fn get_text_mut(&mut self) -> &mut PVecContent {
		&mut self.text
	}
	///Get the url of the PReferenceUrl
	/// # Returns
	/// Url of the PReferenceUrl
	pub fn get_url(&self) -> &String{
		&self.url
	}
	///Get the simple text of the PReferenceUrl
	/// # Returns
	/// Simple text of the PReferenceUrl
	pub fn get_simple_text(&self) -> &String{
		&self.p_simple_text
	}
}

impl PAbstractContent for PReferenceUrl{
	///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{
		false
	}
	///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{
		Default::default()
	}
	///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
	{
		//If there is no url, we do not print the reference
		if self.url.is_empty() {
			panic!("PReferenceUrl::to_html : cannot save reference because url is empty");
		}
		if self.text.len() == 0 {	//If there is not content we repeat the url in the text
			backend.write(&format!("<a href=\"{}\">{}</a>", self.url, self.url));
		}else{	//If there is a content we convert it into html
			backend.write(&format!("<a href=\"{}\"><b>", self.url));
			self.text.to_html(backend, id);
			backend.write(&String::from("</b></a>"));
		}
		// backend.write(&phoenix_html_label(&self.p_label, None));
	}
}