mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-21 03:36:06 +00:00
Add abstraction for files to make iteration on UI easier
This commit is contained in:
parent
486319407a
commit
e8a5e44319
5 changed files with 99 additions and 43 deletions
37
src/web/assets.rs
Normal file
37
src/web/assets.rs
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue