[−][src]Crate guidon
guidon
guidon performs templating based on handlebars templating system.
Usage
Files to be handles needs to have an .hbs
extension. Folders and files names can be templatized too : {{folder/subfolder}}
The entry point is the Guidon structure.
Basic init
use guidon::Guidon; use std::collections::HashMap; use std::path::PathBuf; let mut guidon = Guidon::new(PathBuf::from("path/to/template/dir")); let mut vars = HashMap::new(); vars.insert("key1".to_string(), "value1".to_string()); guidon.apply_template("path/to/destination").unwrap();
With this initialization:
- guidon will use the vars map to find substitution values.
- guidon will parse the directory
path/to/template/dir/template
- the result will be written in
path/to/destination
TryNew init
guidon implements a TryNew trait to initialize from a dir or a git repo
TryNew from path
use guidon::{Guidon, TryNew}; let mut guidon = Guidon::try_new("path/to/template/dir").unwrap();
With this initialization:
- guidon will init the substitution variables from
path/to/template/dir/variables.toml
- guidon will parse the directory
path/to/template/dir/template
use guidon::{Guidon, TryNew}; let mut guidon = Guidon::try_new("path/to/template/dir/my_vars.toml").unwrap(); guidon.use_template_dir(false);
With this initialization:
- guidon will init the substitution variables from
path/to/template/dir/my_vars.toml
- guidon will parse the directory
path/to/template/dir
TryNew from git repo
use guidon::{{Guidon, TryNew, GitOptions}}; let git = GitOptions::builder() .repo("url/to/repo") .credentials(("user".to_string(), "password".to_string())) .build() .unwrap(); let mut guidon = Guidon::try_new(git);
With this initialization
- guidon will clone the repo to a temporary directory
- guidon will init the substitutions variables from
tmp/dir/template.toml
- when applying template, guidon will parse the directory
tmp/dir/template
Template variables
The configuration file is structured as follows :
# Key value pairs for template substitution
[variables]
test1 = "test 1"
test2 = "test 2"
Logs
guidon uses the log facade.
Callbacks
TODO
Re-exports
pub use git::GitOptions; |
Modules
errors | |
git |
Structs
Guidon | The Guidon structure |
Traits
TryNew | Try to initialize Guidon from different sources |
Type Definitions
RenderCallback | |
VariablesCallback |