diff --git a/src/bin.rs b/src/bin.rs index eb4bbea..3e1e7e9 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -74,7 +74,7 @@ fn read_context_from_stdin() -> serde_json::Value { impl ContextElement for serde_json::Value {} impl Renderable for serde_json::Value { - fn render(&self, filters: &Vec) -> Result { + fn render(&self, _filters: &Vec) -> Result { match self { serde_json::Value::Null => Ok("".to_owned()), serde_json::Value::Bool(boolean) => Ok(boolean.to_string()), diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 7d3b3da..92152a7 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,11 +1,7 @@ //! This module contains a rust implementation of LinkedIn Dust -mod node_invoker; mod parser; -pub use node_invoker::run_node_dust; -pub use node_invoker::NodeError; -pub use node_invoker::Result; pub use parser::template; pub use parser::Body; pub use parser::DustTag; diff --git a/src/parser/node_invoker.rs b/src/parser/node_invoker.rs deleted file mode 100644 index c554634..0000000 --- a/src/parser/node_invoker.rs +++ /dev/null @@ -1,61 +0,0 @@ -use std::error; -use std::fmt; -use std::io::Write; -use std::process::Output; -use std::process::{Command, Stdio}; - -pub type Result = std::result::Result; - -#[derive(Clone)] -pub struct NodeError { - output: Output, -} - -impl fmt::Display for NodeError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "Error from node: {}", - String::from_utf8_lossy(&self.output.stderr) - ) - } -} - -impl fmt::Debug for NodeError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "Error from node: {}", - String::from_utf8_lossy(&self.output.stderr) - ) - } -} - -impl error::Error for NodeError { - fn source(&self) -> Option<&(dyn error::Error + 'static)> { - None - } -} - -/// Invokes Node to run the authentic LinkedIn Dust -pub fn run_node_dust(template_path: &str, context: &str) -> Result { - let mut proc = Command::new("node") - .arg("./src/js/dustjs_shim.js") - .arg(template_path) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("failed to execute process"); - proc.stdin - .take() - .unwrap() - .write_all(context.as_bytes()) - .expect("Failed to write to stdin of node process"); - let output = proc.wait_with_output().expect("Failed to wait on node"); - if output.status.success() { - Ok(String::from_utf8(output.stdout).expect("Invalid UTF-8 from node process")) - } else { - Err(NodeError { output: output }) - } -} diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index ea9acbb..9e7151e 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -5,9 +5,7 @@ use crate::parser::Template; use crate::parser::TemplateElement; use crate::renderer::errors::CompileError; use crate::renderer::errors::RenderError; -use crate::renderer::renderable::Renderable; use crate::renderer::walkable::ContextElement; -use crate::renderer::walkable::Walkable; use std::collections::HashMap; #[derive(Clone, Debug)] @@ -116,6 +114,8 @@ fn walk_path<'a>( mod tests { use super::*; use crate::parser::Filter; + use crate::renderer::renderable::Renderable; + use crate::renderer::walkable::Walkable; #[test] fn test_walk_path() { @@ -124,21 +124,21 @@ mod tests { impl ContextElement for HashMap<&str, I> {} impl Renderable for u32 { - fn render(&self, filters: &Vec) -> Result { + fn render(&self, _filters: &Vec) -> Result { // TODO: handle the filters Ok(self.to_string()) } } impl Renderable for &str { - fn render(&self, filters: &Vec) -> Result { + fn render(&self, _filters: &Vec) -> Result { // TODO: handle the filters Ok(self.to_string()) } } impl Renderable for HashMap<&str, I> { - fn render(&self, filters: &Vec) -> Result { + fn render(&self, _filters: &Vec) -> Result { // TODO: handle the filters Err(RenderError::CantRender { elem: self }) }