Struct minijinja::Environment [−][src]
pub struct Environment<'source> { /* fields omitted */ }
Expand description
An abstraction that holds the engine configuration.
This object holds the central configuration state for templates and their configuration. Instances of this type may be modified if no template were loaded so far. Modifications on environments after the first template was loaded will lead to surprising effects and undefined behavior. For instance overriding the auto escape callback will no longer have effects to an already loaded template.
The environment holds references to the source the templates were created from.
This makes it very inconvenient to pass around unless the templates are static
strings. For situations where you want to load dynamic templates and share the
environment it’s recommended to turn on the source
feature and to use the
Source
type with the environment.
Implementations
Creates a new environment with sensible defaults.
This environment does not yet contain any templates but it will have all the
default filters loaded. If you do not want any default configuration you
can use the alternative empty
method.
Creates a completely empty environment.
This environment has no filters, no templates and no default logic for auto escaping configured.
pub fn set_auto_escape_callback<F: Fn(&str) -> AutoEscape + 'static + Sync + Send>(
&mut self,
f: F
)
pub fn set_auto_escape_callback<F: Fn(&str) -> AutoEscape + 'static + Sync + Send>(
&mut self,
f: F
)
Sets a new function to select the default auto escaping.
This function is invoked when templates are loaded from the environment
to determine the default auto escaping behavior. The function is
invoked with the name of the template and can make an initial auto
escaping decision based on that. The default implementation is to
turn on escaping for templates ending with .html
, .htm
and .xml
.
This is supported on crate feature source
only.
source
only.Sets the template source for the environment.
This helps when working with dynamically loaded templates. For more
information see Source
.
Already loaded templates in the environment are discarded and replaced with the templates from the source.
This is supported on crate feature source
only.
source
only.Returns the currently set source.
Loads a template from a string.
The name
parameter defines the name of the template which identifies
it. To look up a loaded template use the get_template
method.
Removes a template by name.
Fetches a template by name.
This requires that the template has been loaded with
add_template
beforehand. If the template was
not loaded an error of kind TemplateNotFound
is returned.
pub fn compile_expression(
&self,
expr: &'source str
) -> Result<Expression<'_, 'source>, Error>
pub fn compile_expression(
&self,
expr: &'source str
) -> Result<Expression<'_, 'source>, Error>
Compiles an expression.
This lets one compile an expression in the template language and
receive the output. This lets one use the expressions of the language
be used as a minimal scripting language. For more information and an
example see Expression
.
pub fn add_filter<F, V, Rv, Args>(&mut self, name: &'source str, f: F) where
V: ArgType,
Rv: Into<Value>,
F: Filter<V, Rv, Args>,
Args: FunctionArgs,
pub fn add_filter<F, V, Rv, Args>(&mut self, name: &'source str, f: F) where
V: ArgType,
Rv: Into<Value>,
F: Filter<V, Rv, Args>,
Args: FunctionArgs,
Adds a new filter function.
For details about filters have a look at filters
.
Removes a filter by name.
Adds a new test function.
For details about tests have a look at tests
.
Removes a test by name.
Trait Implementations
Auto Trait Implementations
impl<'source> !RefUnwindSafe for Environment<'source>
impl<'source> Send for Environment<'source>
impl<'source> Sync for Environment<'source>
impl<'source> Unpin for Environment<'source>
impl<'source> !UnwindSafe for Environment<'source>
Blanket Implementations
Mutably borrows from an owned value. Read more