Loco.rs Minijinja Integration
Go to file
2025-01-14 18:54:55 +01:00
examples/usage_example code: better Readme, implementing custom intializer 2025-01-13 21:40:44 +01:00
src code: pushing tests to > 80% for initial satisfaction. 2025-01-14 16:52:29 +01:00
tests code: tests should be 100% in my mind, but tarpaulin says 94. good enough. 2025-01-14 18:54:55 +01:00
.gitignore code: test framework and coverage for development 2025-01-14 15:53:11 +01:00
Cargo.lock code: test framework and coverage for development 2025-01-14 15:53:11 +01:00
Cargo.toml code: test framework and coverage for development 2025-01-14 15:53:11 +01:00
Justfile code: test framework and coverage for development 2025-01-14 15:53:11 +01:00
README.md code: better Readme, implementing custom intializer 2025-01-13 21:40:44 +01:00
tarpaulin.toml code: test framework and coverage for development 2025-01-14 15:53:11 +01:00
TODOS.md refactor: redacting statement into TODOs 2025-01-13 15:05:34 +01:00

Minijinja Engine for Loco.rs

This crate allows you to integrate Minijinja as Template renderer into Loco.rs

Usage

Use autoreloader

The autoreloader feature automatically uses the minijinja-autoreloader instead of a single environment.

Just set in your Cargo.toml:

loco-minijinja-engine = { features = ["autoreloader"] }

Default Settings

If you want the standard initializer, so access "assets/templates" as your template directory, and a standard minijinja renderer as it comes out of the box, just use in your app.rs:

...

    async fn initializers(_ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
        Ok(vec![Box::new(loco_minijinja_engine::MinijinjaViewEngineInitializer)])
    }

...

Custom Environment or Template Directory

If you want a different directory for your templates, e.g. stay with "assets/views" like the Tera setup in loco, use the custom initializer in your app.rs:

...

    async fn initializers(_ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
        let environment = Environment::new();
        Ok(vec![Box::new(
            loco_minijinja_engine::MinijinjaViewEngineConfigurableInitializer::new(
                "assets/views".to_string(),
                Some(environment),
            ),
        )])
    }

(Note, that because of the trait layout, I cannot prevent two clones and 'static for the custom Environment, so if you need anything more dynamic, feel free to copypaste the initializer, and initialize the Environment in the closure)