[][src]Struct guidon::Guidon

pub struct Guidon<'a> { /* fields omitted */ }

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]

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 a BTreeMap<String, String> as parameter and returns a BTreeMap<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]

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 a String parameter and returns the value to use as a String.

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]

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 if use_template_dir is true (default behaviour)
  • given/path if use_template_dir is false

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]

pub fn try_new(path: P) -> Result<Self>[src]

Initialization from a folder path or a file path

  • dir_path : the base directory for guidon-cli template. The file template.toml is searched in this directory.
  • file_path : the path of the template file. The working dir will be the file parent directory.

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.