use systemd::unit; use horrorshow::prelude::*; use horrorshow::Raw; #[derive(Debug)] pub struct Renderer { pub user: Option } impl Renderer { fn render_in_page<'a>(&self, content: Box) -> String { info!("Rendering page with context: {:?}", self); let login_box: Box = match self.user { Some(ref user) => box_html!{ : user; : " ("; a(href="logout") { // TODO get base url from context : "log out" } : ")"; }, None => box_html! { a(href="login") { // TODO Get base url from context : "Login" } } }; (html!{ : Raw(""); html { head { title: "Systemhttpd"; link(rel="stylesheet", type="text/css", href="/static/main.css"); } body { nav { ul { li { p { : "SystemHttpd" } } } ul(class="right") { li { p { : login_box } } } } main { : content } } } }).into_string().unwrap() } pub fn login_page(&self) -> String { self.render_in_page(box_html! { h1 { : "Log in" } form(method="post") { p { : "Username" } input(type="text", name="username") {} p { : "Password" } input(type="text", name="password") {} p {} input(type="submit", value="Log in") {} } }) } fn unit_table<'a>(&self, units: &'a [&unit::Unit]) -> Box { fn render_unit<'a>(unit: &'a unit::Unit) -> Box { box_html! { tr { td { a(href=format_args!("/status/{}", &unit.name)) { : &unit.name } } td { : format_args!("{} ({})", &unit.active_state, &unit.sub_state) } } } } box_html! { table { tr { th { : "Unit" } th { : "Active" } } @ for unit in units { : render_unit(unit) } } } } pub fn system_status(&self, sections: &[(String, Vec<&unit::Unit>)]) -> String { self.render_in_page(box_html! { @ for &(ref type_, ref units) in sections { h1 { : type_ } : self.unit_table(&units) } }) } pub fn unit_status(&self, unit: &unit::Unit, log: &str) -> String { self.render_in_page(box_html! { h1 { :&unit.name } p { : format_args!("{} ({})", &unit.active_state, &unit.sub_state) } pre { : log } }) } }