Fixing warnings
This commit is contained in:
parent
883bda7a78
commit
8e4f5e3229
src
@ -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<Filter>) -> 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()),
|
||||
|
@ -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;
|
||||
|
@ -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<T> = std::result::Result<T, NodeError>;
|
||||
|
||||
#[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<String> {
|
||||
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 })
|
||||
}
|
||||
}
|
@ -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<I: ContextElement> ContextElement for HashMap<&str, I> {}
|
||||
|
||||
impl Renderable for u32 {
|
||||
fn render(&self, filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// TODO: handle the filters
|
||||
Ok(self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderable for &str {
|
||||
fn render(&self, filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// TODO: handle the filters
|
||||
Ok(self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: ContextElement> Renderable for HashMap<&str, I> {
|
||||
fn render(&self, filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// TODO: handle the filters
|
||||
Err(RenderError::CantRender { elem: self })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user