aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2017-11-16 16:40:38 +0100
committerHarald Eilertsen <haraldei@anduin.net>2017-11-16 16:40:38 +0100
commit3bc7143ced57da953969d80d99ff8466ab986ae2 (patch)
treea4a8ef0958a1c9dae5b6f09f4642d83c3d756fe3 /src
parent1767eb2dafbab8b19cc4cf0a9a890539ce2948c1 (diff)
downloadrocket-blog-3bc7143ced57da953969d80d99ff8466ab986ae2.tar.gz
rocket-blog-3bc7143ced57da953969d80d99ff8466ab986ae2.tar.bz2
rocket-blog-3bc7143ced57da953969d80d99ff8466ab986ae2.zip
Add Bart templating engine.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs
index 622ac1c..8dd6771 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,27 +1,32 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
+extern crate diesel;
extern crate rocket;
extern crate rocket_blog;
+#[macro_use] extern crate bart_derive;
-extern crate diesel;
use self::diesel::prelude::*;
+use self::rocket_blog::{schema, models};
+
+#[derive(BartDisplay)]
+#[template = "templates/index.html"]
+struct IndexTemplate<'a> {
+ title: &'a str,
+ content: &'a str
+}
#[get("/")]
fn index(conn: rocket_blog::DbConn) -> String {
- use rocket_blog::schema::posts::dsl::*;
+ use schema::posts::dsl::*;
let results = posts.filter(published.eq(false))
.limit(5)
- .load::<rocket_blog::models::Post>(&*conn)
+ .load::<models::Post>(&*conn)
.expect("Error loading posts");
- let mut output = String::from("Hallo, for faen!\n\n");
-
- for post in results {
- output += &format!("{}\n", post.title);
- output += "================\n";
- output += &format!("{}\n", post.body);
- }
+ let output : String = results.iter().map(|post| {
+ format!("{}", &IndexTemplate{ title: &post.title, content: &post.body })
+ }).collect();
output
}