Add abstraction for files to make iteration on UI easier

This commit is contained in:
Lucien Greathouse
2019-09-24 14:00:48 -07:00
parent 486319407a
commit e8a5e44319
5 changed files with 99 additions and 43 deletions

37
src/web/assets.rs Normal file
View File

@@ -0,0 +1,37 @@
use std::{fs, path::Path};
static LOGO: &[u8] = include_bytes!("../../assets/logo-512.png");
static ICON: &[u8] = include_bytes!("../../assets/icon-32.png");
static HOME_CSS: &str = include_str!("../../assets/index.css");
macro_rules! declare_asset {
($name: ident, $path: expr) => {
pub fn $name() -> &'static str {
if cfg!(feature = "dev-live-assets") {
let file_path = Path::new(file!());
let asset_path = file_path.parent().unwrap().join($path);
println!("Reloading {}", asset_path.display());
let content = fs::read_to_string(asset_path)
.expect("Couldn't read dev live asset")
.into_boxed_str();
Box::leak(content)
} else {
static CONTENT: &str = include_str!($path);
CONTENT
}
}
};
}
declare_asset!(css, "../../assets/index.css");
pub fn logo() -> &'static [u8] {
LOGO
}
pub fn icon() -> &'static [u8] {
ICON
}