pub struct TemplateEngine { /* private fields */ }Expand description
Represents a template engine.
§Examples
use crabtml::TemplateEngine;
let engine = TemplateEngine::new();Implementations§
Source§impl TemplateEngine
impl TemplateEngine
Sourcepub fn new() -> TemplateEngine
pub fn new() -> TemplateEngine
Creates a new TemplateEngine.
Sourcepub fn add_template_from_file<P: AsRef<Path>>(
&mut self,
name: &str,
pathname: P,
) -> Result<(), Box<dyn Error>>
pub fn add_template_from_file<P: AsRef<Path>>( &mut self, name: &str, pathname: P, ) -> Result<(), Box<dyn Error>>
Adds a template from a file path to the template engine.
§Examples
use crabtml::TemplateEngine;
let mut engine = TemplateEngine::new();
engine.add_template_from_file("test", "tests/test.html").unwrap();
assert!(!engine.is_empty());Sourcepub fn add_template_from_string(
&mut self,
name: &str,
template: &str,
) -> Result<(), Box<dyn Error>>
pub fn add_template_from_string( &mut self, name: &str, template: &str, ) -> Result<(), Box<dyn Error>>
Adds a template from a string to the template engine.
§Examples
use crabtml::TemplateEngine;
let mut engine = TemplateEngine::new();
engine.add_template_from_string("test", "hello {{ text }}").unwrap();
assert!(!engine.is_empty());Sourcepub fn render(
&self,
name: &str,
context: &mut Context,
) -> Result<String, Box<dyn Error>>
pub fn render( &self, name: &str, context: &mut Context, ) -> Result<String, Box<dyn Error>>
Renders a template.
§Examples
use crabtml::{Context, TemplateEngine};
let mut engine = TemplateEngine::new();
engine
.add_template_from_string("test", "hello {{ text }}")
.unwrap();
let mut context = Context::new();
context.set("text", "darkness my old friend");
let rendered = engine.render("test", &mut context).unwrap();
assert_eq!(rendered, "hello darkness my old friend");Auto Trait Implementations§
impl Freeze for TemplateEngine
impl RefUnwindSafe for TemplateEngine
impl Send for TemplateEngine
impl Sync for TemplateEngine
impl Unpin for TemplateEngine
impl UnwindSafe for TemplateEngine
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