aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-01-14 12:39:50 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-01-14 12:39:50 +0100
commit0dae37a2e98c13fbc78acd58b86565fd6f14c654 (patch)
tree681be6b03971acca3f57fd30d613909b60aaa984 /src/controllers
parenta77f6e9d27f98bc36d0911ce58c109f4a18bd835 (diff)
downloadrocket-blog-0dae37a2e98c13fbc78acd58b86565fd6f14c654.tar.gz
rocket-blog-0dae37a2e98c13fbc78acd58b86565fd6f14c654.tar.bz2
rocket-blog-0dae37a2e98c13fbc78acd58b86565fd6f14c654.zip
Split out layout from templates.
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/home_controller.rs14
-rw-r--r--src/controllers/posts_controller.rs30
2 files changed, 30 insertions, 14 deletions
diff --git a/src/controllers/home_controller.rs b/src/controllers/home_controller.rs
index c4c0c56..563be40 100644
--- a/src/controllers/home_controller.rs
+++ b/src/controllers/home_controller.rs
@@ -3,16 +3,20 @@ use rocket_contrib::Json;
#[derive(BartDisplay, Serialize)]
#[template = "templates/index.html"]
-struct IndexTemplate<'a> {
- title: &'a str,
+struct IndexTemplate {
posts: Vec<models::Post>
}
-implement_responder_for!(IndexTemplate<'a>);
+implement_responder_for!(IndexTemplate);
#[get("/", format = "text/html")]
-fn index<'a>(conn: utils::DbConn) -> IndexTemplate<'a> {
- IndexTemplate { title: "Bloggen", posts: models::Post::get_all(conn) }
+fn index(conn: utils::DbConn) -> utils::Page<IndexTemplate> {
+ utils::Page {
+ title: String::from("Bloggen"),
+ content: IndexTemplate {
+ posts: models::Post::get_all(conn)
+ }
+ }
}
#[get("/", format = "application/json")]
diff --git a/src/controllers/posts_controller.rs b/src/controllers/posts_controller.rs
index a8c5e1c..38618d3 100644
--- a/src/controllers/posts_controller.rs
+++ b/src/controllers/posts_controller.rs
@@ -4,16 +4,20 @@ use utils;
#[derive(BartDisplay)]
#[template = "templates/new_post.html"]
-pub struct NewPostTemplate<'a> {
- title: &'a str,
+pub struct NewPostTemplate {
post: ::models::NewPost
}
-implement_responder_for!(NewPostTemplate<'a>);
+implement_responder_for!(NewPostTemplate);
#[get("/new", format = "text/html")]
-fn new<'a>(_conn: utils::DbConn) -> NewPostTemplate<'a> {
- NewPostTemplate { title: "Bloggen", post: Default::default() }
+fn new(_conn: utils::DbConn) -> utils::Page<NewPostTemplate> {
+ utils::Page {
+ title: String::from("New post"),
+ content: NewPostTemplate {
+ post: Default::default()
+ }
+ }
}
#[post("/create", data="<post>")]
@@ -31,9 +35,14 @@ pub struct ShowPostTemplate {
implement_responder_for!(ShowPostTemplate);
#[get("/<id>", format = "text/html")]
-fn show<'a>(id: i32, conn: utils::DbConn) -> ShowPostTemplate {
+fn show(id: i32, conn: utils::DbConn) -> utils::Page<ShowPostTemplate> {
let p = ::models::Post::get(id, conn);
- ShowPostTemplate { post: p }
+ utils::Page {
+ title: p.title.clone(),
+ content: ShowPostTemplate {
+ post: p
+ },
+ }
}
#[derive(BartDisplay)]
@@ -45,9 +54,12 @@ pub struct EditPostTemplate {
implement_responder_for!(EditPostTemplate);
#[get("/<id>/edit", format = "text/html")]
-fn edit(id: i32, conn: utils::DbConn) -> EditPostTemplate {
+fn edit(id: i32, conn: utils::DbConn) -> utils::Page<EditPostTemplate> {
let p = ::models::Post::get(id, conn);
- EditPostTemplate { post: p }
+ utils::Page {
+ title: String::from("Edit post"),
+ content: EditPostTemplate { post: p }
+ }
}
#[post("/update", data="<post>")]