diff options
author | Martin Fischer <martin@push-f.com> | 2021-06-24 20:59:31 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-06-24 20:59:31 +0200 |
commit | b019d39957bd644d9b6b856738b57eb87e0506de (patch) | |
tree | 93d8622084ee3df0438822832564aa70bb380385 | |
parent | a3f04614b916dd5c2591f37decac0ba3e3ecabb5 (diff) |
refactor render_page
-rw-r--r-- | src/main.rs | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs index cdb5650..5c9f10c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -273,29 +273,24 @@ pub struct Page { body: String, } -const CSS: &str = include_str!("static/style.css"); - fn render_page<C: Controller>(page: &Page, controller: &C, parts: &Parts) -> String { - format!( - "<!doctype html>\ - <html>\ - <head>\ - <meta charset=utf-8>\ - <title>{}</title>\ - <meta name=viewport content=\"width=device-width, initial-scale=1\">\ - <style>{}</style>\ - </head>\ - <body><header id=header>{}{}</header>{}</body></html>\ - ", - html_escape(&page.title), - CSS, - page.header.as_deref().unwrap_or_default(), - controller + let mut out = String::new(); + out.push_str("<!doctype html><html><head><meta charset=utf-8>"); + out.push_str(&format!("<title>{}</title>", html_escape(&page.title))); + out.push_str("<meta name=viewport content=\"width=device-width, initial-scale=1\"><style>"); + out.push_str(include_str!("static/style.css")); + out.push_str("</style></head><body><header id=header>"); + out.push_str(page.header.as_deref().unwrap_or_default()); + out.push_str( + &controller .user_info_html(parts) .map(|h| format!("<div class=user-info>{}</div>", h)) .unwrap_or_default(), - page.body, - ) + ); + out.push_str("</header>"); + out.push_str(&page.body); + out.push_str("</body></html>"); + out } #[derive(Deserialize)] |