-
Notifications
You must be signed in to change notification settings - Fork 594
Expand file tree
/
Copy pathcomposer_builder.rs
More file actions
48 lines (37 loc) · 1.3 KB
/
composer_builder.rs
File metadata and controls
48 lines (37 loc) · 1.3 KB
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
use crate::file_writer::BBFiles;
use handlebars::Handlebars;
use serde_json::json;
pub trait ComposerBuilder {
fn create_composer_cpp(&mut self, name: &str);
fn create_composer_hpp(&mut self, name: &str);
}
impl ComposerBuilder for BBFiles {
fn create_composer_cpp(&mut self, name: &str) {
let mut handlebars = Handlebars::new();
let data = &json!({
"name": name,
});
handlebars
.register_template_string(
"composer.cpp",
std::str::from_utf8(include_bytes!("../templates/composer.cpp.hbs")).unwrap(),
)
.unwrap();
let composer_cpp = handlebars.render("composer.cpp", data).unwrap();
self.write_file(None, "composer.cpp", &composer_cpp);
}
fn create_composer_hpp(&mut self, name: &str) {
let mut handlebars = Handlebars::new();
let data = &json!({
"name": name,
});
handlebars
.register_template_string(
"composer.hpp",
std::str::from_utf8(include_bytes!("../templates/composer.hpp.hbs")).unwrap(),
)
.unwrap();
let composer_hpp = handlebars.render("composer.hpp", data).unwrap();
self.write_file(None, "composer.hpp", &composer_hpp);
}
}