Struct template_nest::TemplateNest
source · 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<'_>
impl TemplateNest<'_>
sourcepub fn new(directory_str: &str) -> Result<Self, TemplateNestError>
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
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());
}
sourcepub fn render(&self, filling: &Filling) -> Result<String, TemplateNestError>
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
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more