diff --git a/src/bin.rs b/src/bin.rs index 97f1b13..0e9bd5f 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -56,7 +56,7 @@ fn template_from_file<'a>(file_path: &str, file_contents: &'a str) -> CompiledTe .expect("Failed to compile template") } -fn read_context_from_stdin() -> serde_json::map::Map { +fn read_context_from_stdin() -> serde_json::Value { let mut buffer = String::new(); io::stdin() .read_to_string(&mut buffer) @@ -64,7 +64,7 @@ fn read_context_from_stdin() -> serde_json::map::Map let parsed: serde_json::Value = serde_json::from_str(&buffer).expect("Failed to parse json"); match parsed { - serde_json::Value::Object(obj) => obj, + serde_json::Value::Object(obj) => serde_json::value::Value::Object(obj), _ => panic!("Expected context to be an object"), } } diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 3fc7545..37e6569 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -57,13 +57,13 @@ pub struct Comment<'a> { } #[derive(Clone, Debug, PartialEq)] -struct Path<'a> { - keys: Vec<&'a str>, +pub struct Path<'a> { + pub keys: Vec<&'a str>, } #[derive(Clone, Debug, PartialEq)] pub struct Reference<'a> { - path: Path<'a>, + pub path: Path<'a>, filters: Vec, } diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index f40ecdc..54eb92d 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -48,8 +48,7 @@ impl<'a> DustRenderer<'a> { pub fn render(&self, name: &str, context: &C) -> Result where - C: 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(&self, template: &Template, context: &C) -> Result where - C: 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(&self, tag: &DustTag, context: &C) -> Result where - C: 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