considering tera and minijinja

This commit is contained in:
Per Stark
2024-12-18 18:24:18 +01:00
parent 291c473d00
commit fa6283485c
22 changed files with 1211 additions and 2125 deletions

View File

@@ -3,6 +3,7 @@ use axum::{
response::{Html, IntoResponse},
Form,
};
use axum_htmx::HxBoosted;
use axum_session_auth::AuthSession;
use axum_session_surreal::SessionSurrealPool;
use serde::{Deserialize, Serialize};
@@ -16,13 +17,17 @@ pub struct SignupParams {
pub password: String,
}
pub async fn show_signup_form(State(state): State<AppState>) -> Html<String> {
let context = tera::Context::new();
let html = state
.tera
.render("auth/signup.html", &context)
.unwrap_or_else(|_| "<h1>Error rendering template</h1>".to_string());
Html(html)
pub async fn show_signup_form(
State(state): State<AppState>,
HxBoosted(boosted): HxBoosted,
) -> Html<String> {
let mut context = tera::Context::new();
context.insert("boosted", &boosted);
// let html = state
// .tera
// .render("auth/signup_form.html", &context)
// .unwrap_or_else(|_| "<h1>Error rendering template</h1>".to_string());
Html("html".to_string())
}
pub async fn signup_handler(

View File

@@ -1,9 +1,11 @@
use axum::{extract::State, response::Html};
use axum_session_auth::AuthSession;
use axum_session_surreal::SessionSurrealPool;
use minijinja::context;
use serde_json::json;
use surrealdb::{engine::any::Any, Surreal};
use surrealdb::{engine::any::Any, sql::Relation, Surreal};
use tera::Context;
// use tera::Context;
use tracing::info;
use crate::{error::ApiError, server::AppState, storage::types::user::User};
@@ -18,14 +20,21 @@ pub async fn index_handler(
let queue_length = state.rabbitmq_consumer.get_queue_length().await?;
let output = state
.tera
.render(
"index.html",
&Context::from_value(json!({"adjective": "CRAYCRAY", "queue_length": queue_length}))
.unwrap(),
)
.unwrap();
// let output = state
// .tera
// .render(
// "index.html",
// &Context::from_value(json!({"adjective": "CRAYCRAY", "queue_length": queue_length}))
// .unwrap(),
// )
// .unwrap();
// Ok(output.into())
//
let env = state.templates.acquire_env().unwrap();
let context = context!(queue_length => "2000");
let tmpl = env.get_template("index.html").unwrap();
let output = tmpl.render(context).unwrap();
Ok(output.into())
}

View File

@@ -37,16 +37,17 @@ pub async fn search_result_handler(
)
.await?;
let output = state
.tera
.render(
"search_result.html",
&Context::from_value(
json!({"result": answer.content, "references": answer.references}),
)
.unwrap(),
)
.unwrap();
Ok(Html("Hello".to_string()))
// let output = state
// .tera
// .render(
// "search_result.html",
// &Context::from_value(
// json!({"result": answer.content, "references": answer.references}),
// )
// .unwrap(),
// )
// .unwrap();
Ok(output.into())
// Ok(output.into())
}