1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/***************************************
Auteur : Pierre Aubert
Mail : pierre.aubert@lapp.in2p3.fr
Licence : CeCILL-C
****************************************/
use crate::plectureparser::{
pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
plabeler::PLabelId,
preferenceurl::PReferenceUrl,
pveccontent::PVecContent
};
///Content object of the lecture
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PContentUrl{
///Url of the PContentUrl
url: String,
///Text of url
text: PVecContent,
}
impl PContentUrl {
///Constructor of the PContentUrl
/// # Returns
/// Initialised PContentUrl
pub fn new() -> Self {
PContentUrl {
url: String::from(""),
text: Default::default(),
}
}
///Set the url of the PContentUrl
/// # Parameters
/// - `url` : url of the PContentUrl
pub fn set_url(&mut self, url: &String){
self.url = url.clone()
}
///Get the mutable text of the PContentWorkInProgress
/// # Returns
/// Mutable text of the PContentWorkInProgress
pub fn get_text_mut(&mut self) -> &mut PVecContent {
&mut self.text
}
}
impl PAbstractContent for PContentUrl{
///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{
PReferenceUrl::from_text(current_file, id, &String::from(format!("Url {}", 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
{
if self.text.len() == 0 { //If there is not content we repeat the url in the text
backend.write(&format!("<a id=\"{}\" href=\"{}\">{}</a>", id.get_id(), self.url, self.url));
}else{ //If there is a content we convert it into html
backend.write(&format!("<a id=\"{}\" href=\"{}\">", id.get_id(), self.url));
self.text.to_html(backend, id);
backend.write(&String::from("</a>"));
}
}
}