Struct polly::Template
[−]
[src]
pub struct Template { /* fields omitted */ }
The Polly template.
Methods
impl Template
[src]
fn get_component(&self, name: &str) -> Option<&Component>
Get a component from within the template.
fn get_function(&self, name: &str) -> Option<&PollyFn>
Get a function from within the template.
fn load<P: AsRef<Path>>(file_path: P) -> Result<Self, TemplateError>
Loads the template from the file path.
fn no_locales(self) -> Self
Specify that a template has no locales available.
fn load_from_source<P: AsRef<Path>, S: Into<String>>(path: P, source: S) -> Self
Loads the template from the source provided. The file path is also required, for error handling
fn json(self, json: BTreeMap<String, Value>) -> Self
Pass in a serde_json
Object, for the JSON of the template.
fn locales_dir<S: Into<String>>(self, locales_dir: S) -> Self
Override the default locales directory.
fn register(
&mut self,
name: String,
function: PollyFn
) -> Result<(), TemplateError>
&mut self,
name: String,
function: PollyFn
) -> Result<(), TemplateError>
Registers a function to the template.
fn import<P: AsRef<Path>>(&mut self, path: P) -> Result<(), TemplateError>
Imports components from another template.
fn render(self, lang: &str) -> Result<String, TemplateError>
Renders the template into a HTML String.
fn unwrap_render(self, locale: &str) -> String
Renders the component, or panics if there is an error.