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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/***************************************
Auteur : Pierre Aubert
Mail : pierre.aubert@lapp.in2p3.fr
Licence : CeCILL-C
****************************************/
use crate::plectureparser::{
pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
PReferenceUrl,
phoenix_html_label::phoenix_html_label,
};
///Manage a label and an id
pub struct PLabelId{
///Id of the PLabelId
p_id: usize,
///Label of the PLabelId
p_label: String,
}
impl PLabelId{
///Constructor of a PLabelId
/// # Parameters
/// - `id` : id of the current PContent
/// # Returns
/// Initialised PLabelId
pub fn new(id: usize) -> Self{
PLabelId {
p_id: id,
p_label: String::from(""),
}
}
///Get the Id of the current PLabelId
/// # Returns
/// Id of the current PLabelId
pub fn get_id(&self) -> usize{
self.p_id
}
///Get the Label of the current PLabelId
/// # Returns
/// Label of the current PLabelId
pub fn get_label(&self) -> &String{
&self.p_label
}
///Convert the current struct into html
/// # Parameters
/// - `backend` : backend which write a lecture in files
/// - `with_id` : true if we need to put the id in the label name (such as (id) )
pub fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, with_id: bool)
where TLectureBackend: PAbstractLectureBackend
{
if with_id {
backend.write(&phoenix_html_label(&self.p_label, Some(self.p_id)));
}else{
backend.write(&phoenix_html_label(&self.p_label, None));
}
}
}
///Manage label and id of all PContent to avoid code dupplication
#[derive(Debug, Clone, PartialEq)]
pub struct PLabeler<TData>{
///Id of the PLabeler
p_id: usize,
///Label of the PLabeler
p_label: String,
///Data of the PLabeler
p_data: TData,
}
impl<TData> PLabeler<TData>
where TData: Clone + PAbstractContent
{
///Constructor of a PLabeler
/// # Parameters
/// - `id` : id of the current PContent
/// # Returns
/// Initialised PLabeler
pub fn new(id: usize, data: &TData) -> Self{
PLabeler {
p_id: id,
p_label: String::from(""),
p_data: data.clone(),
}
}
///Set the label of the current PLabeler
/// # Parameters
/// - `label` : label of the current PLabeler
pub fn set_label(&mut self, label: &String){
self.p_label = label.clone();
}
///Get the label of the current PLabeler
/// # Returns
/// Label of the current PLabeler
pub fn get_label(&self) -> &String{
&self.p_label
}
///Get the Id of the current PLabeler
/// # Returns
/// Id of the current PLabeler
pub fn get_id(&self) -> usize{
self.p_id
}
///Get the data of the current PLabeler
/// # Returns
/// Data of the current PLabeler
pub fn get_data(&self) -> &TData{
&self.p_data
}
///Get the muttable data of the current PLabeler
/// # Returns
/// Muttable data of the current PLabeler
pub fn get_data_mut(&mut self) -> &mut TData{
&mut self.p_data
}
///Get the reference url of the current PContent
/// # Parameters
/// - `current_file` : current output file of the PContent
/// # Returns
/// Corresponding PReferenceUrl
pub fn get_reference_url(&self, current_file: &String) -> PReferenceUrl{
self.p_data.get_reference_url(current_file, self.p_id)
}
///Convert the current struct into html
/// # Parameters
/// - `backend` : backend which write a lecture in files
pub fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend)
where TLectureBackend: PAbstractLectureBackend
{
self.p_data.to_html(backend, &PLabelId { p_id: self.p_id, p_label: self.p_label.clone() });
if !self.p_data.has_embeded_label() {
backend.write(&phoenix_html_label(&self.p_label, None));
}
}
}
#[cfg(test)]
mod tests{
use super::*;
///Test the PLabeler add content
#[test]
fn test_plabeler(){
}
}