pub struct Template<'a> {
raw: String,
file_path: &'a str,
schema: Value,
shared: Shared,
time_start: Instant,
time_elapsed: Duration,
out: String,
}
Fields§
§raw: String
§file_path: &'a str
§schema: Value
§time_start: Instant
§time_elapsed: Duration
§out: String
Implementations§
Source§impl<'a> Template<'a>
impl<'a> Template<'a>
A struct representing a template that can be rendered.
This struct is used to handle the rendering of templates.
Sourcepub fn new() -> Result<Self, String>
pub fn new() -> Result<Self, String>
Constructs a new Template
instance with default settings.
It allows you to set up a template and schema with different types.
Sourcepub fn from_file_value(
file_path: &'a str,
schema: Value,
) -> Result<Self, String>
pub fn from_file_value( file_path: &'a str, schema: Value, ) -> Result<Self, String>
Constructs a new Template
instance from a file path and a JSON schema.
§Arguments
file_path
- A reference to the path of the file containing the template content.schema
- A JSON value representing the custom schema to be used with the template.
§Returns
A Result
containing the new Template
instance or an error message if:
- The file cannot be read.
Sourcepub fn set_src_str(&mut self, source: &str)
pub fn set_src_str(&mut self, source: &str)
Sets the content of the template from a string.
§Arguments
source
- A reference to the new string content to be set as the raw content.
Sourcepub fn merge_schema_value(&mut self, schema: Value)
pub fn merge_schema_value(&mut self, schema: Value)
Merges the provided JSON value with the current schema.
§Arguments
schema
- The JSON Value to be merged with the current schema.
Sourcepub fn render(&mut self) -> String
pub fn render(&mut self) -> String
Renders the template content.
This function initializes the rendering process. The resulting output is returned as a string.
§Returns
The rendered template content as a string.
fn init_render(&mut self) -> BlockInherit
fn ends_render(&mut self)
fn set_status_code(&mut self)
fn set_moveto(&mut self)
fn replacements(&mut self)
Sourcepub fn get_status_code(&self) -> &String
pub fn get_status_code(&self) -> &String
Retrieves the status code.
The status code is “200” unless “exit”, “redirect” is used or the template contains a syntax error, which will return a status code of “500”. Although the codes are numeric, a string is returned.
§Returns
A reference to the status code as a string.
Sourcepub fn get_status_text(&self) -> &String
pub fn get_status_text(&self) -> &String
Retrieves the status text.
It will correspond to the one set by the HTTP protocol.
§Returns
A reference to the status text as a string.
Sourcepub fn get_status_param(&self) -> &String
pub fn get_status_param(&self) -> &String
Retrieves the status parameter.
Some statuses such as 301 (redirect) may contain additional data, such as the destination URL, and in similar cases “param” will contain that value.
§Returns
A reference to the status parameter as a string.
Sourcepub fn has_error(&self) -> bool
pub fn has_error(&self) -> bool
Checks if there is an error.
If any error has occurred, in the parse or otherwise, it will return true.
§Returns
A boolean indicating whether there is an error.
Sourcepub fn get_error(&self) -> Value
pub fn get_error(&self) -> Value
Get bifs errors list
§Returns
Value
: A clone of the value with the list of errors in the bifs during rendering.