Add support for supplying multiple templates to the dustjs shim to support testing partials.

This commit is contained in:
Tom Alexander
2020-04-10 19:07:02 -04:00
parent 608c55575e
commit 7e0a617ba6
5 changed files with 40 additions and 14 deletions

View File

@@ -1,9 +1,24 @@
extern crate nom;
use parser::template;
use std::io::{self, Read};
mod parser;
fn main() {
let parsed_template = template("{#foo.bar}hello {name}{/foo.bar}!");
println!("{:?}", parsed_template);
let context = read_context_from_stdin();
println!("{:?}", context);
}
fn read_context_from_stdin() -> serde_json::map::Map<String, serde_json::Value> {
let mut buffer = String::new();
io::stdin()
.read_to_string(&mut buffer)
.expect("Failed to read stdin");
let parsed: serde_json::Value = serde_json::from_str(&buffer).expect("Failed to parse json");
match parsed {
serde_json::Value::Object(obj) => obj,
_ => panic!("Expected context to be an object"),
}
}