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.
This commit is contained in:
parent
265afe7eeb
commit
af5122ab9f
@ -46,6 +46,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
pub fn render<C>(&self, name: &str, context: &C) -> Result<String, RenderError>
|
pub fn render<C>(&self, name: &str, context: &C) -> Result<String, RenderError>
|
||||||
where
|
where
|
||||||
C: Index<&'a str>,
|
C: Index<&'a str>,
|
||||||
|
<C as std::ops::Index<&'a str>>::Output: std::string::ToString,
|
||||||
{
|
{
|
||||||
let main_template = match self.templates.get(name) {
|
let main_template = match self.templates.get(name) {
|
||||||
Some(tmpl) => tmpl,
|
Some(tmpl) => tmpl,
|
||||||
@ -61,6 +62,7 @@ impl<'a> DustRenderer<'a> {
|
|||||||
fn render_template<C>(&self, template: &Template, context: &C) -> Result<String, RenderError>
|
fn render_template<C>(&self, template: &Template, context: &C) -> Result<String, RenderError>
|
||||||
where
|
where
|
||||||
C: Index<&'a str>,
|
C: Index<&'a str>,
|
||||||
|
<C as std::ops::Index<&'a str>>::Output: std::string::ToString,
|
||||||
{
|
{
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
for elem in &template.contents.elements {
|
for elem in &template.contents.elements {
|
||||||
@ -77,10 +79,14 @@ impl<'a> DustRenderer<'a> {
|
|||||||
fn render_tag<C>(&self, tag: &DustTag, context: &C) -> Result<String, RenderError>
|
fn render_tag<C>(&self, tag: &DustTag, context: &C) -> Result<String, RenderError>
|
||||||
where
|
where
|
||||||
C: Index<&'a str>,
|
C: Index<&'a str>,
|
||||||
|
<C as std::ops::Index<&'a str>>::Output: std::string::ToString,
|
||||||
{
|
{
|
||||||
match tag {
|
match tag {
|
||||||
DustTag::DTComment(comment) => (),
|
DustTag::DTComment(comment) => (),
|
||||||
DustTag::DTReference(reference) => (),
|
DustTag::DTReference(reference) => {
|
||||||
|
let val = context.index("name");
|
||||||
|
return Ok(val.to_string());
|
||||||
|
}
|
||||||
_ => (), // TODO: Implement the rest
|
_ => (), // TODO: Implement the rest
|
||||||
}
|
}
|
||||||
Ok("".to_owned())
|
Ok("".to_owned())
|
||||||
|
Loading…
Reference in New Issue
Block a user