From af5122ab9f069c1f4fa9877288feeeff91d2150f Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 11 Apr 2020 19:03:41 -0400 Subject: [PATCH] Figured out how to get a value using `to_string()` Figured out how to get a value using `to_string()` but serde_json's `to_string()` is wrapping a string in quotes. I think I want to implement my own trait to support custom logic for rendering values. --- src/renderer/renderer.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 3923dab..697b1a8 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -46,6 +46,7 @@ impl<'a> DustRenderer<'a> { pub fn render(&self, name: &str, context: &C) -> Result where C: Index<&'a str>, + >::Output: std::string::ToString, { let main_template = match self.templates.get(name) { Some(tmpl) => tmpl, @@ -61,6 +62,7 @@ impl<'a> DustRenderer<'a> { fn render_template(&self, template: &Template, context: &C) -> Result where C: Index<&'a str>, + >::Output: std::string::ToString, { let mut output = String::new(); for elem in &template.contents.elements { @@ -77,10 +79,14 @@ impl<'a> DustRenderer<'a> { fn render_tag(&self, tag: &DustTag, context: &C) -> Result where C: Index<&'a str>, + >::Output: std::string::ToString, { match tag { DustTag::DTComment(comment) => (), - DustTag::DTReference(reference) => (), + DustTag::DTReference(reference) => { + let val = context.index("name"); + return Ok(val.to_string()); + } _ => (), // TODO: Implement the rest } Ok("".to_owned())