rustyphoenixlecture 1.16.1

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 PContentCheckBox{
	///True if the checkbox is checked, false if not
	p_is_checked: bool,
}

impl PContentCheckBox {
	///Constructor of the PContentCheckBox
	/// # Parameters
	/// - `is_checked` : true if the checkbox is checked, false if not
	/// # Returns
	/// Initialised PContentCheckBox
	pub fn new(is_checked: bool) -> Self{
		PContentCheckBox {
			p_is_checked: is_checked,
		}
	}
}

impl PAbstractContent for PContentCheckBox{
	///Say if the PContentCheckBox has an embeded label
	/// # Returns
	/// True if the PContentCheckBox has an embeded label, false otherwise
	fn has_embeded_label(&self) -> bool{
		false
	}
	///Get the reference url of the current PContentCheckBox
	/// # Parameters
	/// - `current_file` : current output file of the PContentCheckBox
	/// - `id` : id of the PContentCheckBox
	/// # Returns
	/// Corresponding PReferenceUrl
	fn get_reference_url(&self, current_file: &String, id: usize) -> PReferenceUrl{
		PReferenceUrl::from_text(current_file, id, &String::from(&format!("PContentCheckBox {}", id)))
	}
	///Convert the current struct into html
	/// # Parameters
	/// - `backend` : backend which write a lecture in files
	/// - `id` : id of the PContentCheckBox
	fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
		where TLectureBackend: PAbstractLectureBackend
	{
		let style: String = if self.p_is_checked {
			String::from("checkbox_checked")
		}else{
			String::from("checkbox_unchecked")
		};
		// backend.write(&String::from(format!("<input id=\"{}\" type=\"checkbox\" class=\"{}\" disabled ", id.get_id(), style)));
		// backend.write(&String::from(format!("<span id=\"{}\" class=\"{}\">", id.get_id(), style)));
		backend.write(&String::from(format!("<img id=\"{}\" src=\"book/images/{}.png\" class=\"checkbox_style\"/>", id.get_id(), style)));
		// if self.p_is_checked {
			// backend.write(&String::from("checked "));
		// }
		// backend.write(&String::from("/>"));
		// backend.write(&String::from("</span>"));
	}
}

#[cfg(test)]
mod tests{
	use super::*;
	use crate::pcontent::pstrbackend::PStrBackend;
	
	///Test the PContentCheckBox
	#[test]
	fn test_content_text(){
		let checkbox: PContentCheckBox = PContentCheckBox::new(false);
		let mut backend = PStrBackend::new();
		checkbox.to_html(&mut backend, &PLabelId::new(42));
		// assert_eq!(backend.get_body(), &String::from("<input id=\"42\" type=\"checkbox\" disabled />"));
		// assert_eq!(backend.get_body(), &String::from("<span id=\"42\" class=\"checkbox_unchecked\"></span>"));
		assert_eq!(backend.get_body(), &String::from("<img id=\"42\" src=\"book/images/checkbox_unchecked.png\" class=\"checkbox_style\"/>"));
	}
	///Test the PContentCheckBox
	#[test]
	fn test_content_text_checked(){
		let checkbox: PContentCheckBox = PContentCheckBox::new(true);
		let mut backend = PStrBackend::new();
		checkbox.to_html(&mut backend, &PLabelId::new(42));
		// assert_eq!(backend.get_body(), &String::from("<input id=\"42\" type=\"checkbox\" disabled checked />"));
		// assert_eq!(backend.get_body(), &String::from("<span id=\"42\" class=\"checkbox_checked\"></span>"));
		assert_eq!(backend.get_body(), &String::from("<img id=\"42\" src=\"book/images/checkbox_checked.png\" class=\"checkbox_style\"/>"));
	}
}