Use Ructe (#327)
All the template are now compiled at compile-time with the `ructe` crate.
I preferred to use it instead of askama because it allows more complex Rust expressions, where askama only supports a small subset of expressions and doesn't allow them everywhere (for instance, `{{ macro!() | filter }}` would result in a parsing error).
The diff is quite huge, but there is normally no changes in functionality.
Fixes #161 and unblocks #110 and #273
This commit is contained in:
+13
-12
@@ -1,29 +1,30 @@
|
||||
use rocket::response::{Redirect, Flash};
|
||||
use rocket_contrib::Template;
|
||||
use rocket_i18n::I18n;
|
||||
|
||||
use plume_common::utils;
|
||||
use plume_models::{db_conn::DbConn, notifications::Notification, users::User};
|
||||
use routes::Page;
|
||||
use template_utils::Ructe;
|
||||
|
||||
#[get("/notifications?<page>")]
|
||||
fn paginated_notifications(conn: DbConn, user: User, page: Page) -> Template {
|
||||
Template::render("notifications/index", json!({
|
||||
"account": user.to_json(&*conn),
|
||||
"notifications": Notification::page_for_user(&*conn, &user, page.limits()).into_iter().map(|n| n.to_json(&*conn)).collect::<Vec<_>>(),
|
||||
"page": page.page,
|
||||
"n_pages": Page::total(Notification::find_for_user(&*conn, &user).len() as i32)
|
||||
}))
|
||||
pub fn paginated_notifications(conn: DbConn, user: User, page: Page, intl: I18n) -> Ructe {
|
||||
render!(notifications::index(
|
||||
&(&*conn, &intl.catalog, Some(user.clone())),
|
||||
Notification::page_for_user(&*conn, &user, page.limits()),
|
||||
page.0,
|
||||
Page::total(Notification::find_for_user(&*conn, &user).len() as i32)
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/notifications")]
|
||||
fn notifications(conn: DbConn, user: User) -> Template {
|
||||
paginated_notifications(conn, user, Page::first())
|
||||
pub fn notifications(conn: DbConn, user: User, intl: I18n) -> Ructe {
|
||||
paginated_notifications(conn, user, Page::first(), intl)
|
||||
}
|
||||
|
||||
#[get("/notifications", rank = 2)]
|
||||
fn notifications_auth() -> Flash<Redirect>{
|
||||
pub fn notifications_auth(i18n: I18n) -> Flash<Redirect>{
|
||||
utils::requires_login(
|
||||
"You need to be logged in order to see your notifications",
|
||||
i18n!(i18n.catalog, "You need to be logged in order to see your notifications"),
|
||||
uri!(notifications)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user