forked from alexislozano/neutrino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
164 lines (143 loc) · 5.25 KB
/
build.rs
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use base64::encode;
use rsass::{compile_scss_file, OutputStyle};
use std::env;
use std::fs;
use std::str;
fn main() {
let out_dir = &env::var("OUT_DIR").unwrap();
// Commons
scss("app", out_dir);
// Themes
themes(out_dir);
// Icons
icons(out_dir);
}
fn scss(name: &str, out_dir: &str) {
let path = format!("src/www/{}/{}.scss", name, name);
let out = format!("{}/{}.css", out_dir, name);
let css =
compile_scss_file(path.as_ref(), OutputStyle::Compressed).unwrap();
fs::write(out, css).unwrap();
}
fn themes(out_dir: &str) {
let mut enum_data = r#"
/// # A theme
pub enum Theme {
"#
.to_string();
let mut impl_data = r#"
impl Theme {
/// Get a string containing the CSS defining the theme
pub fn css(&self) -> &str {
match self {
"#
.to_string();
fs::create_dir_all(format!("{}/themes", out_dir)).unwrap();
match fs::read_dir("src/www/themes") {
Err(e) => panic!(e),
Ok(entries) => {
for entry in entries {
let path = entry.unwrap().path();
let filestem = path
.clone()
.file_stem()
.unwrap()
.to_str()
.unwrap()
.to_string();
let css =
compile_scss_file(path.as_ref(), OutputStyle::Compressed)
.unwrap();
let css_str = str::from_utf8(&css).unwrap();
enum_data.push_str(&format!(r#"{},"#, &filestem));
impl_data.push_str(&format!(
r##"Theme::{} => r#"{}"#,"##,
&filestem, css_str
))
}
}
};
enum_data.push_str("}");
impl_data.push_str("}}}");
fs::write(format!("{}/themes/enum.rs", out_dir), enum_data).unwrap();
fs::write(format!("{}/themes/impl.rs", out_dir), impl_data).unwrap();
}
fn icons(out_dir: &str) {
let mut enum_data = r#""#.to_string();
let mut impl_data = r#""#.to_string();
fs::create_dir_all(format!("{}/icons/", out_dir)).unwrap();
match fs::read_dir("src/www/icons/") {
Err(e) => panic!(e),
Ok(dirs) => {
for dir in dirs {
let path = dir.unwrap().path();
let dirstem = path
.clone()
.file_stem()
.unwrap()
.to_str()
.unwrap()
.to_string();
enum_data.push_str(&format!(
r#"
/// # The {} icon set
pub enum {}Icon {{
"#,
&dirstem, &dirstem
));
impl_data
.push_str(&format!(r#"impl Icon for {}Icon {{"#, dirstem));
let mut impl_function_data = r#"fn data(&self) -> String {
match self {
"#
.to_string();
let mut impl_function_extension =
r#"fn extension(&self) -> String {
match self {
"#
.to_string();
match fs::read_dir(&path) {
Err(e) => panic!(e),
Ok(entries) => {
for entry in entries {
let path = entry.unwrap().path();
let path1 = path.clone();
let path2 = path.clone();
let filestem = path
.file_stem()
.unwrap()
.to_str()
.unwrap()
.to_string();
enum_data.push_str(&format!(r#"{},"#, &filestem));
let extension =
path1.extension().unwrap().to_str().unwrap();
let data = encode(
&String::from_utf8_lossy(
&fs::read(path2).unwrap(),
)
.replace("\n", ""),
);
impl_function_extension.push_str(&format!(
r#"{}Icon::{} => "{}".to_string(),"#,
dirstem, filestem, &extension
));
impl_function_data.push_str(&format!(
r#"{}Icon::{} => "{}".to_string(),"#,
dirstem, filestem, &data
));
}
}
};
enum_data.push_str(r#"}"#);
impl_function_data.push_str(r#"}}"#);
impl_function_extension.push_str(r#"}}"#);
impl_data.push_str(&impl_function_data);
impl_data.push_str(&impl_function_extension);
impl_data.push_str(r#"}"#);
}
}
};
fs::write(format!("{}/icons/enum.rs", out_dir), enum_data).unwrap();
fs::write(format!("{}/icons/impl.rs", out_dir), impl_data).unwrap();
}