Rendering my first template with actually following paths.
Before I was hard-coding the path to the reference. Now I am following the full path programmatically using the new ContextElement and Walkable traits.
This commit is contained in:
@@ -48,8 +48,7 @@ impl<'a> DustRenderer<'a> {
|
||||
|
||||
pub fn render<C>(&self, name: &str, context: &C) -> Result<String, RenderError>
|
||||
where
|
||||
C: Index<&'a str>,
|
||||
<C as std::ops::Index<&'a str>>::Output: Renderable,
|
||||
C: ContextElement,
|
||||
{
|
||||
let main_template = match self.templates.get(name) {
|
||||
Some(tmpl) => tmpl,
|
||||
@@ -64,8 +63,7 @@ impl<'a> DustRenderer<'a> {
|
||||
|
||||
fn render_template<C>(&self, template: &Template, context: &C) -> Result<String, RenderError>
|
||||
where
|
||||
C: Index<&'a str>,
|
||||
<C as std::ops::Index<&'a str>>::Output: Renderable,
|
||||
C: ContextElement,
|
||||
{
|
||||
let mut output = String::new();
|
||||
for elem in &template.contents.elements {
|
||||
@@ -81,13 +79,12 @@ impl<'a> DustRenderer<'a> {
|
||||
|
||||
fn render_tag<C>(&self, tag: &DustTag, context: &C) -> Result<String, RenderError>
|
||||
where
|
||||
C: Index<&'a str>,
|
||||
<C as std::ops::Index<&'a str>>::Output: Renderable,
|
||||
C: ContextElement,
|
||||
{
|
||||
match tag {
|
||||
DustTag::DTComment(comment) => (),
|
||||
DustTag::DTReference(reference) => {
|
||||
let val = context.index("name");
|
||||
let val = walk_path(context, &reference.path.keys);
|
||||
return Ok(val.render());
|
||||
}
|
||||
_ => (), // TODO: Implement the rest
|
||||
|
||||
Reference in New Issue
Block a user