aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-10-28 13:35:15 +0200
committerMartin Fischer <martin@push-f.com>2022-10-28 13:35:15 +0200
commit025d2619341a6323d87c2cfa3dcf0a0f287c6636 (patch)
treec07a427cc750253d07ca99795b726b7213aa75fa
parent651982662065901d7ec27f925caabaa096ee9f99 (diff)
refactor: simplify render_page function
-rw-r--r--src/main.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index e2fea85..af00d3f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -219,16 +219,22 @@ async fn service<C: Controller>(
.await
.map(|resp| match resp {
Response::Raw(resp) => resp,
- Response::Page(page) => {
+ Response::Page(mut page) => {
if !page.script_src.is_empty() {
script_csp = page.script_src.join(" ");
}
if let Some(src) = page.frame_src {
frame_csp = src;
}
+ page.header.push_str(
+ &controller
+ .user_info_html(&parts)
+ .map(|h| format!("<div class=user-info>{}</div>", h))
+ .unwrap_or_default(),
+ );
Builder::new()
.content_type(mime::TEXT_HTML)
- .body(render_page(&page, controller, &parts).into())
+ .body(render_page(&page).into())
.unwrap()
}
})
@@ -266,7 +272,7 @@ pub struct Page {
frame_src: Option<&'static str>,
}
-fn render_page<C: Controller>(page: &Page, controller: &C, parts: &Parts) -> String {
+fn render_page(page: &Page) -> String {
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)));
@@ -274,12 +280,6 @@ fn render_page<C: Controller>(page: &Page, controller: &C, parts: &Parts) -> Str
out.push_str(include_str!("static/style.css"));
out.push_str("</style></head><body><header id=header>");
out.push_str(&page.header);
- out.push_str(
- &controller
- .user_info_html(parts)
- .map(|h| format!("<div class=user-info>{}</div>", h))
- .unwrap_or_default(),
- );
out.push_str("</header>");
out.push_str(&page.body);
for script in &page.scripts {