Add support for supplying multiple templates to the dustjs shim to support testing partials.
parent
608c55575e
commit
7e0a617ba6
@ -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"),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue