Expand description
This crate adds a convenient auto reloader for MiniJinja.
The AutoReloader
is an utility type that can be passed around or placed
in a global variable using something like
once_cell
. It accepts a
closure which is used to create an environment which is passed a notifier.
This notifier can automatically watch file system paths or it can be manually
instructed to invalidate the environment.
Every time acquire_env
is called the reloader
checks if a reload is scheduled in which case it will automatically re-create
the environment. While the guard is retained, the environment
won’t perform further reloads.
§Example
This is an example that uses the source
feature of MiniJinja to automatically
load templates from the file system:
use minijinja_autoreload::AutoReloader;
use minijinja::{Environment, path_loader};
let reloader = AutoReloader::new(|notifier| {
let template_path = "path/to/templates";
let mut env = Environment::new();
env.set_loader(path_loader(template_path));
notifier.watch_path(template_path, true);
Ok(env)
});
let env = reloader.acquire_env()?;
let tmpl = env.get_template("index.html")?;
Structs§
- Auto
Reloader - An auto reloader for MiniJinja
Environment
s. - Environment
Guard - A guard that de-references into an
Environment
. - Notifier
- Signalling utility to notify the auto reloader about reloads.