use askama::Template; use crate::{ data::model, translation::{self, Sentence, Tr}, }; pub struct Recipes { pub published: Vec<(i64, String)>, pub unpublished: Vec<(i64, String)>, pub current_id: Option, } impl Recipes { pub fn is_current(&self, id: &&i64) -> bool { self.current_id == Some(**id) } } #[derive(Template)] #[template(path = "home.html")] pub struct HomeTemplate { pub user: Option, pub tr: Tr, pub recipes: Recipes, } #[derive(Template)] #[template(path = "message.html")] pub struct MessageTemplate<'a> { pub user: Option, pub tr: Tr, pub message: &'a str, pub as_code: bool, // Display the message in
 markup.
}

impl<'a> MessageTemplate<'a> {
    pub fn new(message: &'a str, tr: Tr) -> MessageTemplate<'a> {
        MessageTemplate {
            user: None,
            tr,
            message,
            as_code: false,
        }
    }

    pub fn new_with_user(
        message: &'a str,
        tr: Tr,
        user: Option,
    ) -> MessageTemplate<'a> {
        MessageTemplate {
            user,
            tr,
            message,
            as_code: false,
        }
    }
}

#[derive(Template)]
#[template(path = "sign_up_form.html")]
pub struct SignUpFormTemplate<'a> {
    pub user: Option,
    pub tr: Tr,

    pub email: String,
    pub message: &'a str,
    pub message_email: &'a str,
    pub message_password: &'a str,
}

#[derive(Template)]
#[template(path = "sign_in_form.html")]
pub struct SignInFormTemplate<'a> {
    pub user: Option,
    pub tr: Tr,

    pub email: &'a str,
    pub message: &'a str,
}

#[derive(Template)]
#[template(path = "ask_reset_password.html")]
pub struct AskResetPasswordTemplate<'a> {
    pub user: Option,
    pub tr: Tr,

    pub email: &'a str,
    pub message: &'a str,
    pub message_email: &'a str,
}

#[derive(Template)]
#[template(path = "reset_password.html")]
pub struct ResetPasswordTemplate<'a> {
    pub user: Option,
    pub tr: Tr,

    pub reset_token: &'a str,
    pub message: &'a str,
    pub message_password: &'a str,
}

#[derive(Template)]
#[template(path = "profile.html")]
pub struct ProfileTemplate<'a> {
    pub user: Option,
    pub tr: Tr,

    pub username: &'a str,
    pub email: &'a str,
    pub default_servings: u32,
    pub message: &'a str,
    pub message_email: &'a str,
    pub message_password: &'a str,
}

#[derive(Template)]
#[template(path = "recipe_view.html")]
pub struct RecipeViewTemplate {
    pub user: Option,
    pub tr: Tr,

    pub recipes: Recipes,

    pub recipe: model::Recipe,
}

#[derive(Template)]
#[template(path = "recipe_edit.html")]
pub struct RecipeEditTemplate {
    pub user: Option,
    pub tr: Tr,

    pub recipes: Recipes,

    pub recipe: model::Recipe,
}

#[derive(Template)]
#[template(path = "recipes_list_fragment.html")]
pub struct RecipesListFragmentTemplate {
    pub tr: Tr,

    pub recipes: Recipes,
}