Struct handlebars::RenderContext[][src]

pub struct RenderContext<'reg, 'rc> { /* fields omitted */ }
Expand description

The context of a render call

This context stores information of a render and a writer where generated content is written to.

Implementations

impl<'reg: 'rc, 'rc> RenderContext<'reg, 'rc>[src]

pub fn new(root_template: Option<&'reg String>) -> RenderContext<'reg, 'rc>[src]

Create a render context from a Write

pub fn push_block(&mut self, block: BlockContext<'reg>)[src]

Push a block context into render context stack. This is typically called when you entering a block scope.

pub fn pop_block(&mut self)[src]

Pop and drop current block context. This is typically called when leaving a block scope.

pub fn block(&self) -> Option<&BlockContext<'reg>>[src]

Borrow a reference to current block context

pub fn block_mut(&mut self) -> Option<&mut BlockContext<'reg>>[src]

Borrow a mutable reference to current block context in order to modify some data.

pub fn context(&self) -> Option<Rc<Context>>[src]

Get the modified context data if any

pub fn set_context(&mut self, ctx: Context)[src]

Set new context data into the render process. This is typically called in decorators where user can modify the data they were rendering.

pub fn evaluate(
    &self,
    context: &'rc Context,
    relative_path: &str
) -> Result<ScopedJson<'reg, 'rc>, RenderError>
[src]

Evaluate a Json path in current scope.

Typically you don’t need to evaluate it by yourself. The Helper and Decorator API will provide your evaluated value of their parameters and hash data.

pub fn get_partial(&self, name: &str) -> Option<&Template>[src]

Get registered partial in this render context

pub fn set_partial(&mut self, name: String, partial: &'reg Template)[src]

Register a partial for this context

pub fn remove_partial(&mut self, name: &str)[src]

Remove a registered partial

pub fn is_current_template(&self, p: &str) -> bool[src]

Test if given template name is current template.

pub fn register_local_helper(
    &mut self,
    name: &str,
    def: Box<dyn HelperDef + Send + Sync + 'rc>
)
[src]

Register a helper in this render context. This is a feature provided by Decorator where you can create temporary helpers.

pub fn unregister_local_helper(&mut self, name: &str)[src]

Remove a helper from render context

pub fn get_local_helper(
    &self,
    name: &str
) -> Option<Rc<dyn HelperDef + Send + Sync + 'rc>>
[src]

Attempt to get a helper from current render context.

pub fn get_current_template_name(&self) -> Option<&'reg String>[src]

Returns the current template name. Note that the name can be vary from root template when you are rendering from partials.

pub fn set_current_template_name(&mut self, name: Option<&'reg String>)[src]

Set the current template name.

pub fn get_root_template_name(&self) -> Option<&'reg String>[src]

Get root template name if any. This is the template name that you call render from Handlebars.

pub fn is_disable_escape(&self) -> bool[src]

Get the escape toggle

pub fn set_disable_escape(&mut self, disable: bool)[src]

Set the escape toggle. When toggle is on, escape_fn will be called when rendering.

Trait Implementations

impl<'reg, 'rc> Clone for RenderContext<'reg, 'rc>[src]

fn clone(&self) -> RenderContext<'reg, 'rc>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'reg, 'rc> Debug for RenderContext<'reg, 'rc>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'reg, 'rc> !RefUnwindSafe for RenderContext<'reg, 'rc>

impl<'reg, 'rc> !Send for RenderContext<'reg, 'rc>

impl<'reg, 'rc> !Sync for RenderContext<'reg, 'rc>

impl<'reg, 'rc> Unpin for RenderContext<'reg, 'rc>

impl<'reg, 'rc> !UnwindSafe for RenderContext<'reg, 'rc>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.