rrgen
A microframework for declarative code generation and injection.
Getting started
Templates use Tera as a templating language (similar to liquid), and use a special metadata/body separation with frontmatter.
The first part of the template instructs what the template should do, and which injections it should perform.
The second part is the actual target file that's being generated.
Example template controller.t:
---
to: tests/fixtures/realistic/generated/controllers/.rs
injections:
- into: tests/fixtures/realistic/generated/controllers/mod.rs
append: true
content: "pub mod {{ name | snake_case }};"
- into: tests/fixtures/realistic/generated/app.rs
after: "AppRoutes::"
content: " .add_route(controllers::{{ name | snake_case }}::routes())"
---
use ;
use ;
pub async
pub async
Rendering a template will create one or more files, potentially inject into files, and is done like so:
use fs;
use Rgen;
use json;
let rrgen = default;
let vars = json!;
rrgen.generate
.unwrap;
vars will be variables that are exposed both for the frontmatter part and the body part.