Crates.io | germinate |
lib.rs | germinate |
version | 0.7.0 |
source | src |
created_at | 2020-05-18 16:06:09.105057 |
updated_at | 2021-09-21 08:59:52.105085 |
description | A templating library for injecting variables from multiple external sources |
homepage | |
repository | https://github.com/itmecho/germinate |
max_upload_size | |
id | 243080 |
size | 152,583 |
This crate provides a method of injecting variables from multiple external sources into a
template string. Sources can be anything as long as they implement the
Loader
trait which handles the
loading of the variables in a standard way.
default
- ["aws"]
aws
- Enable the AWS value sourcesThese are the currently implemented sources and their associated template keys
Source | Key | Feature | Description |
---|---|---|---|
AWS EC2 Instance Tags | awsec2tag |
aws |
Load the value of AWS EC2 Instance Tags by their key |
AWS EC2 Metadata Service | awsec2metadata |
aws |
Load a value from the AWS EC2 Metadata Service by it's path |
AWS SSM Parameter | awsssm |
aws |
Load a value from the AWS SSM Parameter Store by it's name. LIMITATION when running on an EC2 instance, the parameter must be in the same region as the instance |
Environment Variables | env |
- |
Load the value of an environment variable |
let mut seed = Seed::new("Hi %env:NAME%!");
let output = seed.germinate().await?;
assert_eq!("Hi John!", output);
You can also include your own sources using the
Seed::add_custom_loader
method. The only requirement is that the custom loader must implement the
Loader
trait
let mut seed = Seed::new("Hi %name:name%");
// Add a custom loader for the name key. This is the loader that will be used whenever
// germinate finds %name:...% in the template string
seed.add_custom_loader("name".to_string(), Box::new(NameLoader {}));
let output = seed.germinate().await?;
assert_eq!("Hi John", output);
Germinate provides a CLI for templating files, available from the Github releases. To run the CLI, cimply download the binary for your system and check the usage with germinate --help
The CLI can be used to parse an template file and output it either to stdout
or optionally, an output file
# To print the parsed result to stdout
germinate myfile.txt.tmpl
# To write the output to a file
germinate myfile.txt.tmpl -o myfile.txt