| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
use quasi_tauri::Served; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
pub fn get(path: &str) -> Option<Served> { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
if path == super::theming::ADDRESS { |
| 30 |
return Some(Served::new(CSS, super::theming::css().as_bytes())); |
| 31 |
} |
| 32 |
|
| 33 |
let (content_type, body): (&str, &[u8]) = match path { |
| 34 |
|
| 35 |
|
| 36 |
"/static/typography.css" => (CSS, include_bytes!("../../frontend/css/typography.css")), |
| 37 |
"/static/geometry.css" => (CSS, include_bytes!("../../frontend/css/geometry.css")), |
| 38 |
"/static/timing.css" => (CSS, include_bytes!("../../frontend/css/timing.css")), |
| 39 |
"/static/layout.css" => (CSS, include_bytes!("../../frontend/css/layout.css")), |
| 40 |
"/static/styles.css" => (CSS, include_bytes!("../../frontend/css/styles.css")), |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
"/static/htmx.min.js" => (JS, include_bytes!("../../frontend/vendor/htmx.min.js")), |
| 52 |
"/static/quasi-selection.js" => { |
| 53 |
(JS, include_bytes!("../../frontend/js/quasi-selection.js")) |
| 54 |
} |
| 55 |
"/static/quasi-clock.js" => (JS, include_bytes!("../../frontend/js/quasi-clock.js")), |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
"/static/host.js" => (JS, include_bytes!("../../frontend/js/host.js")), |
| 61 |
"/static/quasi-download.js" => (JS, include_bytes!("../../frontend/js/quasi-download.js")), |
| 62 |
"/static/quasi-fill.js" => (JS, include_bytes!("../../frontend/js/quasi-fill.js")), |
| 63 |
"/static/quasi-reveal.js" => (JS, include_bytes!("../../frontend/js/quasi-reveal.js")), |
| 64 |
"/static/quasi-repeat.js" => (JS, include_bytes!("../../frontend/js/quasi-repeat.js")), |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
"/fonts/QuasiMono.woff2" => ( |
| 69 |
WOFF2, |
| 70 |
include_bytes!("../../frontend/fonts/QuasiMono.woff2"), |
| 71 |
), |
| 72 |
"/fonts/QuasiBody.woff2" => ( |
| 73 |
WOFF2, |
| 74 |
include_bytes!("../../frontend/fonts/QuasiBody.woff2"), |
| 75 |
), |
| 76 |
"/fonts/Reglo-Bold.woff2" => ( |
| 77 |
WOFF2, |
| 78 |
include_bytes!("../../frontend/fonts/Reglo-Bold.woff2"), |
| 79 |
), |
| 80 |
|
| 81 |
_ => return None, |
| 82 |
}; |
| 83 |
Some(Served::new(content_type, body)) |
| 84 |
} |
| 85 |
|
| 86 |
const CSS: &str = "text/css; charset=utf-8"; |
| 87 |
const JS: &str = "text/javascript; charset=utf-8"; |
| 88 |
const WOFF2: &str = "font/woff2"; |
| 89 |
|
| 90 |
#[cfg(test)] |
| 91 |
mod tests { |
| 92 |
use super::get; |
| 93 |
|
| 94 |
#[test] |
| 95 |
fn every_asset_the_shell_names_is_served() { |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
for path in [ |
| 100 |
"/static/typography.css", |
| 101 |
"/static/geometry.css", |
| 102 |
"/static/timing.css", |
| 103 |
"/static/layout.css", |
| 104 |
"/static/styles.css", |
| 105 |
"/static/htmx.min.js", |
| 106 |
"/static/quasi-selection.js", |
| 107 |
"/static/quasi-clock.js", |
| 108 |
"/static/quasi-download.js", |
| 109 |
"/static/quasi-fill.js", |
| 110 |
"/static/quasi-reveal.js", |
| 111 |
"/static/quasi-repeat.js", |
| 112 |
"/fonts/QuasiMono.woff2", |
| 113 |
"/fonts/QuasiBody.woff2", |
| 114 |
"/fonts/Reglo-Bold.woff2", |
| 115 |
] { |
| 116 |
let served = get(path).unwrap_or_else(|| panic!("{path} is not served")); |
| 117 |
assert!(!served.body.is_empty(), "{path} is empty"); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
#[test] |
| 134 |
fn the_theme_is_served_even_before_it_is_installed() { |
| 135 |
let path = crate::quasi::theming::ADDRESS; |
| 136 |
let served = get(path).unwrap_or_else(|| panic!("{path} is not served")); |
| 137 |
assert_eq!(served.content_type, super::CSS); |
| 138 |
assert_eq!( |
| 139 |
served.body, |
| 140 |
crate::quasi::theming::css().as_bytes(), |
| 141 |
"the body is whatever theming holds, installed or not" |
| 142 |
); |
| 143 |
} |
| 144 |
|
| 145 |
#[test] |
| 146 |
fn a_route_address_is_not_an_asset_address() { |
| 147 |
|
| 148 |
|
| 149 |
for path in ["/", "/projects", "/tasks", "/static", "/static/"] { |
| 150 |
assert!(get(path).is_none(), "{path} must reach the router"); |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
|