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
/***************************************
Auteur : Pierre Aubert
Mail : pierre.aubert@lapp.in2p3.fr
Licence : CeCILL-C
****************************************/
use crate::plectureparser::{
pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
plabeler::PLabelId,
preferenceurl::PReferenceUrl
};
///Reference in any other PContent of the lecture
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PContentReference{
///Reference name
p_reference: String,
///Name of an other lecture the reference refers to (empty if it is the current lecture)
p_other_lecture_name: String,
///Url to jump to the reference
p_url: PReferenceUrl,
}
impl PContentReference {
///Constructor of a PContentReference
/// # Parameters
/// - `reference` : reference of the content
pub fn new(reference: &String) -> Self{
PContentReference {
p_reference: reference.clone(),
p_other_lecture_name: String::from(""),
p_url: Default::default(),
}
}
///Constructor of a PContentReference
/// # Parameters
/// - `other_lecture_reference` : reference of the content
/// - `other_lecture_name` : name of the other lecture the reference refers to
pub fn from_other_lecture(other_lecture_reference: &String, other_lecture_name: &String) -> Self{
PContentReference {
p_reference: other_lecture_reference.clone(),
p_other_lecture_name: other_lecture_name.clone(),
p_url: Default::default(),
}
}
///Set the url of the PContentReference
/// # Parameters
/// - `url` : url of the PContentReference
pub fn set_url(&mut self, url: &PReferenceUrl){
self.p_url = url.clone();
}
///Get the reference name of the PContentReference
/// # Returns
/// Reference name of the PContentReference
pub fn get_reference(&self) -> &String{
&self.p_reference
}
///Get the name of the lecture reference of the PContentReference
/// # Returns
/// Name of the lecture reference of the PContentReference
pub fn get_other_lecture_name(&self) -> &String{
&self.p_other_lecture_name
}
}
impl PAbstractContent for PContentReference{
///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 PContent
/// # Returns
/// Corresponding PReferenceUrl
fn get_reference_url(&self, _current_file: &String, _id: usize) -> PReferenceUrl{
self.p_url.clone()
}
///Convert the current struct into html
/// # Parameters
/// - `backend` : backend which write a lecture in files
/// - `_id` : id of the PContent
fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, _id: &PLabelId)
where TLectureBackend: PAbstractLectureBackend
{
//TODO : At some point we will be able to make a thumbnail of the url destination, but let's make all things work before
// println!("PContentReference::to_html : save reference '{}'", self.p_reference);
self.p_url.to_html(backend, _id);
}
}