summaryrefslogtreecommitdiff
path: root/src/render/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/mod.rs')
-rw-r--r--src/render/mod.rs42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/render/mod.rs b/src/render/mod.rs
index b47ee55..9bce062 100644
--- a/src/render/mod.rs
+++ b/src/render/mod.rs
@@ -5,10 +5,15 @@ use horrorshow::Raw;
#[derive(Debug)]
pub struct Renderer {
+ pub base_url: String,
pub user: Option<String>,
}
impl Renderer {
+ fn get_url(&self, path: &str) -> String {
+ format!("{}{}", self.base_url, path)
+ }
+
fn render_in_page<'a>(&self, content: Box<RenderBox + 'a>) -> String {
info!("Rendering page with context: {:?}", self);
let login_box: Box<RenderBox> = match self.user {
@@ -17,16 +22,16 @@ impl Renderer {
: "Logged in as ";
: user;
: " (";
- a(href="logout") { // TODO get base url from context
- : "log out"
+ a(href=self.get_url("logout")) {
+ : "Log out"
}
: ")";
}
}
None => {
box_html! {
- a(href="login") { // TODO Get base url from context
- : "Login"
+ a(href=self.get_url("login")) { // TODO Get base url from context
+ : "Log in"
}
}
}
@@ -83,24 +88,25 @@ impl Renderer {
})
}
- fn unit_table<'a>(&self, units: &'a [&unit::Unit]) -> Box<RenderBox + 'a> {
- fn render_unit<'a>(unit: &'a unit::Unit) -> Box<RenderBox + 'a> {
- box_html! {
- tr {
- td {
- a(href=format_args!("/status/{}", &unit.name)) {
- : &unit.name
- }
- }
- td {
- : format_args!("{} ({})",
- &unit.active_state,
- &unit.sub_state)
+ fn render_unit<'a>(&'a self, unit: &'a unit::Unit) -> Box<RenderBox + 'a> {
+ box_html! {
+ tr {
+ td {
+ a(href=self.get_url(&format!("/status/{}", &unit.name))) {
+ : &unit.name
}
}
+ td {
+ : format_args!("{} ({})",
+ &unit.active_state,
+ &unit.sub_state)
+ }
}
}
+ }
+
+ fn unit_table<'a>(&'a self, units: &'a [&unit::Unit]) -> Box<RenderBox + 'a> {
box_html! {
table {
tr {
@@ -112,7 +118,7 @@ impl Renderer {
}
}
@ for unit in units {
- : render_unit(unit)
+ : self.render_unit(unit)
}
}
}