| Crates.io | sbolt |
| lib.rs | sbolt |
| version | 0.0.2 |
| created_at | 2025-10-12 07:30:33.107776+00 |
| updated_at | 2025-10-12 07:40:03.503082+00 |
| description | A small and fast view template engine in rust |
| homepage | https://github.com/gu-wei-x/sbolt |
| repository | https://github.com/gu-wei-x/sbolt |
| max_upload_size | |
| id | 1879021 |
| size | 191,561 |
sbolt is a view template engine in rust. sbolt pre-processes templates from directories and compiles them into crate bits.
The template syntax is inspired by aspnet Razor syntax which uses @ symbol to transition between CONTENT and rust code. A sample template looks llike bellow: views/welcome.rshtml
@{
let name = match context.get_data::<String>("name") {
Some(str) => str,
None => "",
};
}
<html>
<head>
<title>Welcome</title>
</head>
<body>
<div>Welcome @name!</div>
</body>
</html>
The goal of sbolt is to have your templates and static files accessible to your rust code as a module. And the module will be generated into code living outside of src directory. There are 3 steps to use the crate:
- add the crate to deps:
Cargo.toml
cargo add sbolt
cargo add sbolt --build
- create a build script to process templates:
build.rs
fn main() {
let option = sbolt::codegen::CompilerOptions::default()
.with_optimize(true)
.with_source_dir("src/views")
.with_mod_name("example_views");
let compiler = sbolt::codegen::Compiler::new(option);
compiler.compile();
}
sbolt::include_views!();
fn main() {
let mut context = sbolt::context! {
name: "sbolt".to_string()
};
let output = example_views::render("views/welcome", &mut context).unwrap_or_else(|e| {
eprintln!("Error: {e:?}");
std::process::exit(1);
});
println!("{output}");
}