Added the signature for passing filters into the render function.
Added the signature for passing filters into the render function but I am not yet using the filters.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
extern crate nom;
|
||||
|
||||
use parser::Filter;
|
||||
use renderer::compile_template;
|
||||
use renderer::CompiledTemplate;
|
||||
use renderer::ContextElement;
|
||||
@@ -73,15 +74,16 @@ fn read_context_from_stdin() -> serde_json::Value {
|
||||
impl ContextElement for serde_json::Value {}
|
||||
|
||||
impl Renderable for serde_json::Value {
|
||||
fn render(&self) -> Result<String, RenderError> {
|
||||
fn render(&self, filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
match self {
|
||||
serde_json::Value::Null => Ok("".to_owned()),
|
||||
serde_json::Value::Bool(boolean) => Ok(boolean.to_string()),
|
||||
serde_json::Value::Number(num) => Ok(num.to_string()),
|
||||
serde_json::Value::String(string) => Ok(string.to_string()),
|
||||
serde_json::Value::Array(arr) => {
|
||||
// TODO: Handle the filters instead of passing a Vec::new()
|
||||
let rendered: Result<Vec<String>, RenderError> =
|
||||
arr.iter().map(|val| val.render()).collect();
|
||||
arr.iter().map(|val| val.render(&Vec::new())).collect();
|
||||
let rendered_slice: &[String] = &rendered?;
|
||||
Ok(rendered_slice.join(","))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user