use handlebars_iron::handlebars::to_json; use handlebars_iron::Template; use iron::prelude::{Request, Response}; use iron::{IronResult, Set, status}; use mount::Mount; use serde_json::value::{Map, Value}; use staticfile::Static; use std::path::Path; pub fn render_page(name: &str, mut template_data: Map) -> Template { template_data.insert("parent".to_string(), to_json(&"layout/base".to_owned())); Template::new(name, template_data) } pub struct AssetsHandler; impl AssetsHandler { pub fn new(prefix: &str, mount_path: &str) -> Mount { let mut assets_mount = Mount::new(); assets_mount.mount(prefix, Static::new(Path::new(mount_path))); assets_mount } } pub fn hello_world (_request: &mut Request) -> IronResult { use serde_json::value::{Map, Value}; let mut data = Map::new(); data.insert("title".to_string(), to_json(&"Media Collection CRUD".to_owned())); let mut response = Response::new(); response.set_mut(render_page("index", data)) .set_mut(status::Ok); Ok(response) }