2020-04-28 19:09:02 -04:00
|
|
|
use crate::parser::Filter;
|
2020-04-12 18:29:40 -04:00
|
|
|
use crate::renderer::errors::RenderError;
|
2020-05-09 14:00:19 -04:00
|
|
|
use crate::renderer::errors::WalkError;
|
2020-04-11 22:23:59 -04:00
|
|
|
use std::fmt::Debug;
|
2020-04-11 20:34:16 -04:00
|
|
|
|
2020-05-05 20:43:53 -04:00
|
|
|
pub trait ContextElement: Debug + Walkable + Renderable + Loopable {}
|
2020-04-11 20:34:16 -04:00
|
|
|
|
2020-04-11 22:19:54 -04:00
|
|
|
pub trait Walkable {
|
2020-05-09 14:00:19 -04:00
|
|
|
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError>;
|
2020-04-11 20:34:16 -04:00
|
|
|
}
|
2020-04-28 19:09:02 -04:00
|
|
|
|
|
|
|
pub trait Renderable {
|
|
|
|
fn render(&self, filters: &Vec<Filter>) -> Result<String, RenderError>;
|
|
|
|
}
|
2020-04-28 19:34:52 -04:00
|
|
|
|
|
|
|
pub trait Loopable {
|
|
|
|
/// Return the elements for a Dust section
|
|
|
|
///
|
|
|
|
/// Sections in dust are accomplished with the {#path} syntax. A
|
|
|
|
/// section has a truthiness check performed on it. If that
|
|
|
|
/// truthiness check fails, then it will render the
|
|
|
|
/// else-block. Otherwise if its a scalar value it will render
|
|
|
|
/// once with the context being the element at that path. Finally,
|
|
|
|
/// if its an array-like value then it will render n-times, once
|
|
|
|
/// for each element of the array.
|
|
|
|
fn get_loop_elements(&self) -> Result<Vec<&dyn ContextElement>, RenderError>;
|
|
|
|
}
|