[−][src]Struct guidon::Guidon
The Guidon structure
Implementations
impl<'a> Guidon<'a>
[src]
pub fn new(path: PathBuf) -> Self
[src]
Creates a new Guidon from a path
pub fn variables(&mut self, vars: BTreeMap<String, String>)
[src]
Sets the substitutions variables
pub fn use_template_dir(&mut self, tplt: bool) -> &mut Self
[src]
If set to true
guidon-cli will try to parse a file structure in a folder called template
located in the given input path.
If set to false
guidon-cli will parse the given input folder.
By default guidon-cli will use a template dir.
pub fn use_strict_mode(&mut self, strict: bool) -> &mut Self
[src]
Wether to use or no Handlebars strict mode.
If set to true
(default value), an error will be raised if a variable is not defined.
If set to false
missing variables will be set to an empty string.
pub fn set_variables_callback<F>(&mut self, cb: F) where
F: Fn(&mut BTreeMap<String, String>) + 'a,
[src]
F: Fn(&mut BTreeMap<String, String>) + 'a,
Provides a callback to perform an operation on the variables map. Can be used to change default variables values.
Arguments
cb
: callback. A closure with takes aBTreeMap<String, String>
as parameter and returns aBTreeMap<String, String>
.
Example
use guidon::Guidon; use std::collections::BTreeMap; use std::path::PathBuf; let cb = |h: &mut BTreeMap<String, String>| { h.iter_mut().for_each(|(_, v)| *v +=" cb"); }; let mut guidon = Guidon::new(PathBuf::from("template/path")); guidon.set_variables_callback(cb);
pub fn set_render_callback<F>(&mut self, cb: F) where
F: Fn(String) -> String + 'a,
[src]
F: Fn(String) -> String + 'a,
Provides a callback to be called when a variables is not found in the configuration file.
Arguments
cb
: callback. A closure with takes the expected key as aString
parameter and returns the value to use as aString
.
Example
use guidon::Guidon; use std::collections::BTreeMap; use std::path::PathBuf; // this callback will add `-cb` to the key as a value let cb = |h: String| { let mut s = h.clone(); s.push_str("-cb"); s }; let mut guidon = Guidon::new(PathBuf::from("template/path")); guidon.set_render_callback(cb);
pub fn apply_template<T>(&mut self, to_dir: T) -> Result<()> where
T: AsRef<Path>,
[src]
T: AsRef<Path>,
Apply template. The substitution will be performed with variables provided in the config file. The input dir is deduced from the path given at guidon-cli initialization:
given/path/template
ifuse_template_dir
istrue
(default behaviour)given/path
ifuse_template_dir
isfalse
Arguments
to_dir
: the directory where the templated file structure will be created.
Trait Implementations
impl<'a> Default for Guidon<'a>
[src]
impl<'a> TryNew<GitOptions> for Guidon<'a>
[src]
pub fn try_new(git: GitOptions) -> Result<Self>
[src]
Initialization from a git repository
The repo MUST contains at its root a template.toml
file.
impl<'a, P: 'a + AsRef<Path>> TryNew<P> for Guidon<'a>
[src]
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Guidon<'a>
impl<'a> !Send for Guidon<'a>
impl<'a> !Sync for Guidon<'a>
impl<'a> Unpin for Guidon<'a>
impl<'a> !UnwindSafe for Guidon<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,