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
/***************************************
Auteur : Pierre Aubert
Mail : pierre.aubert@lapp.in2p3.fr
Licence : CeCILL-C
****************************************/
use crate::phighlighter::PLocation;
use crate::plectureparser::pabstractcontent::PAbstractLectureBackend;
///String backend for the lecture used mainly for unit testing, to ease string comparison without openning a file with all the trouble that come with it
pub struct PStrBackend{
///Content of the backend
body: String,
}
impl PStrBackend{
///Constructor of the PStrBackend
pub fn new() -> Self{
PStrBackend {
body: String::from("")
}
}
///Get the content of the PStrBackend
/// # Returns
/// Content of the PStrBackend
pub fn get_body(&self) -> &String{
&self.body
}
}
impl PAbstractLectureBackend for PStrBackend {
///Create a new file
/// # Parameters
/// - `_output_filename` : name of the file to write
/// - `_title` : title of the section
/// - `_location` : location of current source file where this section was defined
/// - `_prev_page` : previous page to visit
/// - `_next_page` : next page to visit
fn create_file(&mut self, _output_filename: &String, _title: &String,
_location: &PLocation,
_prev_page: &String, _next_page: &String)
{
//Let's close the previous file is there was one
self.close();
}
///Write text in the current file
/// # Parameters
/// - `text` : text to write in the current file
fn write(&mut self, text: &String){
self.body += &text;
}
///Write a formula in html
/// # Parameters
/// - `formula` : formula to write in html
/// # Errors
/// This function will panic if there is a problem during the formula generation
fn write_formula(&mut self, formula: &String){
self.body += &formula;
}
///Close the current file
fn close(&mut self){
self.body = String::from("");
}
}