generated from alecodes/base-template
feat: add minijinja as template engine
This commit is contained in:
parent
5a9b871e42
commit
6cb75aa442
10 changed files with 150 additions and 31 deletions
25
src/lib.rs
25
src/lib.rs
|
|
@ -1,3 +1,28 @@
|
|||
mod error;
|
||||
pub mod router;
|
||||
|
||||
pub use error::{Error, Result, ResultTemplate};
|
||||
use minijinja::{Environment, Template};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Link {
|
||||
pub path: String,
|
||||
pub text: String,
|
||||
pub subpages: Vec<Self>,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
tmpl_env: Environment<'static>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(tmpl_env: Environment<'static>) -> Arc<Self> {
|
||||
Arc::new(AppState { tmpl_env })
|
||||
}
|
||||
|
||||
pub fn get_template(&self, name: &str) -> Result<Template> {
|
||||
Ok(self.tmpl_env.get_template(name)?)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue