Remove some unnecessary blocks.

This commit is contained in:
Eric Huss 2020-05-10 09:23:40 -07:00
parent 578e4da5b6
commit 6038af292f
2 changed files with 17 additions and 23 deletions

View File

@ -57,20 +57,16 @@ impl HtmlHandlebars {
bail!(ErrorKind::ReservedFilenameError(path.clone())); bail!(ErrorKind::ReservedFilenameError(path.clone()));
}; };
// Non-lexical lifetimes needed :'( let book_title = ctx
let title: String; .data
{ .get("book_title")
let book_title = ctx .and_then(serde_json::Value::as_str)
.data .unwrap_or("");
.get("book_title")
.and_then(serde_json::Value::as_str)
.unwrap_or("");
title = match book_title { let title = match book_title {
"" => ch.name.clone(), "" => ch.name.clone(),
_ => ch.name.clone() + " - " + book_title, _ => ch.name.clone() + " - " + book_title,
} };
}
ctx.data.insert("path".to_owned(), json!(path)); ctx.data.insert("path".to_owned(), json!(path));
ctx.data.insert("content".to_owned(), json!(content)); ctx.data.insert("content".to_owned(), json!(content));

View File

@ -204,18 +204,16 @@ impl Renderer for CmdRenderer {
Err(e) => return self.handle_render_command_error(ctx, e), Err(e) => return self.handle_render_command_error(ctx, e),
}; };
{ let mut stdin = child.stdin.take().expect("Child has stdin");
let mut stdin = child.stdin.take().expect("Child has stdin"); if let Err(e) = serde_json::to_writer(&mut stdin, &ctx) {
if let Err(e) = serde_json::to_writer(&mut stdin, &ctx) { // Looks like the backend hung up before we could finish
// Looks like the backend hung up before we could finish // sending it the render context. Log the error and keep going
// sending it the render context. Log the error and keep going warn!("Error writing the RenderContext to the backend, {}", e);
warn!("Error writing the RenderContext to the backend, {}", e);
}
// explicitly close the `stdin` file handle
drop(stdin);
} }
// explicitly close the `stdin` file handle
drop(stdin);
let status = child let status = child
.wait() .wait()
.chain_err(|| "Error waiting for the backend to complete")?; .chain_err(|| "Error waiting for the backend to complete")?;