pub struct TemplateNest<'a> {
    pub delimiters: (&'a str, &'a str),
    pub label: &'a str,
    pub extension: &'a str,
    pub directory: PathBuf,
    pub show_labels: bool,
    pub comment_delimiters: (&'a str, &'a str),
    pub fixed_indent: bool,
}
Expand description

Renders a template hash to produce an output.

Fields§

§delimiters: (&'a str, &'a str)

Delimiters used in the template. It is a tuple of two strings, representing the start and end delimiters.

§label: &'a str

Name label used to identify the template to be used.

§extension: &'a str

Template extension, appended on label to identify the template.

§directory: PathBuf

Directory where templates are located.

§show_labels: bool

Prepend & Append a string to every template which is helpful in identifying which template the output text came from.

§comment_delimiters: (&'a str, &'a str)

Used in conjunction with show_labels. If the template is HTML then use ‘’.

§fixed_indent: bool

Intended to improve readability when inspecting nested templates.

Implementations§

source§

impl TemplateNest<'_>

source

pub fn new(directory_str: &str) -> Result<Self, TemplateNestError>

Creates a new instance of TemplateNest with the specified directory.

Examples found in repository?
examples/01-simple-render.rs (line 5)
4
5
6
7
8
9
10
11
12
13
14
15
16
fn main() -> Result<(), TemplateNestError> {
    let nest = TemplateNest::new("templates")?;
    let simple_page = filling!(
        "TEMPLATE": "00-simple-page",
        "variable": "Simple Variable",
        "simple_component":  {
            "TEMPLATE":"01-simple-component",
            "variable": "Simple Variable in Simple Component"
        }
    );
    println!("{}", nest.render(&simple_page)?);
    Ok(())
}
More examples
Hide additional examples
examples/02-modify-filling.rs (line 8)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let nest = TemplateNest::new("templates").unwrap();
    let mut simple_page = filling!(
        "TEMPLATE": "00-simple-page",
        "simple_component":  {
            "TEMPLATE":"01-simple-component",
            "variable": "Simple Variable in Simple Component"
        }
    );
    match simple_page {
        Filling::Template(ref mut map) => {
            map.insert("variable".to_string(), filling_text!("Simple Variable"));
        }
        _ => {}
    }

    println!("{}", nest.render(&simple_page).unwrap());
}
source

pub fn render(&self, filling: &Filling) -> Result<String, TemplateNestError>

Given a TemplateHash, it parses the TemplateHash and renders a String output.

Examples found in repository?
examples/01-simple-render.rs (line 14)
4
5
6
7
8
9
10
11
12
13
14
15
16
fn main() -> Result<(), TemplateNestError> {
    let nest = TemplateNest::new("templates")?;
    let simple_page = filling!(
        "TEMPLATE": "00-simple-page",
        "variable": "Simple Variable",
        "simple_component":  {
            "TEMPLATE":"01-simple-component",
            "variable": "Simple Variable in Simple Component"
        }
    );
    println!("{}", nest.render(&simple_page)?);
    Ok(())
}
More examples
Hide additional examples
examples/03-initialize-nest-with-defaults.rs (line 19)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let nest = TemplateNest {
        directory: "templates".into(),
        label: &"NAME",
        ..Default::default()
    };
    let simple_page = filling!(
        "NAME": "00-simple-page",
        "variable": "Simple Variable",
        "simple_component":  {
            "NAME":"01-simple-component",
            "variable": "Simple Variable in Simple Component"
        }
    );
    println!("{}", nest.render(&simple_page).unwrap());
}
examples/02-modify-filling.rs (line 23)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let nest = TemplateNest::new("templates").unwrap();
    let mut simple_page = filling!(
        "TEMPLATE": "00-simple-page",
        "simple_component":  {
            "TEMPLATE":"01-simple-component",
            "variable": "Simple Variable in Simple Component"
        }
    );
    match simple_page {
        Filling::Template(ref mut map) => {
            map.insert("variable".to_string(), filling_text!("Simple Variable"));
        }
        _ => {}
    }

    println!("{}", nest.render(&simple_page).unwrap());
}

Trait Implementations§

source§

impl Default for TemplateNest<'_>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for TemplateNest<'a>

§

impl<'a> Send for TemplateNest<'a>

§

impl<'a> Sync for TemplateNest<'a>

§

impl<'a> Unpin for TemplateNest<'a>

§

impl<'a> UnwindSafe for TemplateNest<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.