Struct mage::Template
[−]
[src]
pub struct Template { /* fields omitted */ }
Template builder
Methods
impl Template
[src]
fn new() -> Template
Create a template builder.
fn template<T: Into<String>>(self, template: T) -> Template
Set temlate from string.
fn open<P: AsRef<Path>>(self, path: P) -> Result<Template, Error>
Open a template file.
fn context(self, context: Context) -> Template
Set context.
fn root<P: Into<PathBuf>>(self, root: P) -> Template
Set template's root path.
fn extension<T: Into<String>>(self, extension: T) -> Template
Set template's extension.
fn value<T, V>(self, name: T, value: V) -> Template where
T: Into<String>,
V: Serialize,
T: Into<String>,
V: Serialize,
Add value to context.
fn function<T, F>(self, name: T, function: F) -> Template where
T: Into<String>,
F: 'static + Fn(Vec<Value>) -> Result<Value, ExpressionError> + Sync + Send,
T: Into<String>,
F: 'static + Fn(Vec<Value>) -> Result<Value, ExpressionError> + Sync + Send,
Add function to context.
fn compile(self) -> Result<Template, Error>
Compile an template. An template can be compiled only once and then render multiple times with different context and function. You can also render a template without compile.
fn render(&self) -> Result<String, Error>
Render.