mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-27 03:08:41 +02:00
minijinja running
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::response::Html;
|
||||
use minijinja_autoreload::AutoReloader;
|
||||
|
||||
pub mod auth;
|
||||
pub mod file;
|
||||
pub mod index;
|
||||
@@ -5,3 +10,38 @@ pub mod ingress;
|
||||
pub mod query;
|
||||
pub mod queue_length;
|
||||
pub mod search_result;
|
||||
|
||||
pub fn render_template<T>(
|
||||
template_name: &str,
|
||||
context: T,
|
||||
templates: Arc<AutoReloader>,
|
||||
) -> Result<Html<String>, minijinja::Error>
|
||||
where
|
||||
T: serde::Serialize,
|
||||
{
|
||||
let env = templates.acquire_env()?;
|
||||
let tmpl = env.get_template(template_name)?;
|
||||
|
||||
let context = minijinja::Value::from_serialize(&context);
|
||||
let output = tmpl.render(context)?;
|
||||
|
||||
Ok(output.into())
|
||||
}
|
||||
|
||||
pub fn render_block<T>(
|
||||
template_name: &str,
|
||||
block: &str,
|
||||
context: T,
|
||||
templates: Arc<AutoReloader>,
|
||||
) -> Result<Html<String>, minijinja::Error>
|
||||
where
|
||||
T: serde::Serialize,
|
||||
{
|
||||
let env = templates.acquire_env()?;
|
||||
let tmpl = env.get_template(template_name)?;
|
||||
|
||||
let context = minijinja::Value::from_serialize(&context);
|
||||
let output = tmpl.eval_to_state(context)?.render_block(block)?;
|
||||
|
||||
Ok(output.into())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user